Re: How do I make my form process data and output in another page?

2014-07-21 Thread Mike Dewhirst

On 22/07/2014 1:07 PM, Jordan S wrote:

Hi, I'm trying to make a molecular mass calculator webpage, where a user
inputs a chemical formula and gets the mass as a result. I've made this
work in python using raw_input(), but now I'd need to use a form with
django.

I have the html form set up, but when I click "submit", the page just
shows itself again.



I'm interested in molecular mass calculation mainly because of isotopic 
variances. How do you account for them? They seem to vary somewhat 
depending on the laboratory doing the work. I'm building an application 
and have made an interface to collect molecular weight from NIH or 
Chemspider. But I would prefer to calculate weights than go and get them.


On your Django question, I would be creating a database record for each 
substance formula and calculate the molecular weight in models.py then 
put the value in a field just prior to save(). Once you have the data 
you can just redisplay the same page.


Otherwise, detect that you actually have a molecular weight and display 
a different page.


Here is an excerpt from my own Substance model ...

formula = models.CharField(max_length=LARGE)

molecular_weight = models.DecimalField(null=True, blank=True,
max_digits=10,
decimal_places=4,
default=0.)

... and this is where I would do the calculation ...

def save(self, *args, **kwargs):
self.molecular_weight = CalcMolecularMass(self.formula)
super(Substance, self).save(*args, **kwargs)

Mike


What I want to happen is:

1. User inputs formula in form on index.html(ex. H2)
2. Form data is processed using the code that I put in the result view
3. Result is outputted in result.html

However, I'm not sure how to do this, as I've looked through the
tutorial and form docs.

Here is my views.py:

 1.
from django.shortcuts import render
 2.
from django.db import connection
 3.
from django.http import HttpResponseRedirect
 4.
from django.core.urlresolvers import reverse
 5.
import sys, re
 6.
 7.
# Create your views here.
 8.
def index(request):
 9.
if request.method == "POST":
10.
return HttpResponseRedirect(reverse('MolecularMass:result'))
11.
else:
12.
return render(request, 'MolecularMass/index.html')
13.
def result(request):
14.
 c = connections['default'].cursor()
15.
16.
def FindEndParentheses(separated):
17.
 count = 0
18.
for index, val in enumerate(separated):
19.
if val == ')':
20.
 count -= 1
21.
if count == 0:
22.
return index
23.
elif val == '(':
24.
 count += 1
25.
raise NameError('Please close the parentheses')
26.
def GetAtomicMass(val):
27.
 c.execute("SELECT Atomic_Weight FROM Elements WHERE
Atomic_Numer=%s" % val)
28.
return c.fetchone[0]
29.
def Parser(separated, total):
30.
if len(separated) == 0:
31.
return sum(total)
32.
 val = separated[0]
33.
if val == '(':
34.
 end = FindEndParentheses(separated)
35.
 total.append(Parser(separated[1:end], []))
36.
return Parser(separated[end + 1:], total)
37.
elif val.isdigit():
38.
 total[-1] *= int(val)
39.
else:
40.
 total.append(GetAtomicMass(val))
41.
return Parser(separated[1:], total)
42.
def CalcMolecularMass(formula):
43.
 separated =
re.findall(r'[A-Z][a-z]*|\d+|\(|\)', formula)
44.
return('The molecular mass of {} is
{:.3f}\n'.format(formula, Parser(separated, [])))
45.
 content = CalcMolecularMass(formula)
46.
return render(request, 'MolecularMass/result.html', content)

My index.html:

|
Enter a chemical formula to get its molecular mass

 {% csrf_token %}



|


My result.html:

|
{{content }}
|


--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/2feffc32-36f1-49c0-9561-ce9945ffe12d%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegr

How do I make my form process data and output in another page?

2014-07-21 Thread Jordan S
Hi, I'm trying to make a molecular mass calculator webpage, where a user 
inputs a chemical formula and gets the mass as a result. I've made this 
work in python using raw_input(), but now I'd need to use a form with 
django. 

I have the html form set up, but when I click "submit", the page just shows 
itself again.

What I want to happen is:

1. User inputs formula in form on index.html(ex. H2)
2. Form data is processed using the code that I put in the result view
3. Result is outputted in result.html

However, I'm not sure how to do this, as I've looked through the tutorial 
and form docs.

Here is my views.py:

   1. from django.shortcuts import render
   2. from django.db import connection
   3. from django.http import HttpResponseRedirect
   4. from django.core.urlresolvers import reverse
   5. import sys, re
   6.  
   7. # Create your views here.
   8. def index(request):
   9. if request.method == "POST":
   10. return HttpResponseRedirect(reverse(
   'MolecularMass:result'))
   11. else:
   12. return render(request, 'MolecularMass/index.html')
   13. def result(request):
   14. c = connections['default'].cursor()
   15.  
   16. def FindEndParentheses(separated):
   17. count = 0
   18. for index, val in enumerate(separated):
   19. if val == ')':
   20. count -= 1
   21. if count == 0:
   22. return index
   23. elif val == '(':
   24. count += 1
   25. raise NameError('Please close the parentheses')
   26. def GetAtomicMass(val):
   27. c.execute("SELECT Atomic_Weight FROM Elements WHERE 
   Atomic_Numer=%s" % val)
   28. return c.fetchone[0]
   29. def Parser(separated, total):
   30. if len(separated) == 0:
   31. return sum(total)
   32. val = separated[0]
   33. if val == '(':
   34. end = FindEndParentheses(separated)
   35. total.append(Parser(separated[1:end], []))
   36. return Parser(separated[end + 1:], total)
   37. elif val.isdigit():
   38. total[-1] *= int(val)
   39. else:
   40. total.append(GetAtomicMass(val))
   41. return Parser(separated[1:], total)
   42. def CalcMolecularMass(formula):
   43. separated = re.findall(r'[A-Z][a-z]*|\d+|\(|\)',
formula)
   44. return('The molecular mass of {} is {:.3f}\n'.format(
   formula, Parser(separated, [])))
   45. content = CalcMolecularMass(formula)
   46. return render(request, 'MolecularMass/result.html', content)
   
My index.html:


Enter a chemical formula to get its molecular mass

{% csrf_token %}





My result.html:


{{ content }}


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2feffc32-36f1-49c0-9561-ce9945ffe12d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Converting to Custom User Model (Django 1.5)

2014-07-21 Thread PRyan
We are currently using the following user model setup:

settings.py:
AUTH_USER_MODEL = 'auth.User'

userprofile.py:
class UserProfile(DirtyFieldsMixin, User):

Is it possible to change these to the following and have South take care of 
the data as not lose anything?

settings.py:
AUTH_USER_MODEL = 'userprofile.UserProfile'

userprofile.py:
class UserProfile(DirtyFieldsMixin, AbstractUser):

I have looked through here and the rest of google and all the answers show 
created a new custom user that you copy everything to. Is it possible to 
continue to use our UserProfile but just convert it to extend AbstractUser 
as made possible in Django 1.5 (which we are currently using)?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/507e89b9-bde1-4cfe-bf32-1c7a8b973d1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question about including CSRF token.

2014-07-21 Thread Gonzalo Delgado
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

El 21/07/14 15:57, Chen Xu escribió:
> I am writing a website using Django, and getting confused about
> CSRF token, I understand I need to include the csrf token on my web
> page to prevent the CSRF attack. However, I am also working on a
> mobile app, which will sends request to my website API, and get
> response back, how should I handle the CSRF token problem in this
> case?

How does your mobile app and your website API communicate?

Take a look at the documentation AJAX example here:
https://docs.djangoproject.com/en/1.6/ref/contrib/csrf/#ajax

It uses a custom "X-CSRFToken" header in the AJAX query from the client.
You can probably implement something similar in your app (if it isn't
implemented in javascript).


- -- 
Gonzalo Delgado
-BEGIN PGP SIGNATURE-
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iF4EAREIAAYFAlPNsWUACgkQzbfdFL5JoUlNgwD+MSz1AoP4ddGJkTNkbNZ7r80W
0jnMizvZ7f5tGoEdSAwA/j4LeVLF5pXGFj/hPLl/JHc1Kqw+BbhK53iTCFd9ZNzT
=Rbs/
-END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53CDB165.10709%40gonzalodelgado.com.ar.
For more options, visit https://groups.google.com/d/optout.


Re: Introducing myself and my first question

2014-07-21 Thread Mario Gudelj
Hey Martin,

I can guarantee you that PyCharm is totally worth buying. It will speed up
your development drastically and it works really well with Django.
Autocompletion both in Python and template code, syntax highlighting in
both, easy Option+Enter imports, navigation through code, refactoring. You
name it has it. Just the merge tool is worth those $99.

Cheers,

M


On 22 July 2014 07:37, Martin Torre Castro  wrote:

> Thanks to you also, Chen, I read you the last, but not least. I looked at
> PyCharm's price but it seemed expensive for buying for being used by two
> people at developing.
>
> I take care of the 'pip freeze' tip. :-)
>
>
> On Sunday, 20 July 2014 03:48:37 UTC+2, Edward Chen wrote:
>
>> Hi - I am kind of new myself, and I don't have all the answers to your
>> questions, but here are some thoughts, and I could be wrong.
>>
>> 1.  You can set up your virtualenv anywhere you like.  The one I'm using
>> right now is in ~/Envs/venv_for_my_project/  All you're doing with it is
>> source/bin/activate.  As Two Scoops of Django recommends, just store the
>> output of pip freeze in version control.
>>
>> 2. I am not using Eclipse, so I can't help there.  I am using PyCharm
>> which has a nice integration with virtualenv and Django.  It's easy to
>> start the server in debugging mode and set break points.  With Pycharm, I
>> set it up once, pointing it to the location of my virtualenv, and haven't
>> touched it since, even though I've added packages to my virtualenv.  The
>> downside of PyCharm is that it costs money.
>>
>> 3. I don't think you can screw things up too much.  You may want to first
>> do as much as possible via the command line in a terminal window and see if
>> that works (for example, start and stop the server), then try the same
>> thing through Eclipse's interface.  The worst that can happen is that your
>> test server doesn't work.
>>
>>
>>
>>
>> On Sat, Jul 19, 2014 at 3:09 PM, Martin Torre Castro 
>> wrote:
>>
>>> Hello,
>>>
>>> my name is Martin and I'm a computer engineer from Spain. I'm going to
>>> start a new project with a colleague and I decided to use Django because we
>>> searched for free opensource tools and I'm in love with Python.
>>>
>>> We have made a couple of tutorials (the official one and "Tango with
>>> django"). I've also bought the book "Two scoops of Django" for the 1.6
>>> Django edition. We're starting the project soon as well as we finish the
>>> design, but I'm concerned about setting up the new environment. We're
>>> thinking of using:
>>>
>>>
>>>- postgresql
>>>- Python/Django [ of course ;-) ]
>>>- Eclipse/Pydev
>>>- Git
>>>- jQuery
>>>
>>> I've been reading the Greenfield/Roy book and some web sites and I want
>>> to set up the environment with good practices by using virtualenvwrapper,
>>> virtualenv, pip, the requirements.txt files and so on.
>>> I have made some mix for all this, but I would be grateful if someone
>>> could confirm us if we are on the right way, give us some advice or maybe
>>> tell us where on the internet we can find a good way of doing all this.
>>>
>>> My preview for the whole setting up is next:
>>>
>>>
>>>1. We should start the installations by installing "sudo apt-get
>>>install virtualenvwrapper" . If I understand correctly, this
>>>installs virtualenv as well as an embedded pip.
>>>2. The virtualenv must be created ("virtualenv env") in the parent
>>>directory of the Eclipse workspace, I suppose. This is one point of
>>>confusion to me. I don't know either if I have to activate this every 
>>> time
>>>I come back for developing resuming the work from days before. I 
>>> completely
>>>understand that later from Eclipse I will give the python path inside the
>>>virtualenv, but don't know if must activate the virtualenv every
>>>time.
>>>3. Next step would be to install all the things we need (django,
>>>pillow, psycopg2) using a requirements.txt file. "pip install -r
>>>requirements.txt"
>>>4. We should create the new django project with a python
>>>django-admin.py startproject 
>>>5. Now I don't know if we should link the project to an already
>>>installed version of Eclipse or run the "git init" first. I
>>>understand that Eclipse and Git don't need to be installed inside the
>>>virtualenv. In fact, I've been reading and it seems that Eclipse can work
>>>OK just by being given the path inside the virtualenv where the python
>>>executable is located. I've also read that some people used to make
>>>different workspaces, but configuring the paths should be enough
>>>http://stackoverflow.com/questions/1145374/virtualenv-with-eclipse-
>>>galileo
>>>
>>> 
>>>
>>> From here I would just upload to github or bitbucket, maybe doing the
>>> whole thing from Eclipse would be easier. But the integration with Eclipse
>>> when we made tangow

Re: Introducing myself and my first question

2014-07-21 Thread Martin Torre Castro
Thanks to you also, Chen, I read you the last, but not least. I looked at 
PyCharm's price but it seemed expensive for buying for being used by two 
people at developing.

I take care of the 'pip freeze' tip. :-)

On Sunday, 20 July 2014 03:48:37 UTC+2, Edward Chen wrote:
>
> Hi - I am kind of new myself, and I don't have all the answers to your 
> questions, but here are some thoughts, and I could be wrong.
>
> 1.  You can set up your virtualenv anywhere you like.  The one I'm using 
> right now is in ~/Envs/venv_for_my_project/  All you're doing with it is 
> source/bin/activate.  As Two Scoops of Django recommends, just store the 
> output of pip freeze in version control.
>
> 2. I am not using Eclipse, so I can't help there.  I am using PyCharm 
> which has a nice integration with virtualenv and Django.  It's easy to 
> start the server in debugging mode and set break points.  With Pycharm, I 
> set it up once, pointing it to the location of my virtualenv, and haven't 
> touched it since, even though I've added packages to my virtualenv.  The 
> downside of PyCharm is that it costs money.
>
> 3. I don't think you can screw things up too much.  You may want to first 
> do as much as possible via the command line in a terminal window and see if 
> that works (for example, start and stop the server), then try the same 
> thing through Eclipse's interface.  The worst that can happen is that your 
> test server doesn't work.
>
>   
>
>
> On Sat, Jul 19, 2014 at 3:09 PM, Martin Torre Castro  > wrote:
>
>> Hello,
>>
>> my name is Martin and I'm a computer engineer from Spain. I'm going to 
>> start a new project with a colleague and I decided to use Django because we 
>> searched for free opensource tools and I'm in love with Python.
>>
>> We have made a couple of tutorials (the official one and "Tango with 
>> django"). I've also bought the book "Two scoops of Django" for the 1.6 
>> Django edition. We're starting the project soon as well as we finish the 
>> design, but I'm concerned about setting up the new environment. We're 
>> thinking of using:
>>
>>
>>- postgresql
>>- Python/Django [ of course ;-) ]
>>- Eclipse/Pydev
>>- Git
>>- jQuery
>>
>> I've been reading the Greenfield/Roy book and some web sites and I want 
>> to set up the environment with good practices by using virtualenvwrapper, 
>> virtualenv, pip, the requirements.txt files and so on.
>> I have made some mix for all this, but I would be grateful if someone 
>> could confirm us if we are on the right way, give us some advice or maybe 
>> tell us where on the internet we can find a good way of doing all this.
>>
>> My preview for the whole setting up is next:
>>
>>
>>1. We should start the installations by installing "sudo apt-get 
>>install virtualenvwrapper" . If I understand correctly, this installs 
>>virtualenv as well as an embedded pip.
>>2. The virtualenv must be created ("virtualenv env") in the parent 
>>directory of the Eclipse workspace, I suppose. This is one point of 
>>confusion to me. I don't know either if I have to activate this every 
>> time 
>>I come back for developing resuming the work from days before. I 
>> completely 
>>understand that later from Eclipse I will give the python path inside the 
>>virtualenv, but don't know if must activate the virtualenv every time. 
>>3. Next step would be to install all the things we need (django, 
>>pillow, psycopg2) using a requirements.txt file. "pip install -r 
>>requirements.txt"
>>4. We should create the new django project with a python 
>>django-admin.py startproject  
>>5. Now I don't know if we should link the project to an already 
>>installed version of Eclipse or run the "git init" first. I 
>>understand that Eclipse and Git don't need to be installed inside the 
>>virtualenv. In fact, I've been reading and it seems that Eclipse can work 
>>OK just by being given the path inside the virtualenv where the python 
>>executable is located. I've also read that some people used to make 
>>different workspaces, but configuring the paths should be enough 
>>
>> http://stackoverflow.com/questions/1145374/virtualenv-with-eclipse-galileo 
>>
>> From here I would just upload to github or bitbucket, maybe doing the 
>> whole thing from Eclipse would be easier. But the integration with Eclipse 
>> when we made tangowithdjango tutorial was the difficult point, because 
>> there is no option for importing a django project from Eclipse (Kepler 
>> version last time). We found easier to create the project from Eclipse, but 
>> we were not using a virtualenv for the tutorial.
>>
>> I haven't used virtualenv before, so it's our second main obstacle, but I 
>> expect it will be easy when we get used to it (^_^) .
>>
>> Please could someone help with some piece of advice, pros and cons of 
>> every option. Just don't want to do something now I will regret in future.
>>
>> Thank you vee

Re: Introducing myself and my first question

2014-07-21 Thread Martin Torre Castro
Thanks to you both.

I know the URL, Ariel, and I will look at it when beginning the 
implementation.

Thanks Cal for the comments. I've been heard very well about Sublime Text 
and I'm planning ot use it, not as a IDE, but for other issues as a 
complementary editor.

On Sunday, 20 July 2014 03:48:37 UTC+2, Edward Chen wrote:
>
> Hi - I am kind of new myself, and I don't have all the answers to your 
> questions, but here are some thoughts, and I could be wrong.
>
> 1.  You can set up your virtualenv anywhere you like.  The one I'm using 
> right now is in ~/Envs/venv_for_my_project/  All you're doing with it is 
> source/bin/activate.  As Two Scoops of Django recommends, just store the 
> output of pip freeze in version control.
>
> 2. I am not using Eclipse, so I can't help there.  I am using PyCharm 
> which has a nice integration with virtualenv and Django.  It's easy to 
> start the server in debugging mode and set break points.  With Pycharm, I 
> set it up once, pointing it to the location of my virtualenv, and haven't 
> touched it since, even though I've added packages to my virtualenv.  The 
> downside of PyCharm is that it costs money.
>
> 3. I don't think you can screw things up too much.  You may want to first 
> do as much as possible via the command line in a terminal window and see if 
> that works (for example, start and stop the server), then try the same 
> thing through Eclipse's interface.  The worst that can happen is that your 
> test server doesn't work.
>
>   
>
>
> On Sat, Jul 19, 2014 at 3:09 PM, Martin Torre Castro  > wrote:
>
>> Hello,
>>
>> my name is Martin and I'm a computer engineer from Spain. I'm going to 
>> start a new project with a colleague and I decided to use Django because we 
>> searched for free opensource tools and I'm in love with Python.
>>
>> We have made a couple of tutorials (the official one and "Tango with 
>> django"). I've also bought the book "Two scoops of Django" for the 1.6 
>> Django edition. We're starting the project soon as well as we finish the 
>> design, but I'm concerned about setting up the new environment. We're 
>> thinking of using:
>>
>>
>>- postgresql
>>- Python/Django [ of course ;-) ]
>>- Eclipse/Pydev
>>- Git
>>- jQuery
>>
>> I've been reading the Greenfield/Roy book and some web sites and I want 
>> to set up the environment with good practices by using virtualenvwrapper, 
>> virtualenv, pip, the requirements.txt files and so on.
>> I have made some mix for all this, but I would be grateful if someone 
>> could confirm us if we are on the right way, give us some advice or maybe 
>> tell us where on the internet we can find a good way of doing all this.
>>
>> My preview for the whole setting up is next:
>>
>>
>>1. We should start the installations by installing "sudo apt-get 
>>install virtualenvwrapper" . If I understand correctly, this installs 
>>virtualenv as well as an embedded pip.
>>2. The virtualenv must be created ("virtualenv env") in the parent 
>>directory of the Eclipse workspace, I suppose. This is one point of 
>>confusion to me. I don't know either if I have to activate this every 
>> time 
>>I come back for developing resuming the work from days before. I 
>> completely 
>>understand that later from Eclipse I will give the python path inside the 
>>virtualenv, but don't know if must activate the virtualenv every time. 
>>3. Next step would be to install all the things we need (django, 
>>pillow, psycopg2) using a requirements.txt file. "pip install -r 
>>requirements.txt"
>>4. We should create the new django project with a python 
>>django-admin.py startproject  
>>5. Now I don't know if we should link the project to an already 
>>installed version of Eclipse or run the "git init" first. I 
>>understand that Eclipse and Git don't need to be installed inside the 
>>virtualenv. In fact, I've been reading and it seems that Eclipse can work 
>>OK just by being given the path inside the virtualenv where the python 
>>executable is located. I've also read that some people used to make 
>>different workspaces, but configuring the paths should be enough 
>>
>> http://stackoverflow.com/questions/1145374/virtualenv-with-eclipse-galileo 
>>
>> From here I would just upload to github or bitbucket, maybe doing the 
>> whole thing from Eclipse would be easier. But the integration with Eclipse 
>> when we made tangowithdjango tutorial was the difficult point, because 
>> there is no option for importing a django project from Eclipse (Kepler 
>> version last time). We found easier to create the project from Eclipse, but 
>> we were not using a virtualenv for the tutorial.
>>
>> I haven't used virtualenv before, so it's our second main obstacle, but I 
>> expect it will be easy when we get used to it (^_^) .
>>
>> Please could someone help with some piece of advice, pros and cons of 
>> every option. Just don't want to do so

Re: django + Mysql connector

2014-07-21 Thread François Schiettecatte
Check this thread:

https://groups.google.com/forum/#!topic/django-users/cb_IGZXVuVQ

François

On Jul 21, 2014, at 4:23 PM, Henrique Oliveira  
wrote:

> Hi there,
> 
> I am getting this error after hours:
> 
>  File "/opt/d/lib/python3.4/site-packages/django/contrib/sites/models.py", 
> line 45, in get_current
> current_site = SITE_CACHE[sid]
> 
> KeyError: 1
> 
> 
> During handling of the above exception, another exception occurred:
> 
> 
> Traceback (most recent call last):
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/backends/__init__.py", 
> line 131, in _cursor
> return self.create_cursor()
> 
>   File "/opt/d/lib/python3.4/site-packages/mysql/connector/django/base.py", 
> line 537, in create_cursor
> cursor = self.connection.cursor()
> 
>   File "/opt/d/lib/python3.4/site-packages/mysql/connector/connection.py", 
> line 1328, in cursor
> raise errors.OperationalError("MySQL Connection not available.")
> 
> mysql.connector.errors.OperationalError: MySQL Connection not available.
> 
> 
> The above exception was the direct cause of the following exception:
> 
> 
> Traceback (most recent call last):
> 
>   File "/opt/d/lib/python3.4/site-packages/django/core/handlers/base.py", 
> line 114, in get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
> 
>   File "/opt/d/lib/python3.4/site-packages/django/views/generic/base.py", 
> line 69, in view
> return self.dispatch(request, *args, **kwargs)
> 
>   File "/opt/d/lib/python3.4/site-packages/allauth/account/views.py", line 
> 62, in dispatch
> **kwargs)
> 
>   File "/opt/d/lib/python3.4/site-packages/django/views/generic/base.py", 
> line 87, in dispatch
> return handler(request, *args, **kwargs)
> 
>   File "/opt/d/lib/python3.4/site-packages/django/views/generic/edit.py", 
> line 161, in get
> return self.render_to_response(self.get_context_data(form=form))
> 
>   File "/opt/d/lib/python3.4/site-packages/allauth/account/views.py", line 
> 111, in get_context_data
> "site": Site.objects.get_current(),
> 
>   File "/opt/d/lib/python3.4/site-packages/django/contrib/sites/models.py", 
> line 47, in get_current
> current_site = self.get(pk=sid)
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/models/manager.py", line 
> 151, in get
> return self.get_queryset().get(*args, **kwargs)
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/models/query.py", line 
> 301, in get
> num = len(clone)
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/models/query.py", line 
> 77, in __len__
> self._fetch_all()
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/models/query.py", line 
> 854, in _fetch_all
> self._result_cache = list(self.iterator())
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/models/query.py", line 
> 220, in iterator
> for row in compiler.results_iter():
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/models/sql/compiler.py", 
> line 709, in results_iter
> for rows in self.execute_sql(MULTI):
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/models/sql/compiler.py", 
> line 781, in execute_sql
> cursor = self.connection.cursor()
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/backends/__init__.py", 
> line 159, in cursor
> cursor = util.CursorWrapper(self._cursor(), self)
> 
>   File "/opt/d/lib/python3.4/site-packages/mysql/connector/django/base.py", 
> line 552, in _cursor
> return super(DatabaseWrapper, self)._cursor()
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/backends/__init__.py", 
> line 131, in _cursor
> return self.create_cursor()
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/utils.py", line 99, in 
> __exit__
> six.reraise(dj_exc_type, dj_exc_value, traceback)
> 
>   File "/opt/d/lib/python3.4/site-packages/django/utils/six.py", line 535, in 
> reraise
> raise value.with_traceback(tb)
> 
>   File "/opt/d/lib/python3.4/site-packages/django/db/backends/__init__.py", 
> line 131, in _cursor
> return self.create_cursor()
> 
>   File "/opt/d/lib/python3.4/site-packages/mysql/connector/django/base.py", 
> line 537, in create_cursor
> cursor = self.connection.cursor()
> 
>   File "/opt/d/lib/python3.4/site-packages/mysql/connector/connection.py", 
> line 1328, in cursor
> raise errors.OperationalError("MySQL Connection not available.")
> 
> django.db.utils.OperationalError
> 
> Any ideas to solve this?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/eea4aae8-2f50-4571-89b4-71a2cdb6a559%

django + Mysql connector

2014-07-21 Thread Henrique Oliveira
Hi there,

I am getting this error after hours:

 File "/opt/d/lib/python3.4/site-packages/django/contrib/sites/models.py", 
line 45, in get_current
current_site = SITE_CACHE[sid]

KeyError: 1


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/opt/d/lib/python3.4/site-packages/django/db/backends/__init__.py", 
line 131, in _cursor
return self.create_cursor()

  File "/opt/d/lib/python3.4/site-packages/mysql/connector/django/base.py", 
line 537, in create_cursor
cursor = self.connection.cursor()

  File "/opt/d/lib/python3.4/site-packages/mysql/connector/connection.py", 
line 1328, in cursor
raise errors.OperationalError("MySQL Connection not available.")

mysql.connector.errors.OperationalError: MySQL Connection not available.


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "/opt/d/lib/python3.4/site-packages/django/core/handlers/base.py", 
line 114, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)

  File "/opt/d/lib/python3.4/site-packages/django/views/generic/base.py", 
line 69, in view
return self.dispatch(request, *args, **kwargs)

  File "/opt/d/lib/python3.4/site-packages/allauth/account/views.py", line 
62, in dispatch
**kwargs)

  File "/opt/d/lib/python3.4/site-packages/django/views/generic/base.py", 
line 87, in dispatch
return handler(request, *args, **kwargs)

  File "/opt/d/lib/python3.4/site-packages/django/views/generic/edit.py", 
line 161, in get
return self.render_to_response(self.get_context_data(form=form))

  File "/opt/d/lib/python3.4/site-packages/allauth/account/views.py", line 
111, in get_context_data
"site": Site.objects.get_current(),

  File "/opt/d/lib/python3.4/site-packages/django/contrib/sites/models.py", 
line 47, in get_current
current_site = self.get(pk=sid)

  File "/opt/d/lib/python3.4/site-packages/django/db/models/manager.py", 
line 151, in get
return self.get_queryset().get(*args, **kwargs)

  File "/opt/d/lib/python3.4/site-packages/django/db/models/query.py", line 
301, in get
num = len(clone)

  File "/opt/d/lib/python3.4/site-packages/django/db/models/query.py", line 
77, in __len__
self._fetch_all()

  File "/opt/d/lib/python3.4/site-packages/django/db/models/query.py", line 
854, in _fetch_all
self._result_cache = list(self.iterator())

  File "/opt/d/lib/python3.4/site-packages/django/db/models/query.py", line 
220, in iterator
for row in compiler.results_iter():

  File 
"/opt/d/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 
709, in results_iter
for rows in self.execute_sql(MULTI):

  File 
"/opt/d/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 
781, in execute_sql
cursor = self.connection.cursor()

  File "/opt/d/lib/python3.4/site-packages/django/db/backends/__init__.py", 
line 159, in cursor
cursor = util.CursorWrapper(self._cursor(), self)

  File "/opt/d/lib/python3.4/site-packages/mysql/connector/django/base.py", 
line 552, in _cursor
return super(DatabaseWrapper, self)._cursor()

  File "/opt/d/lib/python3.4/site-packages/django/db/backends/__init__.py", 
line 131, in _cursor
return self.create_cursor()

  File "/opt/d/lib/python3.4/site-packages/django/db/utils.py", line 99, in 
__exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)

  File "/opt/d/lib/python3.4/site-packages/django/utils/six.py", line 535, 
in reraise
raise value.with_traceback(tb)

  File "/opt/d/lib/python3.4/site-packages/django/db/backends/__init__.py", 
line 131, in _cursor
return self.create_cursor()

  File "/opt/d/lib/python3.4/site-packages/mysql/connector/django/base.py", 
line 537, in create_cursor
cursor = self.connection.cursor()

  File "/opt/d/lib/python3.4/site-packages/mysql/connector/connection.py", 
line 1328, in cursor
raise errors.OperationalError("MySQL Connection not available.")

django.db.utils.OperationalError

Any ideas to solve this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eea4aae8-2f50-4571-89b4-71a2cdb6a559%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie: Complete environment setup(virtualenv, pip, eclipse, git...)

2014-07-21 Thread Martin Torre Castro
Thanks Mulianto, ngangsia and Tom.

I'm working in Ubuntu but I will take advantage of your instructions 
ngangsia when setting up all the "machinery".

Thanks also Tom, for the advice and the requirements tip, as this will be 
another thing we're trying for the first time in future.

On Sunday, 20 July 2014 03:41:11 UTC+2, Martin Torre Castro wrote:
>
> Hello,
>
> my name is Martin and I'm a computer engineer from Spain. I'm going to 
> start a new project with a colleague and I decided to use Django because we 
> searched for free opensource tools and I'm in love with Python.
>
> We have made a couple of tutorials (the official one and "Tango with 
> django"). I've also bought the book "Two scoops of Django" for the 1.6 
> Django edition. We're starting the project soon as well as we finish the 
> design, but I'm concerned about setting up the new environment. We're 
> thinking of using:
>
>
>- postgresql
>- Python/Django [ of course ;-) ]
>- Eclipse/Pydev
>- Git
>- jQuery
>
> I've been reading the Greenfield/Roy book and some web sites and I want to 
> set up the environment with good practices by using virtualenvwrapper, 
> virtualenv, pip, the requirements.txt files and so on.
> I have made some mix for all this, but I would be grateful if someone 
> could confirm us if we are on the right way, give us some advice or maybe 
> tell us where on the internet we can find a good way of doing all this.
>
> My preview for the whole setting up is next:
>
>
>1. We should start the installations by installing "sudo apt-get 
>install virtualenvwrapper" . If I understand correctly, this installs 
>virtualenv as well as an embedded pip.
>2. The virtualenv must be created ("virtualenv env") in the parent 
>directory of the Eclipse workspace, I suppose. This is one point of 
>confusion to me. I don't know either if I have to activate this every time 
>I come back for developing resuming the work from days before. I 
> completely 
>understand that later from Eclipse I will give the python path inside the 
>virtualenv, but don't know if must activate the virtualenv every time.
>3. Next step would be to install all the things we need (django, 
>pillow, psycopg2) using a requirements.txt file. "pip install -r 
>requirements.txt"
>4. We should create the new django project with a python 
>django-admin.py startproject 
>5. Now I don't know if we should link the project to an already 
>installed version of Eclipse or run the "git init" first. I understand 
>that Eclipse and Git don't need to be installed inside the virtualenv. In 
>fact, I've been reading and it seems that Eclipse can work OK just by 
> being 
>given the path inside the virtualenv where the python executable is 
>located. I've also read that some people used to make different 
> workspaces, 
>but configuring the paths should be enough 
>http://stackoverflow.com/questions/1145374/virtualenv-with-eclipse-galileo
>
> From here I would just upload to github or bitbucket, maybe doing the 
> whole thing from Eclipse would be easier. But the integration with Eclipse 
> when we made tangowithdjango tutorial was the difficult point, because 
> there is no option for importing a django project from Eclipse (Kepler 
> version last time). We found easier to create the project from Eclipse, but 
> we were not using a virtualenv for the tutorial.
>
> I haven't used virtualenv before, so it's our second main obstacle, but I 
> expect it will be easy when we get used to it (^_^) .
>
> Please could someone help with some piece of advice, pros and cons of 
> every option. Just don't want to do something now I will regret in future.
>
> Thank you veeery much in advance.
>
> PS: Some links visited:
> http://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/
> http://www.tangowithdjango.com/book/chapters/setup.html
> https://virtualenv.pypa.io/en/latest/virtualenv.html
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/397abd48-4a73-42dd-8350-ea1c6be48fe1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie: Complete environment setup(virtualenv, pip, eclipse, git...)

2014-07-21 Thread Tom Evans
On Sun, Jul 20, 2014 at 1:41 AM, Martin Torre Castro  wrote:
> Hello,
>
> my name is Martin and I'm a computer engineer from Spain. I'm going to start
> a new project with a colleague and I decided to use Django because we
> searched for free opensource tools and I'm in love with Python.
>
> We have made a couple of tutorials (the official one and "Tango with
> django"). I've also bought the book "Two scoops of Django" for the 1.6
> Django edition. We're starting the project soon as well as we finish the
> design, but I'm concerned about setting up the new environment. We're
> thinking of using:
>
> postgresql
> Python/Django [ of course ;-) ]
> Eclipse/Pydev
> Git
> jQuery
>
> I've been reading the Greenfield/Roy book and some web sites and I want to
> set up the environment with good practices by using virtualenvwrapper,
> virtualenv, pip, the requirements.txt files and so on.
> I have made some mix for all this, but I would be grateful if someone could
> confirm us if we are on the right way, give us some advice or maybe tell us
> where on the internet we can find a good way of doing all this.
>
> My preview for the whole setting up is next:
>
> We should start the installations by installing "sudo apt-get install
> virtualenvwrapper" . If I understand correctly, this installs virtualenv as
> well as an embedded pip.
> The virtualenv must be created ("virtualenv env") in the parent directory of
> the Eclipse workspace, I suppose. This is one point of confusion to me. I
> don't know either if I have to activate this every time I come back for
> developing resuming the work from days before. I completely understand that
> later from Eclipse I will give the python path inside the virtualenv, but
> don't know if must activate the virtualenv every time.
> Next step would be to install all the things we need (django, pillow,
> psycopg2) using a requirements.txt file. "pip install -r requirements.txt"
> We should create the new django project with a python django-admin.py
> startproject 
> Now I don't know if we should link the project to an already installed
> version of Eclipse or run the "git init" first. I understand that Eclipse
> and Git don't need to be installed inside the virtualenv. In fact, I've been
> reading and it seems that Eclipse can work OK just by being given the path
> inside the virtualenv where the python executable is located. I've also read
> that some people used to make different workspaces, but configuring the
> paths should be enough
> http://stackoverflow.com/questions/1145374/virtualenv-with-eclipse-galileo
>
> From here I would just upload to github or bitbucket, maybe doing the whole
> thing from Eclipse would be easier. But the integration with Eclipse when we
> made tangowithdjango tutorial was the difficult point, because there is no
> option for importing a django project from Eclipse (Kepler version last
> time). We found easier to create the project from Eclipse, but we were not
> using a virtualenv for the tutorial.
>
> I haven't used virtualenv before, so it's our second main obstacle, but I
> expect it will be easy when we get used to it (^_^) .
>
> Please could someone help with some piece of advice, pros and cons of every
> option. Just don't want to do something now I will regret in future.
>
> Thank you veeery much in advance.
>
> PS: Some links visited:
> http://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/
> http://www.tangowithdjango.com/book/chapters/setup.html
> https://virtualenv.pypa.io/en/latest/virtualenv.html
>

Hi Martin

Everything you've said seems on the right path. For your couple of queries:

You need to activate the virtualenv each time you want to run python
within that environment. You simplify this by putting the path to the
environment in to Eclipse as this also 'activates' the environment, so
that every time you run something through Eclipse you do not need to
first activate the environment.

Typically, you would need to activate the environment to do things
like run your project from the command line, or install python
packages in to the environment.

Another useful technique I use is to have a "bootstrap" script, a
simple shell script that installs a virtualenv if it does not already
exist, activates that environment; and then installs or upgrades all
the packages listed in requirements.txt. This script can then be run
whenever to ensure the environment is up to date and correct.

  #!/bin/sh
  if [ ! -d env ]; then
  virtualenv env
  fi
  ln -sf ./env/bin/activate
  . ./activate
  pip install --upgrade -r requirements.txt

Give your projects differently named environments - don't call them
all 'env', or you will inevitably install something in the wrong env.

When writing your requirements file, you can track security releases
of libraries by specifying like this:

  django>1.6<1.7

This would install the latest security release in the 1.6 line of
django, and every time you re-run bootstrap, it will install any 

Question about including CSRF token.

2014-07-21 Thread Chen Xu
Hi Everyone,
I am writing a website using Django, and getting confused about CSRF token,
I understand I need to include the csrf token on my web page to prevent the
CSRF attack. However, I am also working on a mobile app, which will sends
request to my website API, and get response back, how should I handle the
CSRF token problem in this case?


Thanks

-- 
⚡ Chen Xu ⚡

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACac-qaboHwAb6op6VDymu20vyUBa8BOMSzUr1ypEFUruvYGUA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie: Complete environment setup(virtualenv, pip, eclipse, git...)

2014-07-21 Thread ngangsia akumbo
If you are working with windows , let me give you a very simple guide.
Google and download setuptools.exe and install in to your computer.

First install python 2.7 ans set the python path
Then move to this directory C:\Python27\scripts in the windows command .
You should run easy_install pip 
Then also run easy install virtualevn and your virtual env will be install 
in that directory alone.

Then to create you environment you run this command 
virtualenv --no-site-packages [name of your environment]
for example virtualenv --no-site-packages django_test

Then to activate this environment you type this command
[name of your enviroment]\scripts\activate   make sure you do all this in 
that directory abovee

for example
C:\Python27\scripts\django_test\scripts\activate
then your environment will be activated

Then move to this directory cd django_test
you path will become C:\Python27\scripts\django_test.

Then run pip install django [you can specify the version]

then when django is install move to the directory as so
run the dir command you will see the downloaded django

move to the downloaded django as using this command

cd Django-1.4.3 depending on the version of your django
To install the django now in to the system , type 

setup.py install in this directory 
C:\Python27\scripts\django_test\Django-1.4.3. That will depend your 
directory 

django will be install
then move to cd django
C:\Python27\scripts\django_test\Django-1.4.3\django

move to C:\Python27\scripts\django_test\Django-1.4.3\django\bin\

the u will have to create your projects

run this command withtin that sam directory

C:\Python27\scripts\django_test\Django-1.4.3\django\bin\django-admin.py 
startproject [name of your project]


Then you can figure out the rest
Thanks



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/371195f9-f729-46d0-82a1-65974b844464%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Initial data in 1.7

2014-07-21 Thread Tomas Ehrlich
Hi there,
as pointed in documentation [1], automatic loading of initial data from
initial_data.[xml/yaml/json] is deprecated since 1.7 in favor of data
migrations.

However, there are several drawbacks and differencies:

  1. Data migration is executed only once (unless migrations are
 rewinded to the beginning), while initial_data were loaded
 everytime with syncdb command.

 Former behavior ensures that the right data are present in table.
 Of course it can be used with data which doesn't change often
 (like sites).

  2. It's not straightforward to provide initial data to existing or
 third-party apps. One have to create custom app to store migrations
 (like 'initial_data') and then create *empty* models.py in app
 directory. Otherwise migrations won't be loaded, as already pointed
 in [2].

What's the correct way to provide initial data to apps which needs to be
present everytime, otherwise website won't work (like sites, auth
token, superadmins, etc.)?

Have anyone solved this issue recently in Django 1.7?


Thanks,
   Tom

[1] 
https://docs.djangoproject.com/en/dev/howto/initial-data/#automatically-loading-initial-data-fixtures
[2] 
https://groups.google.com/d/msgid/django-users/20140715142108.GA10827%40rkade-thinkpad

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20140721191447.46b17e63%40bodhi.
For more options, visit https://groups.google.com/d/optout.


Re: managing temporarily created files

2014-07-21 Thread alghafli

Dear Paul,
Thank you for the fast and useful reply. However, I have two questions.
According to django documentation, HttpResponse accepts string 
parameter. Does it also accept binary data. I am using python3 in which 
string is a unicode string and binary data are stored in bytes class.
Second, I am planning to use ezodf library to create odt files. It 
appears that there is no way I can access data from memory in this 
library. do you know of any good python library that can create and 
modify odt files?


Thank you

على الإثنين 21 تـمـوز 2014 18:49, كتب Paul J Stevens:


On 21-07-14 17:09, alghafli wrote:


I want to dynamically create a temporary odt file and upload it to the
client. The file is dynamically created based on GET request parameters.
It basically searches the database and fills the odt file with
information. This file is temporary and should be deleted after the
upload finishes.

tempfile.TemporaryFile is what you seem to want. The file object is
deleted automatically.

fd = tempfile.TemporaryFile()
fd.write(odt_data)
fd.seek(0)
return HttpResponse(
 fd.read(),
 content_type='application/vnd.oasis.opendocument.text'
)

But then you might as well skip the tempfile feature, and stream
directly from memory:

return HttpResponse(
 odt_data,
 content_type='application/vnd.oasis.opendocument.text'
)



Here is how I am planning to do it. The view function creates the file
and fills it with information. The file is created in a directory which
is added to the STATICFILES_DIRS. The view then redirects to the file
url and the client downloads the file.

Since your odt data is for one-time-only usage, you don't need to put
them in any kind of STATIC_FILES directory. That feature is of use to
offload download performance to the web-server, but for one-time-only
downloads there is no point.


To delete the files, I am planning to create a class that handles
temporary file creation and deletion. The class forces an upper limit to
temporary files number, say 10. Any file created after 10 files will
make the class delete older files based on modification time. I might as
well create a thread that would delete files regularly but it would be a
bit more complicated and unnecessary for this specific project.

Done already by the tempfile.TemporaryFile class, and totally redundant
when streaming from memory.




--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53CD4326.80404%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Recommendation/alternative for multi-tenancy under django

2014-07-21 Thread Subodh Nijsure
Unfortunately one of our requirement is to use mySQL. So this wouldn't
work with that correct?

To be honest at this moment I am not sure of pros & cons of using
mySQl v/s postgres  I will do some more research on that and see if
switching to postgres SQL is an option.

-Subodh

On Fri, Jul 18, 2014 at 9:11 PM, carlos  wrote:
> Hi, Subodh right now i find information for multi-tenant project in django
> and see
> this app, i never used only i read information for the future project.
>
> https://github.com/bernardopires/django-tenant-schemas
>
> maybe help you.
>
> Cheers
>
>
> On Fri, Jul 18, 2014 at 6:56 PM, Mike Dewhirst 
> wrote:
>>
>> On 19/07/2014 3:51 AM, Subodh Nijsure wrote:
>>>
>>> This is the first time I am trying to implement multi-tenant setup
>>> under django and hence the question.
>>>
>>> Problem/Setup
>>> - There are two companies signed up for service from portal I am
>>> developing say  CompanyA, CompanyB.
>>>
>>> - Each user with this setup is identified by unique email address,
>>> users login using their email address and password.
>>>
>>> - CompanyA has following users
>>>  A-tech1
>>>  A-tech2
>>>  A-tech3
>>>
>>> - CompanyB has following users
>>>  B-tech1
>>>  B-tech2
>>>  B-tech3
>>>
>>> Requirements:
>>>
>>> 1. Data security/isolation:Technician A-tech1, A-tech2, A-tech3
>>> should only be able to view data associated with companyA. Same for
>>> B-tech* technicians should only be able to see data from companyB.
>>>
>>> 2. Scalability: CompanyA, CompanyB might be of different sizes -
>>> companyA might have 10 users. While CompanyB might have 1s users
>>> representing large customers.
>>> 3. SLA: There might be different service level agreement with companyA
>>>   & companyB.
>>>
>>>
>>> I think, it doesn't make sense to lump data related to companyA, companyB
>>> into same database.
>>>
>>> Proposed Architecture Possibilities:
>>>
>>> Path 1:
>>> -  system will use one replicated database for
>>> authentication/authorization
>>> - When a company is registered within the system, 'Administrator' will
>>> assign a company to specific database connection. And request will be
>>> routed  to correct database using database router, based on currently
>>> logged in user.
>>>
>>> See https://docs.djangoproject.com/en/dev/topics/db/multi-db/ for
>>> multi-db applications under django.
>>>
>>> Path 2:
>>>
>>> Do the url based routing  c1.company.com , c2.company.com in apache
>>> server setup  and let apache configuraion refer to different wsgi.py
>>> scripts to set  proper values for DJANGO_SETTING_MODULE.   And each
>>> settings file points to different databases.
>>>
>>> Are either of these approaches (1 or 2) work better?
>>
>>
>> Another possible approach (in Postgres) is to keep everything in the same
>> database but segregate the private tables into different schemas. Normally
>> in Postgres everything goes into the public schema and you deal with privacy
>> using decorators and logic. But you could use non-public schemas as a
>> different segregation level. I'm not sure how easy or otherwise that might
>> be using Django.
>>
>> I have a similar if not identical privacy/segregation requirement which
>> needs to be solved before I can advance from prototype to production. Hence
>> I'm very interested in how you solve yours. Please share ...
>>
>> Mike
>>
>>
>>
>>> -Subodh
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/53C9C227.7020405%40dewhirst.com.au.
>>
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAM-7rO3eWkc_ixxoxSK%3DMUXgKicy%2Bc0Uc1%2B4ugjPWecTrLrYFw%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.go

Re: Dictionary-style string formatting

2014-07-21 Thread Paul J Stevens
https://docs.python.org/2/library/stdtypes.html#string-formatting-operations



On 21-07-14 16:21, François Schiettecatte wrote:
> Hi
> 
> Here it tells me that 'The given URL may contain dictionary-style string 
> formatting...':
> 
>   
> https://docs.djangoproject.com/en/1.6/ref/class-based-views/base/#redirectview
> 
> and to get it to work I have to put an 's' at the end of the url parameters:
> 
> url('^(?P\d{6})$', RedirectView.as_view(url='/entry/%(number)s')),
> 
> Why is there an 's' ? I could not find documentation on this.
> 
> Thanks
> 
> François
> 

-- 

Paul J Stevens   pjstevns @ gmail, twitter, github, linkedin
   www.nfg.nl/i...@nfg.nl/+31.85.877.99.97

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53CD37A5.3020401%40nfg.nl.
For more options, visit https://groups.google.com/d/optout.


Re: managing temporarily created files

2014-07-21 Thread Paul J Stevens


On 21-07-14 17:09, alghafli wrote:

> I want to dynamically create a temporary odt file and upload it to the
> client. The file is dynamically created based on GET request parameters.
> It basically searches the database and fills the odt file with
> information. This file is temporary and should be deleted after the
> upload finishes.

tempfile.TemporaryFile is what you seem to want. The file object is
deleted automatically.

fd = tempfile.TemporaryFile()
fd.write(odt_data)
fd.seek(0)
return HttpResponse(
fd.read(),
content_type='application/vnd.oasis.opendocument.text'
)

But then you might as well skip the tempfile feature, and stream
directly from memory:

return HttpResponse(
odt_data,
content_type='application/vnd.oasis.opendocument.text'
)


> Here is how I am planning to do it. The view function creates the file
> and fills it with information. The file is created in a directory which
> is added to the STATICFILES_DIRS. The view then redirects to the file
> url and the client downloads the file.

Since your odt data is for one-time-only usage, you don't need to put
them in any kind of STATIC_FILES directory. That feature is of use to
offload download performance to the web-server, but for one-time-only
downloads there is no point.

> To delete the files, I am planning to create a class that handles
> temporary file creation and deletion. The class forces an upper limit to
> temporary files number, say 10. Any file created after 10 files will
> make the class delete older files based on modification time. I might as
> well create a thread that would delete files regularly but it would be a
> bit more complicated and unnecessary for this specific project.

Done already by the tempfile.TemporaryFile class, and totally redundant
when streaming from memory.


-- 

Paul J Stevens   pjstevns @ gmail, twitter, github, linkedin
   www.nfg.nl/i...@nfg.nl/+31.85.877.99.97

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53CD368C.8090906%40nfg.nl.
For more options, visit https://groups.google.com/d/optout.


managing temporarily created files

2014-07-21 Thread alghafli

Hello django community,
I am currently developing my first web application. Since I am new to 
web development, I thought I should seek advice on what I am trying to 
implement at the moment.
Before I start, here are my questions: *can django do this?**if not, is 
there a python library that can do this? if not, am I doing it right?*


I want to dynamically create a temporary odt file and upload it to the 
client. The file is dynamically created based on GET request parameters. 
It basically searches the database and fills the odt file with 
information. This file is temporary and should be deleted after the 
upload finishes.


Here is how I am planning to do it. The view function creates the file 
and fills it with information. The file is created in a directory which 
is added to the STATICFILES_DIRS. The view then redirects to the file 
url and the client downloads the file.
To delete the files, I am planning to create a class that handles 
temporary file creation and deletion. The class forces an upper limit to 
temporary files number, say 10. Any file created after 10 files will 
make the class delete older files based on modification time. I might as 
well create a thread that would delete files regularly but it would be a 
bit more complicated and unnecessary for this specific project.


Thank you,
Mohammad

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53CD2D1F.8080102%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: looking for a good tutorial for creating user with fb,tw,google login

2014-07-21 Thread Luca Corti

Il 2014-07-20 20:53 Bussiere ha scritto:

there is no twitter in django-allauth.


Twitter is there.

https://github.com/pennersr/django-allauth/tree/master/allauth/socialaccount/providers/twitter

ciao

Luca

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4024840cd7fad53144dff247a79910eb%40mail.fantacast.it.
For more options, visit https://groups.google.com/d/optout.


Dictionary-style string formatting

2014-07-21 Thread François Schiettecatte
Hi

Here it tells me that 'The given URL may contain dictionary-style string 
formatting...':


https://docs.djangoproject.com/en/1.6/ref/class-based-views/base/#redirectview

and to get it to work I have to put an 's' at the end of the url parameters:

url('^(?P\d{6})$', RedirectView.as_view(url='/entry/%(number)s')),

Why is there an 's' ? I could not find documentation on this.

Thanks

François

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/C603820C-BBAF-4B99-B111-44FABC983F16%40gmail.com.
For more options, visit https://groups.google.com/d/optout.