Re: Use 3rd party django package in my own project (PYTHONPATH)

2015-05-11 Thread Mario Gudelj
Have you looked at
https://django-model-report.readthedocs.org/en/latest/installation.html ?

After you add it to "INSTALLED_APPS" (I guess that's what you meant by
adding it to 'Installed_Packages') you need to create reports.py etc. The
instructions on RTD are pretty good...

On 12 May 2015 at 05:21, Kasra Khosravi  wrote:

> i am creating a susbcription management system and I want to use a third
> party django package for reporting :
>
> https://github.com/juanpex/django-model-report
>
> Since I am new to django, I'm not sure how to use it, First I install it
> using pip (I have also tried installing it using setup.py), after that I
> think I have to add this package to my PYTHONPATH but I have no idea how to
> do it.
>
> After doing this, when I put that package under "Installed_Packages" in
> django settings.py, Nothing happends.
>
> i was wondering if anybody can help me with 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/ac50f0ad-ea9a-4e61-90ad-6d8ef281f329%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...@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/CAHqTbjk4A-wmeYrhRPUqQBvvkAM5ybnLMnnshv%2B6RamTBVZXqQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Switching settings, in a non-webapp?

2015-05-11 Thread Doug Blank
This ended up being just a simple Python3 issue, and the solution below
works fine, as far as I can tell so far. I post it here in case anyone
finds it useful:

I defined a "modules checkpoint" to which I can roll back to:

>>> from modules_checkpoint import ModulesCheckpoint
>>> checkpoint = ModulesCheckpoint()
>>> from gramps.webapp.databases.database1 import database
>>> database.dji.Person.all().count()
4
>>> checkpoint.reset()
>>> from gramps.webapp.databases.database2 import database
>>> database.dji.Person.all().count()
0
>>> checkpoint.reset()
>>> from gramps.webapp.databases.database1 import database
>>> database.dji.Person.all().count()
4

(showing the different counts in two different Django databases, defined in
different settings.py). Code is below.

-Doug

# modules_checkpoint.py
import sys
class ModulesCheckpoint(object):
def __init__(self):
self.original = sys.modules.copy()

def reset(self):
# clear modules:
for key in list(sys.modules.keys()):
del(sys.modules[key])
# load previous:
for key in self.original:
sys.modules[key] = self.original[key]


On Mon, May 11, 2015 at 12:17 PM, Doug Blank  wrote:

> Django users,
>
> We are using Django for two purposes: its ORM for a single-user desktop
> app, and for a regular Django webapp.
>
> For the desktop ORM, is there a way to switch between different
> settings.py? For example, we'd like to be able to load the default
> settings, but then later unload everything, and load different default
> settings.
>
> Looking for something like unloading/reloading all of the relevant
> sys.modules.
>
> We're using python3 if that matters.
>
> Thanks for any suggestions/pointers!
>
> -Doug
>

-- 
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/CAAusYCjbrM%2BWbOrfP0_3uC-QPDXtwMELnFdZLNdABhX97QmYqw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Defining base templates for reusable apps

2015-05-11 Thread Some Developer

On 09/05/15 11:47, Bruno A. wrote:

Hi,

I've never done it, but I myself want to do a similar thing, so I've
been thinking about it a bit. The solutions I've thought of are the
following:

  * Template inheritance, as you mention. You provide the base template,
but it might not be straightforward for the app's user to override.
The Django's admin is a good example of this, and it can be
customized partially or entirely by adding an admin directory in
your site's templates directory, there are also some apps providing
new interfaces
 entirely.
  * Use the include tag

to let your app's user define the main site canvas and just generate
some basic HTML in the middle of their page, with their navbar,
footer...
  * Along the same lines, provide in your apps custom template tags for
the CSS, the JS you need and the content of your pages.

Now, I guess it depends on the complexity of the content your app
provide, whether you need parameters, etc...



Yeah I'll have to think about this some more. In all my previous 
projects I have just used straight up template inheritance but in those 
projects I haven't had to worry about a user needing to customise the 
look and feel of the site.


By providing a base template it makes the project easier to develop but 
I also think it makes it harder to customise by other users of the 
project as they have to plugin in their own base template and create the 
required blocks for the other templates to inherit from.


--
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/55513F37.100%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Switching settings, in a non-webapp?

2015-05-11 Thread David Sieger
I think I understand now. Never mind, then. ;-)

Am 12.05.2015 um 00:00 schrieb Doug Blank:
> On Mon, May 11, 2015 at 4:44 PM, David Sieger  > wrote:
>
> If restarting the whole http service is an option, you could think
> about a setting up a separate service that is capable of
> stopping/starting your http service. You could then order this new
> service from within the http service to restart the http service
> with a different settings module. (I'm thinking ZeroMQ, but there
> are definitely other ways to implement this.)
>
>
> Thanks, but I think you have misunderstood... there is no http
> service... this is not a web app... only Python is involved. I need to
> reset the Django initialization in a Python session.
>
> -Doug
>  
>
>
> David
>
>
> Am 11.05.2015 um 18:17 schrieb Doug Blank:
>> Django users,
>>
>> We are using Django for two purposes: its ORM for a single-user
>> desktop app, and for a regular Django webapp.
>>
>> For the desktop ORM, is there a way to switch between different
>> settings.py? For example, we'd like to be able to load the
>> default settings, but then later unload everything, and load
>> different default settings.
>>
>> Looking for something like unloading/reloading all of the
>> relevant sys.modules.
>>
>> We're using python3 if that matters.
>>
>> Thanks for any suggestions/pointers!
>>
>> -Doug
>> -- 
>> 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/CAAusYCjPN3t61ku93rqhZxmV2eoLp90ddxPyqeTcEUQbx6B7bA%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.google.com/d/msgid/django-users/555114C7.1060306%40conceal.at
> 
> .
> 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/CAAusYCiD9PkB0_aO4bt2n8%2Bcp71KXog6%2B5UJh0fksAHCA4n8OA%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.google.com/d/msgid/django-users/55512983.5010809%40conceal.at.
For more options, visit https://groups.google.com/d/optout.


Re: Switching settings, in a non-webapp?

2015-05-11 Thread Doug Blank
On Mon, May 11, 2015 at 4:44 PM, David Sieger 
wrote:

>  If restarting the whole http service is an option, you could think about
> a setting up a separate service that is capable of stopping/starting your
> http service. You could then order this new service from within the http
> service to restart the http service with a different settings module. (I'm
> thinking ZeroMQ, but there are definitely other ways to implement this.)
>

Thanks, but I think you have misunderstood... there is no http service...
this is not a web app... only Python is involved. I need to reset the
Django initialization in a Python session.

-Doug


>
> David
>
>
> Am 11.05.2015 um 18:17 schrieb Doug Blank:
>
> Django users,
>
>  We are using Django for two purposes: its ORM for a single-user desktop
> app, and for a regular Django webapp.
>
>  For the desktop ORM, is there a way to switch between different
> settings.py? For example, we'd like to be able to load the default
> settings, but then later unload everything, and load different default
> settings.
>
>  Looking for something like unloading/reloading all of the relevant
> sys.modules.
>
>  We're using python3 if that matters.
>
>  Thanks for any suggestions/pointers!
>
>  -Doug
>  --
> 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/CAAusYCjPN3t61ku93rqhZxmV2eoLp90ddxPyqeTcEUQbx6B7bA%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.google.com/d/msgid/django-users/555114C7.1060306%40conceal.at
> 
> .
> 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/CAAusYCiD9PkB0_aO4bt2n8%2Bcp71KXog6%2B5UJh0fksAHCA4n8OA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Switching settings, in a non-webapp?

2015-05-11 Thread David Sieger
If restarting the whole http service is an option, you could think about
a setting up a separate service that is capable of stopping/starting
your http service. You could then order this new service from within the
http service to restart the http service with a different settings
module. (I'm thinking ZeroMQ, but there are definitely other ways to
implement this.)

David

Am 11.05.2015 um 18:17 schrieb Doug Blank:
> Django users,
>
> We are using Django for two purposes: its ORM for a single-user
> desktop app, and for a regular Django webapp.
>
> For the desktop ORM, is there a way to switch between different
> settings.py? For example, we'd like to be able to load the default
> settings, but then later unload everything, and load different default
> settings.
>
> Looking for something like unloading/reloading all of the relevant
> sys.modules.
>
> We're using python3 if that matters.
>
> Thanks for any suggestions/pointers!
>
> -Doug
> -- 
> 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/CAAusYCjPN3t61ku93rqhZxmV2eoLp90ddxPyqeTcEUQbx6B7bA%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.google.com/d/msgid/django-users/555114C7.1060306%40conceal.at.
For more options, visit https://groups.google.com/d/optout.


Use 3rd party django package in my own project (PYTHONPATH)

2015-05-11 Thread Kasra Khosravi
i am creating a susbcription management system and I want to use a third 
party django package for reporting :

https://github.com/juanpex/django-model-report

Since I am new to django, I'm not sure how to use it, First I install it 
using pip (I have also tried installing it using setup.py), after that I 
think I have to add this package to my PYTHONPATH but I have no idea how to 
do it.

After doing this, when I put that package under "Installed_Packages" in 
django settings.py, Nothing happends.

i was wondering if anybody can help me with 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/ac50f0ad-ea9a-4e61-90ad-6d8ef281f329%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Two questions on Django Tutorial.

2015-05-11 Thread Tim Graham
You are using Python 2, but the tutorial is written for Python 3 as noted 
in part 1. If you aren't willing to switch to Python 3, you can rename the 
__str__ method to __unicode__ as the comment indicates.

On Monday, May 11, 2015 at 12:35:39 PM UTC-4, SUBHABRATA BANERJEE wrote:
>
> Dear Group,
>
> I am very new to Django, and started with Django on Windows. I am using 
> Python 2.7.9. I have some 
> issues learning it. 
>
> (a) I was following the Tutorial given in 
> https://docs.djangoproject.com/en/1.8/intro/tutorial02/ 
> 
> It is generally going fine I am using, 1.8.1 of Django as given in 
> >>> django.get_version()
> '1.8.1'
> Here as I gave 
> python manage.py runserver
> I could find the login page, http://127.0.0.1:8000/admin/ and could login 
> using my login id and password.
> But as I changed the admin.py with admin.site.register(Question) I could 
> not find the changed view of the login page, rather it is 
> not coming anymore.
>
> (b) I was trying to follow the earlier part of the Tutorial given in,
> https://docs.djangoproject.com/en/1.8/intro/tutorial01/, things were 
> generally fine, 
> but somehow I am failing to follow, 
> def __str__(self):  # __unicode__ on Python 2
> return self.question_text
> in models.py, I am not being able to write models.py
> So, if I use it as,
> In [12]: Question.objects.all()
> Out[12]: []
>
> In [13]: from polls.models import Question, Choice
>
> In [14]: Question.objects.all()
> Out[14]: []
>
> In [15]: Question.objects.filter(id=1)
> Out[15]: []
>
> In [16]: Question.objects.filter(question_text__startswith='What')
> Out[16]: []
>
> In [17]: from polls.models import Question, Choice
>
> In [18]: Question.objects.all()
> Out[18]: []
>
> In [19]: Question.objects.filter(id=1)
> Out[19]: []
>
> I am not getting the desired output.
>
> If any one may kindly suggest what is the error I am doing.
>
> Thanks in advance,
> Regards,
> Subhabrata Banerjee. 
>
>
>
>
>
>
>
>
>  
>

-- 
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/2f79c374-40c3-46a4-9693-a753c9b92b13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Two questions on Django Tutorial.

2015-05-11 Thread SUBHABRATA BANERJEE
Dear Group,

I am very new to Django, and started with Django on Windows. I am using 
Python 2.7.9. I have some 
issues learning it. 

(a) I was following the Tutorial given in 
https://docs.djangoproject.com/en/1.8/intro/tutorial02/
It is generally going fine I am using, 1.8.1 of Django as given in 
>>> django.get_version()
'1.8.1'
Here as I gave 
python manage.py runserver
I could find the login page, http://127.0.0.1:8000/admin/ and could login 
using my login id and password.
But as I changed the admin.py with admin.site.register(Question) I could 
not find the changed view of the login page, rather it is 
not coming anymore.

(b) I was trying to follow the earlier part of the Tutorial given in,
https://docs.djangoproject.com/en/1.8/intro/tutorial01/, things were 
generally fine, 
but somehow I am failing to follow, 
def __str__(self):  # __unicode__ on Python 2
return self.question_text
in models.py, I am not being able to write models.py
So, if I use it as,
In [12]: Question.objects.all()
Out[12]: []

In [13]: from polls.models import Question, Choice

In [14]: Question.objects.all()
Out[14]: []

In [15]: Question.objects.filter(id=1)
Out[15]: []

In [16]: Question.objects.filter(question_text__startswith='What')
Out[16]: []

In [17]: from polls.models import Question, Choice

In [18]: Question.objects.all()
Out[18]: []

In [19]: Question.objects.filter(id=1)
Out[19]: []

I am not getting the desired output.

If any one may kindly suggest what is the error I am doing.

Thanks in advance,
Regards,
Subhabrata Banerjee. 








 

-- 
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/547a0366-b238-4c13-9978-e57450f84d6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Limitation

2015-05-11 Thread aRkadeFR

Please refer to all existing project in django:
http://stackoverflow.com/questions/886221/does-django-scale

:)

On 05/11/2015 06:15 PM, Arindam sarkar wrote:

can django be used for large projects ?

--
Regards,

Arindam

Contact no. 08732822385


--
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/CAGnF%2BrAZ7eeueOSbh7x33ARQEgTpCR156t4xpFyrco2SGgzMjQ%40mail.gmail.com 
.

For more options, visit https://groups.google.com/d/optout.


--
aRkadeFR

--
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/5550D767.5080406%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


DjangoCon US 2015 Proposals Deadline

2015-05-11 Thread Andrew Pinkham
There are only 4 days left to submit a proposal to DjangoCon US 2015 
!

We want to hear about your experience with and around Django. However, talks: 

- Don't need to be about Django specifically
- Don't need to be 100% fleshed out.
- Don't need to be purely technical
- Don't need to be advanced

The conference isn't until September, so if you have a kernel of an idea, 
submit that! 

Never spoken before? Not a problem! There are speaker mentors that will help 
you .

Is cost a concern? Not a problem! Apply for financial aid 

 (deadline also May 15th for speakers).

There is no reason not to apply! Here are two articles to get you started.

- Writing a PyCon Proposal by Brian Curtin 

- How to Submit a Kickass Talk to otsconf (or any other conf for that matter) 
by the OpenTechSchool Conference 


As always, feel free to contact us !

Submit your proposals soon, and we hope to see you at DjangoCon US!

Andrew

-- 
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/03C3A5AD-D660-4AA7-9B86-031FF0025B9D%40andrewsforge.com.
For more options, visit https://groups.google.com/d/optout.


Switching settings, in a non-webapp?

2015-05-11 Thread Doug Blank
Django users,

We are using Django for two purposes: its ORM for a single-user desktop
app, and for a regular Django webapp.

For the desktop ORM, is there a way to switch between different
settings.py? For example, we'd like to be able to load the default
settings, but then later unload everything, and load different default
settings.

Looking for something like unloading/reloading all of the relevant
sys.modules.

We're using python3 if that matters.

Thanks for any suggestions/pointers!

-Doug

-- 
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/CAAusYCjPN3t61ku93rqhZxmV2eoLp90ddxPyqeTcEUQbx6B7bA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django Limitation

2015-05-11 Thread Arindam sarkar
can django be used for large projects ?

-- 
Regards,

Arindam

Contact no. 08732822385

-- 
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/CAGnF%2BrAZ7eeueOSbh7x33ARQEgTpCR156t4xpFyrco2SGgzMjQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: SETTINGS Error

2015-05-11 Thread SUBHABRATA BANERJEE
I misread so deleted the question

-- 
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/a516f4a2-25c2-4213-98c6-fb788f3c99da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: SETTINGS Error

2015-05-11 Thread Sergiy Khohlov
You have not configured database in your setup. Your error is popped up in
this case.
11 трав. 2015 18:57, користувач "SUBHABRATA BANERJEE" <
subhabrata.bane...@gmail.com> написав:

> Dear Group,
>
> I am pretty new to Django. I was using
> https://docs.djangoproject.com/en/1.8/intro/tutorial01/ to learn aspects
> of Django.
> As I gave the command in IDLE,
> from django.db import models
>
> I am getting the error as,
> Traceback (most recent call last):
>   File "", line 1, in 
> from django.db import connection
>   File "C:\Python27\lib\site-packages\django\db\__init__.py", line 11, in
> 
> if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
>   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 53,
> in __getattr__
> self._setup(name)
>   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 46,
> in _setup
> % (desc, ENVIRONMENT_VARIABLE))
> ImproperlyConfigured: Requested setting DATABASES, but settings are not
> configured. You must either define the environment variable
> DJANGO_SETTINGS_MODULE or call settings.configure() before accessing
> settings.
>
> I tried to do some research on the problem in internet and did not find
> anything much of use.
>
> I am using Windows 7 Professional, Python 2.7.9 and IDLE as GUI. I am
> using
> >>> django.get_version()
> '1.5.4'
> as my django version, and learnt more or less how to use command prompt as
> given in this tutorial.
>
> If anyone may kindly suggest how to solve the problem.
>
> Regards,
> Subhabrata Banerjee.
>
> --
> 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/4a3531e6-de46-4106-bfaa-1787e9696d86%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...@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/CADTRxJPmT%2BMqUs9qJ14uyqiiZHa_TK_2kY%3D%3DG%2BTiScTVCfTaSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


SETTINGS Error

2015-05-11 Thread SUBHABRATA BANERJEE
Dear Group,

I am pretty new to Django. I was using 
https://docs.djangoproject.com/en/1.8/intro/tutorial01/ to learn aspects of 
Django.
As I gave the command in IDLE, 
from django.db import models

I am getting the error as,
Traceback (most recent call last):
  File "", line 1, in 
from django.db import connection
  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 11, in 

if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 53, in 
__getattr__
self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 46, in 
_setup
% (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting DATABASES, but settings are not 
configured. You must either define the environment variable 
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing 
settings.

I tried to do some research on the problem in internet and did not find 
anything much of use.

I am using Windows 7 Professional, Python 2.7.9 and IDLE as GUI. I am using 
>>> django.get_version()
'1.5.4'
as my django version, and learnt more or less how to use command prompt as 
given in this tutorial.

If anyone may kindly suggest how to solve the problem.

Regards,
Subhabrata Banerjee. 

-- 
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/4a3531e6-de46-4106-bfaa-1787e9696d86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: percentage or number data entry solution please

2015-05-11 Thread Mike Dewhirst

On 11/05/2015 11:42 PM, Derek wrote:

I realise this is probably overkill for your needs; but django-suit
allows for a ton of customisation options for the admin, one of which is
the ability to supply "units" as part of the data entry forms - see:
http://django-suit.readthedocs.org/en/latest/widgets.html#enclosedinput

Your other option is to provide functionality in the clean method to
convert "33.3%" (which is a string ) into 33.3 (numeric) and then store
the numeric value into another field... but that is messy.  I would
rather have my label say, for example:

Score(%): 

which is linked to a numeric only field.  And then have the form raise
an error (custom if need be) on that field if the user tries to enter
33.3% rather than 33.3  (sometimes users have to be willing to learn as
well :)


Which is what I am doing ... and will keep doing until there is an 
enhancement along the lines of a DecimalField arg/kwarg which lets the 
form accept a % sign but throws it away.


I have added some help text which explains what to do.

Thanks Derek

Mike


On Monday, 11 May 2015 02:45:00 UTC+2, Mike Dewhirst wrote:

In the Admin I want the user to be able to enter a decimal number
with a
percentage sign (eg 33.3%) or without (eg 33.3) and to collect it as a
decimal number.

At the moment DecimalField barfs if the user enters a human style
percentage sign.

My initial thought is to change it to a CharField and muck around
making
an awful mess behind the scenes to get - and store - the 0 to 100
decimal value I really want.

On the other hand, there is a snippet ...

https://djangosnippets.org/snippets/1914/


... which looks promising but I'm not sure how to get that into the
Admin

I have seen Django Extras has a PercentField but that seems to be a lot
of stuff to solve a small "simple" problem. Also, I haven't seen where
to slip it into the Admin

There is a ticket #17662 (now closed 'wontfix') but that focuses on
doing conversions which isn't what I'm after.

Here is another approach based on the snippet quoted above ...


http://stackoverflow.com/questions/6690692/problem-rendering-a-django-form-field-with-different-representation




... and which draws a suggestion to use a MultiValueField. I didn't try
too hard to understand the Django docs on MultiValueField because if
that is the answer I'm trying to fix the wrong problem.

I just want to ignore the percent sign if the user sticks it into a
DecimalField.

Thanks for any ideas

Mike

--
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/cebb28c2-9351-4d13-af3f-82c38d88b489%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...@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/5550BBF3.3010801%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: rollback the update query

2015-05-11 Thread Tom Evans
On Mon, May 11, 2015 at 11:44 AM, Simran Singh
 wrote:
> I am really new to Django and I am using Django 1.8. Many of the
> manual_transaction features have been depreciated in this. I have used
> @transaction.atomic(None, True)

nit; these are the defaults. You might as well just say:

  @transaction.atomic

> to pack the transaction and rollback the
> updates if at any point the condition is not met.
> I tried to store the transaction in savepoint and used  savepoint_rollback
> or savepoint_commit as per the condition. But I am having no luck here. No
> matter where the control goes but as soon as atomic block ends, it is
> committing the changes

Show the code. All you have shared so far is that you are using the
API; how you use it matters!

> in mysql db.

What storage engine are you using with mysql? MyISAM is
non-transactional; it accepts the SQL statements for transactions, but
always operates in autocommit mode.

Cheers

Tom

-- 
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/CAFHbX1LOP3whUoVmmO%2BeSn44UyTiy67XXucjeJDSWRxJP7VFmg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread Guilherme Leal
Puting plain, you just need to execute a POST request on the client side.
That makes aviable the content on the request.POST property on your client
side view.

Wich tecnology you use to make the post request doesnt matter. The only
thing you need to keep in mind is when you "navigate" through your browser,
you're making a GET request, not a POST. Thats why your request didnt had a
body on the exemple you previously provided.

If you explained a little bit more of your app context, would be easier to
explain more.

2015-05-11 10:51 GMT-03:00 steve malise :

> I want to display HTTP POST data from client side to on the server side and
> what am supposed do to achieve?
>
> On Mon, May 11, 2015 at 3:31 PM, Jani Tiainen  wrote:
>
>> Hi,
>>
>> Sounds like you're mixing up terms and technologies here and really you
>> are trying something that Django was never designed for.
>>
>> It would be really helpful to know what are you really trying to do,
>> instead of just trying techniques that may or may not work for your case.
>>
>>
>> On Mon, 11 May 2015 15:18:37 +0200
>> steve malise  wrote:
>>
>> > Meaning write JavaScript code to make a request?
>> > how can achieve it other than writing JavaScript code?
>> >
>> >
>> > On Mon, May 11, 2015 at 3:13 PM, Guilherme Leal 
>> wrote:
>> >
>> > > The "navigation" of your browser always performs a GET method. If
>> you're
>> > > trying to test that kind of request in the browser, the best aproach
>> would
>> > > be open the JavaScript and make the request there.
>> > >
>> > > 2015-05-11 10:09 GMT-03:00 steve malise :
>> > >
>> > >> client code:
>> > >> import httplib
>> > >> import urllib
>> > >>
>> > >> data = urllib.urlencode({'data':'data1'})
>> > >> conn = httplib.HTTPConnection(myipaddr)
>> > >> headers = {"Content-type":"application/x-www-form-urlencoded",
>> > >> "Accept":"text/plain",
>> > >>  "Content-Length:":len(data)}
>> > >> h.request('POST','/',data,headers)
>> > >>
>> > >> res = h.getresponse()
>> > >> print r.status,r.reason
>> > >>
>> > >> server side code(view.py):
>> > >>
>> > >> from django.shortcuts import render
>> > >> from django.views.decorators.csrf import csrf_exempt
>> > >> from django.http import HttpResponse
>> > >> from django.conf.urls import url
>> > >> from django.template import loader
>> > >> from django.utils.timezone import utc
>> > >> from django.template import Context, Template
>> > >> from django.template.loader import get_template
>> > >> from django.shortcuts import render_to_response
>> > >> from django.template import RequestContext
>> > >> from myapp.models import Temperature
>> > >> from myapp import models
>> > >> import socket , select
>> > >> import os
>> > >> import datetime
>> > >> socktetList=[]
>> > >>
>> > >>
>> > >> @csrf_exempt
>> > >> def myview(request):
>> > >> if request.method == 'POST':
>> > >> return HttpResponse("%s %s" % (request.method, request.body))
>> > >> #print POST body
>> > >> else:
>> > >> return HttpResponse("%s %s" % (request.method, request.body))
>> > >>
>> > >> on the client side i get "200 OK"(everything is ok)
>> > >> but when i open my browser it return "GET",
>> > >>
>> > >> i want it to return or display POST DATA.
>> > >>
>> > >> how can i do that??
>> > >> please help
>> > >>
>> > >>
>> > >>
>> > >> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com>
>> wrote:
>> > >>
>> > >>> On 07 May 16:00, steve malise wrote:
>> > >>> > The error comes when i runserver and send data from another
>> computer to
>> > >>> > django,then i get this "code 400, message Bad request syntax (
>> data
>> > >>> from
>> > >>> > another computer)"
>> > >>>
>> > >>> This is because
>> > >>>
>> > >>> On 07 May 11:42, Tom Evans wrote:
>> > >>> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use
>> one
>> > >>> > of the http libraries built in to python:
>> > >>>
>> > >>> You can find here some directions on forming the request validly,
>> > >>> http://www.w3.org/Protocols/Specs.html
>> > >>>
>> > >>> as you apparently don't want to use any of the libraries below.
>> > >>>
>> > >>> On 07 May 16:00, steve malise wrote:
>> > >>> > urllib2:
>> > >>> > https://docs.python.org/2/howto/urllib2.html#data
>> > >>> >
>> > >>> > httplib:
>> > >>> > https://docs.python.org/2/library/httplib.html#examples
>> > >>> >
>> > >>> > or use a 3rd party library that wraps those in a more pleasing
>> > >>> interface:
>> > >>> >
>> > >>> > requests:
>> > >>> > http://docs.python-requests.org/en/latest/
>> > >>>
>> > >>> Using one of the above-listed libraries would still accomplish what
>> you
>> > >>> are trying to do, as you described here,
>> > >>>
>> > >>> On 07 May 16:00, steve malise wrote:
>> > >>> > What i am trying to do is run python script(client side) on
>> another
>> > >>> > computer which is on same network with my computer,then 

Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread steve malise
I want to display HTTP POST data from client side to on the server side and
what am supposed do to achieve?

On Mon, May 11, 2015 at 3:31 PM, Jani Tiainen  wrote:

> Hi,
>
> Sounds like you're mixing up terms and technologies here and really you
> are trying something that Django was never designed for.
>
> It would be really helpful to know what are you really trying to do,
> instead of just trying techniques that may or may not work for your case.
>
>
> On Mon, 11 May 2015 15:18:37 +0200
> steve malise  wrote:
>
> > Meaning write JavaScript code to make a request?
> > how can achieve it other than writing JavaScript code?
> >
> >
> > On Mon, May 11, 2015 at 3:13 PM, Guilherme Leal 
> wrote:
> >
> > > The "navigation" of your browser always performs a GET method. If
> you're
> > > trying to test that kind of request in the browser, the best aproach
> would
> > > be open the JavaScript and make the request there.
> > >
> > > 2015-05-11 10:09 GMT-03:00 steve malise :
> > >
> > >> client code:
> > >> import httplib
> > >> import urllib
> > >>
> > >> data = urllib.urlencode({'data':'data1'})
> > >> conn = httplib.HTTPConnection(myipaddr)
> > >> headers = {"Content-type":"application/x-www-form-urlencoded",
> > >> "Accept":"text/plain",
> > >>  "Content-Length:":len(data)}
> > >> h.request('POST','/',data,headers)
> > >>
> > >> res = h.getresponse()
> > >> print r.status,r.reason
> > >>
> > >> server side code(view.py):
> > >>
> > >> from django.shortcuts import render
> > >> from django.views.decorators.csrf import csrf_exempt
> > >> from django.http import HttpResponse
> > >> from django.conf.urls import url
> > >> from django.template import loader
> > >> from django.utils.timezone import utc
> > >> from django.template import Context, Template
> > >> from django.template.loader import get_template
> > >> from django.shortcuts import render_to_response
> > >> from django.template import RequestContext
> > >> from myapp.models import Temperature
> > >> from myapp import models
> > >> import socket , select
> > >> import os
> > >> import datetime
> > >> socktetList=[]
> > >>
> > >>
> > >> @csrf_exempt
> > >> def myview(request):
> > >> if request.method == 'POST':
> > >> return HttpResponse("%s %s" % (request.method, request.body))
> > >> #print POST body
> > >> else:
> > >> return HttpResponse("%s %s" % (request.method, request.body))
> > >>
> > >> on the client side i get "200 OK"(everything is ok)
> > >> but when i open my browser it return "GET",
> > >>
> > >> i want it to return or display POST DATA.
> > >>
> > >> how can i do that??
> > >> please help
> > >>
> > >>
> > >>
> > >> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com>
> wrote:
> > >>
> > >>> On 07 May 16:00, steve malise wrote:
> > >>> > The error comes when i runserver and send data from another
> computer to
> > >>> > django,then i get this "code 400, message Bad request syntax ( data
> > >>> from
> > >>> > another computer)"
> > >>>
> > >>> This is because
> > >>>
> > >>> On 07 May 11:42, Tom Evans wrote:
> > >>> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use
> one
> > >>> > of the http libraries built in to python:
> > >>>
> > >>> You can find here some directions on forming the request validly,
> > >>> http://www.w3.org/Protocols/Specs.html
> > >>>
> > >>> as you apparently don't want to use any of the libraries below.
> > >>>
> > >>> On 07 May 16:00, steve malise wrote:
> > >>> > urllib2:
> > >>> > https://docs.python.org/2/howto/urllib2.html#data
> > >>> >
> > >>> > httplib:
> > >>> > https://docs.python.org/2/library/httplib.html#examples
> > >>> >
> > >>> > or use a 3rd party library that wraps those in a more pleasing
> > >>> interface:
> > >>> >
> > >>> > requests:
> > >>> > http://docs.python-requests.org/en/latest/
> > >>>
> > >>> Using one of the above-listed libraries would still accomplish what
> you
> > >>> are trying to do, as you described here,
> > >>>
> > >>> On 07 May 16:00, steve malise wrote:
> > >>> > What i am trying to do is run python script(client side) on another
> > >>> > computer which is on same network with my computer,then receive
> data
> > >>> from
> > >>> > another computer with the django(which is running on my
> computer(server
> > >>> > side)).i am using built-in "runserver".
> > >>>
> > >>> so I suspect that you are doing something more that we missed.
> Perhaps
> > >>> you could tell us why you want to do 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 

Re: percentage or number data entry solution please

2015-05-11 Thread Derek
I realise this is probably overkill for your needs; but django-suit allows 
for a ton of customisation options for the admin, one of which is the 
ability to supply "units" as part of the data entry forms - see:
http://django-suit.readthedocs.org/en/latest/widgets.html#enclosedinput

Your other option is to provide functionality in the clean method to 
convert "33.3%" (which is a string ) into 33.3 (numeric) and then store the 
numeric value into another field... but that is messy.  I would rather have 
my label say, for example:

Score(%): 

which is linked to a numeric only field.  And then have the form raise an 
error (custom if need be) on that field if the user tries to enter 33.3% 
rather than 33.3  (sometimes users have to be willing to learn as well :)

On Monday, 11 May 2015 02:45:00 UTC+2, Mike Dewhirst wrote:
>
> In the Admin I want the user to be able to enter a decimal number with a 
> percentage sign (eg 33.3%) or without (eg 33.3) and to collect it as a 
> decimal number. 
>
> At the moment DecimalField barfs if the user enters a human style 
> percentage sign. 
>
> My initial thought is to change it to a CharField and muck around making 
> an awful mess behind the scenes to get - and store - the 0 to 100 
> decimal value I really want. 
>
> On the other hand, there is a snippet ... 
>
> https://djangosnippets.org/snippets/1914/ 
>
> ... which looks promising but I'm not sure how to get that into the Admin 
>
> I have seen Django Extras has a PercentField but that seems to be a lot 
> of stuff to solve a small "simple" problem. Also, I haven't seen where 
> to slip it into the Admin 
>
> There is a ticket #17662 (now closed 'wontfix') but that focuses on 
> doing conversions which isn't what I'm after. 
>
> Here is another approach based on the snippet quoted above ... 
>
>
> http://stackoverflow.com/questions/6690692/problem-rendering-a-django-form-field-with-different-representation
>  
>
> ... and which draws a suggestion to use a MultiValueField. I didn't try 
> too hard to understand the Django docs on MultiValueField because if 
> that is the answer I'm trying to fix the wrong problem. 
>
> I just want to ignore the percent sign if the user sticks it into a 
> DecimalField. 
>
> Thanks for any ideas 
>
> Mike 
>

-- 
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/cebb28c2-9351-4d13-af3f-82c38d88b489%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread Jani Tiainen
Hi,

Sounds like you're mixing up terms and technologies here and really you are 
trying something that Django was never designed for.

It would be really helpful to know what are you really trying to do, instead of 
just trying techniques that may or may not work for your case.


On Mon, 11 May 2015 15:18:37 +0200
steve malise  wrote:

> Meaning write JavaScript code to make a request?
> how can achieve it other than writing JavaScript code?
> 
> 
> On Mon, May 11, 2015 at 3:13 PM, Guilherme Leal  wrote:
> 
> > The "navigation" of your browser always performs a GET method. If you're
> > trying to test that kind of request in the browser, the best aproach would
> > be open the JavaScript and make the request there.
> >
> > 2015-05-11 10:09 GMT-03:00 steve malise :
> >
> >> client code:
> >> import httplib
> >> import urllib
> >>
> >> data = urllib.urlencode({'data':'data1'})
> >> conn = httplib.HTTPConnection(myipaddr)
> >> headers = {"Content-type":"application/x-www-form-urlencoded",
> >> "Accept":"text/plain",
> >>  "Content-Length:":len(data)}
> >> h.request('POST','/',data,headers)
> >>
> >> res = h.getresponse()
> >> print r.status,r.reason
> >>
> >> server side code(view.py):
> >>
> >> from django.shortcuts import render
> >> from django.views.decorators.csrf import csrf_exempt
> >> from django.http import HttpResponse
> >> from django.conf.urls import url
> >> from django.template import loader
> >> from django.utils.timezone import utc
> >> from django.template import Context, Template
> >> from django.template.loader import get_template
> >> from django.shortcuts import render_to_response
> >> from django.template import RequestContext
> >> from myapp.models import Temperature
> >> from myapp import models
> >> import socket , select
> >> import os
> >> import datetime
> >> socktetList=[]
> >>
> >>
> >> @csrf_exempt
> >> def myview(request):
> >> if request.method == 'POST':
> >> return HttpResponse("%s %s" % (request.method, request.body))
> >> #print POST body
> >> else:
> >> return HttpResponse("%s %s" % (request.method, request.body))
> >>
> >> on the client side i get "200 OK"(everything is ok)
> >> but when i open my browser it return "GET",
> >>
> >> i want it to return or display POST DATA.
> >>
> >> how can i do that??
> >> please help
> >>
> >>
> >>
> >> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com> 
> >> wrote:
> >>
> >>> On 07 May 16:00, steve malise wrote:
> >>> > The error comes when i runserver and send data from another computer to
> >>> > django,then i get this "code 400, message Bad request syntax ( data
> >>> from
> >>> > another computer)"
> >>>
> >>> This is because
> >>>
> >>> On 07 May 11:42, Tom Evans wrote:
> >>> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
> >>> > of the http libraries built in to python:
> >>>
> >>> You can find here some directions on forming the request validly,
> >>> http://www.w3.org/Protocols/Specs.html
> >>>
> >>> as you apparently don't want to use any of the libraries below.
> >>>
> >>> On 07 May 16:00, steve malise wrote:
> >>> > urllib2:
> >>> > https://docs.python.org/2/howto/urllib2.html#data
> >>> >
> >>> > httplib:
> >>> > https://docs.python.org/2/library/httplib.html#examples
> >>> >
> >>> > or use a 3rd party library that wraps those in a more pleasing
> >>> interface:
> >>> >
> >>> > requests:
> >>> > http://docs.python-requests.org/en/latest/
> >>>
> >>> Using one of the above-listed libraries would still accomplish what you
> >>> are trying to do, as you described here,
> >>>
> >>> On 07 May 16:00, steve malise wrote:
> >>> > What i am trying to do is run python script(client side) on another
> >>> > computer which is on same network with my computer,then receive data
> >>> from
> >>> > another computer with the django(which is running on my computer(server
> >>> > side)).i am using built-in "runserver".
> >>>
> >>> so I suspect that you are doing something more that we missed. Perhaps
> >>> you could tell us why you want to do 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/20150507141332.GA27942%40d1stkfactory
> >>> .
> >>> 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 

Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread Guilherme Leal
Just to clarify, in your browser, if you simply "navigate" to the url of
your view, the browser will issue a GET to the server.

If you write the JavaScript function, you can specify the method of your
request... preaty much the same thing as you did in the exemple that you
sent.

Its fairly trivial, and JQuery makes it even simpler
.



2015-05-11 10:18 GMT-03:00 steve malise :

> Meaning write JavaScript code to make a request?
> how can achieve it other than writing JavaScript code?
>
>
> On Mon, May 11, 2015 at 3:13 PM, Guilherme Leal 
> wrote:
>
>> The "navigation" of your browser always performs a GET method. If you're
>> trying to test that kind of request in the browser, the best aproach would
>> be open the JavaScript and make the request there.
>>
>> 2015-05-11 10:09 GMT-03:00 steve malise :
>>
>>> client code:
>>> import httplib
>>> import urllib
>>>
>>> data = urllib.urlencode({'data':'data1'})
>>> conn = httplib.HTTPConnection(myipaddr)
>>> headers = {"Content-type":"application/x-www-form-urlencoded",
>>> "Accept":"text/plain",
>>>  "Content-Length:":len(data)}
>>> h.request('POST','/',data,headers)
>>>
>>> res = h.getresponse()
>>> print r.status,r.reason
>>>
>>> server side code(view.py):
>>>
>>> from django.shortcuts import render
>>> from django.views.decorators.csrf import csrf_exempt
>>> from django.http import HttpResponse
>>> from django.conf.urls import url
>>> from django.template import loader
>>> from django.utils.timezone import utc
>>> from django.template import Context, Template
>>> from django.template.loader import get_template
>>> from django.shortcuts import render_to_response
>>> from django.template import RequestContext
>>> from myapp.models import Temperature
>>> from myapp import models
>>> import socket , select
>>> import os
>>> import datetime
>>> socktetList=[]
>>>
>>>
>>> @csrf_exempt
>>> def myview(request):
>>> if request.method == 'POST':
>>> return HttpResponse("%s %s" % (request.method, request.body))
>>> #print POST body
>>> else:
>>> return HttpResponse("%s %s" % (request.method, request.body))
>>>
>>> on the client side i get "200 OK"(everything is ok)
>>> but when i open my browser it return "GET",
>>>
>>> i want it to return or display POST DATA.
>>>
>>> how can i do that??
>>> please help
>>>
>>>
>>>
>>> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com>
>>> wrote:
>>>
 On 07 May 16:00, steve malise wrote:
 > The error comes when i runserver and send data from another computer
 to
 > django,then i get this "code 400, message Bad request syntax ( data
 from
 > another computer)"

 This is because

 On 07 May 11:42, Tom Evans wrote:
 > Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
 > of the http libraries built in to python:

 You can find here some directions on forming the request validly,
 http://www.w3.org/Protocols/Specs.html

 as you apparently don't want to use any of the libraries below.

 On 07 May 16:00, steve malise wrote:
 > urllib2:
 > https://docs.python.org/2/howto/urllib2.html#data
 >
 > httplib:
 > https://docs.python.org/2/library/httplib.html#examples
 >
 > or use a 3rd party library that wraps those in a more pleasing
 interface:
 >
 > requests:
 > http://docs.python-requests.org/en/latest/

 Using one of the above-listed libraries would still accomplish what you
 are trying to do, as you described here,

 On 07 May 16:00, steve malise wrote:
 > What i am trying to do is run python script(client side) on another
 > computer which is on same network with my computer,then receive data
 from
 > another computer with the django(which is running on my
 computer(server
 > side)).i am using built-in "runserver".

 so I suspect that you are doing something more that we missed. Perhaps
 you could tell us why you want to do 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/20150507141332.GA27942%40d1stkfactory
 .
 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.

Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread steve malise
Meaning write JavaScript code to make a request?
how can achieve it other than writing JavaScript code?


On Mon, May 11, 2015 at 3:13 PM, Guilherme Leal  wrote:

> The "navigation" of your browser always performs a GET method. If you're
> trying to test that kind of request in the browser, the best aproach would
> be open the JavaScript and make the request there.
>
> 2015-05-11 10:09 GMT-03:00 steve malise :
>
>> client code:
>> import httplib
>> import urllib
>>
>> data = urllib.urlencode({'data':'data1'})
>> conn = httplib.HTTPConnection(myipaddr)
>> headers = {"Content-type":"application/x-www-form-urlencoded",
>> "Accept":"text/plain",
>>  "Content-Length:":len(data)}
>> h.request('POST','/',data,headers)
>>
>> res = h.getresponse()
>> print r.status,r.reason
>>
>> server side code(view.py):
>>
>> from django.shortcuts import render
>> from django.views.decorators.csrf import csrf_exempt
>> from django.http import HttpResponse
>> from django.conf.urls import url
>> from django.template import loader
>> from django.utils.timezone import utc
>> from django.template import Context, Template
>> from django.template.loader import get_template
>> from django.shortcuts import render_to_response
>> from django.template import RequestContext
>> from myapp.models import Temperature
>> from myapp import models
>> import socket , select
>> import os
>> import datetime
>> socktetList=[]
>>
>>
>> @csrf_exempt
>> def myview(request):
>> if request.method == 'POST':
>> return HttpResponse("%s %s" % (request.method, request.body))
>> #print POST body
>> else:
>> return HttpResponse("%s %s" % (request.method, request.body))
>>
>> on the client side i get "200 OK"(everything is ok)
>> but when i open my browser it return "GET",
>>
>> i want it to return or display POST DATA.
>>
>> how can i do that??
>> please help
>>
>>
>>
>> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com> wrote:
>>
>>> On 07 May 16:00, steve malise wrote:
>>> > The error comes when i runserver and send data from another computer to
>>> > django,then i get this "code 400, message Bad request syntax ( data
>>> from
>>> > another computer)"
>>>
>>> This is because
>>>
>>> On 07 May 11:42, Tom Evans wrote:
>>> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
>>> > of the http libraries built in to python:
>>>
>>> You can find here some directions on forming the request validly,
>>> http://www.w3.org/Protocols/Specs.html
>>>
>>> as you apparently don't want to use any of the libraries below.
>>>
>>> On 07 May 16:00, steve malise wrote:
>>> > urllib2:
>>> > https://docs.python.org/2/howto/urllib2.html#data
>>> >
>>> > httplib:
>>> > https://docs.python.org/2/library/httplib.html#examples
>>> >
>>> > or use a 3rd party library that wraps those in a more pleasing
>>> interface:
>>> >
>>> > requests:
>>> > http://docs.python-requests.org/en/latest/
>>>
>>> Using one of the above-listed libraries would still accomplish what you
>>> are trying to do, as you described here,
>>>
>>> On 07 May 16:00, steve malise wrote:
>>> > What i am trying to do is run python script(client side) on another
>>> > computer which is on same network with my computer,then receive data
>>> from
>>> > another computer with the django(which is running on my computer(server
>>> > side)).i am using built-in "runserver".
>>>
>>> so I suspect that you are doing something more that we missed. Perhaps
>>> you could tell us why you want to do 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/20150507141332.GA27942%40d1stkfactory
>>> .
>>> 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/CACwh%3D0zjAYKjmyTJTWcucTyLM_iVaLokcgqREZpXgzp7e_GEGw%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are 

Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread Guilherme Leal
The "navigation" of your browser always performs a GET method. If you're
trying to test that kind of request in the browser, the best aproach would
be open the JavaScript and make the request there.

2015-05-11 10:09 GMT-03:00 steve malise :

> client code:
> import httplib
> import urllib
>
> data = urllib.urlencode({'data':'data1'})
> conn = httplib.HTTPConnection(myipaddr)
> headers = {"Content-type":"application/x-www-form-urlencoded",
> "Accept":"text/plain",
>  "Content-Length:":len(data)}
> h.request('POST','/',data,headers)
>
> res = h.getresponse()
> print r.status,r.reason
>
> server side code(view.py):
>
> from django.shortcuts import render
> from django.views.decorators.csrf import csrf_exempt
> from django.http import HttpResponse
> from django.conf.urls import url
> from django.template import loader
> from django.utils.timezone import utc
> from django.template import Context, Template
> from django.template.loader import get_template
> from django.shortcuts import render_to_response
> from django.template import RequestContext
> from myapp.models import Temperature
> from myapp import models
> import socket , select
> import os
> import datetime
> socktetList=[]
>
>
> @csrf_exempt
> def myview(request):
> if request.method == 'POST':
> return HttpResponse("%s %s" % (request.method, request.body))
> #print POST body
> else:
> return HttpResponse("%s %s" % (request.method, request.body))
>
> on the client side i get "200 OK"(everything is ok)
> but when i open my browser it return "GET",
>
> i want it to return or display POST DATA.
>
> how can i do that??
> please help
>
>
>
> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com> wrote:
>
>> On 07 May 16:00, steve malise wrote:
>> > The error comes when i runserver and send data from another computer to
>> > django,then i get this "code 400, message Bad request syntax ( data from
>> > another computer)"
>>
>> This is because
>>
>> On 07 May 11:42, Tom Evans wrote:
>> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
>> > of the http libraries built in to python:
>>
>> You can find here some directions on forming the request validly,
>> http://www.w3.org/Protocols/Specs.html
>>
>> as you apparently don't want to use any of the libraries below.
>>
>> On 07 May 16:00, steve malise wrote:
>> > urllib2:
>> > https://docs.python.org/2/howto/urllib2.html#data
>> >
>> > httplib:
>> > https://docs.python.org/2/library/httplib.html#examples
>> >
>> > or use a 3rd party library that wraps those in a more pleasing
>> interface:
>> >
>> > requests:
>> > http://docs.python-requests.org/en/latest/
>>
>> Using one of the above-listed libraries would still accomplish what you
>> are trying to do, as you described here,
>>
>> On 07 May 16:00, steve malise wrote:
>> > What i am trying to do is run python script(client side) on another
>> > computer which is on same network with my computer,then receive data
>> from
>> > another computer with the django(which is running on my computer(server
>> > side)).i am using built-in "runserver".
>>
>> so I suspect that you are doing something more that we missed. Perhaps
>> you could tell us why you want to do 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/20150507141332.GA27942%40d1stkfactory
>> .
>> 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/CACwh%3D0zjAYKjmyTJTWcucTyLM_iVaLokcgqREZpXgzp7e_GEGw%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 

Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread steve malise
client code:
import httplib
import urllib

data = urllib.urlencode({'data':'data1'})
conn = httplib.HTTPConnection(myipaddr)
headers = {"Content-type":"application/x-www-form-urlencoded",
"Accept":"text/plain",
 "Content-Length:":len(data)}
h.request('POST','/',data,headers)

res = h.getresponse()
print r.status,r.reason

server side code(view.py):

from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from django.conf.urls import url
from django.template import loader
from django.utils.timezone import utc
from django.template import Context, Template
from django.template.loader import get_template
from django.shortcuts import render_to_response
from django.template import RequestContext
from myapp.models import Temperature
from myapp import models
import socket , select
import os
import datetime
socktetList=[]


@csrf_exempt
def myview(request):
if request.method == 'POST':
return HttpResponse("%s %s" % (request.method, request.body))
#print POST body
else:
return HttpResponse("%s %s" % (request.method, request.body))

on the client side i get "200 OK"(everything is ok)
but when i open my browser it return "GET",

i want it to return or display POST DATA.

how can i do that??
please help



On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com> wrote:

> On 07 May 16:00, steve malise wrote:
> > The error comes when i runserver and send data from another computer to
> > django,then i get this "code 400, message Bad request syntax ( data from
> > another computer)"
>
> This is because
>
> On 07 May 11:42, Tom Evans wrote:
> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
> > of the http libraries built in to python:
>
> You can find here some directions on forming the request validly,
> http://www.w3.org/Protocols/Specs.html
>
> as you apparently don't want to use any of the libraries below.
>
> On 07 May 16:00, steve malise wrote:
> > urllib2:
> > https://docs.python.org/2/howto/urllib2.html#data
> >
> > httplib:
> > https://docs.python.org/2/library/httplib.html#examples
> >
> > or use a 3rd party library that wraps those in a more pleasing interface:
> >
> > requests:
> > http://docs.python-requests.org/en/latest/
>
> Using one of the above-listed libraries would still accomplish what you
> are trying to do, as you described here,
>
> On 07 May 16:00, steve malise wrote:
> > What i am trying to do is run python script(client side) on another
> > computer which is on same network with my computer,then receive data from
> > another computer with the django(which is running on my computer(server
> > side)).i am using built-in "runserver".
>
> so I suspect that you are doing something more that we missed. Perhaps
> you could tell us why you want to do 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/20150507141332.GA27942%40d1stkfactory
> .
> 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/CACwh%3D0zjAYKjmyTJTWcucTyLM_iVaLokcgqREZpXgzp7e_GEGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to fix the UnboundLocalError

2015-05-11 Thread François Schiettecatte
You have an ident issue of some sort. pre_ques is out of scope if the 
request.method is not POST.

François

> On May 11, 2015, at 7:24 AM, 田福顿  wrote:
> 
> This is my code, 
> 
> def test_words(request):
> if request.method == "POST":
> i_d = request.user.id
> pre_word = []
> pre_mean = []
> pre_ques = 
> {"word":"","option1":"","option2":"","option3":"","option4":""}
> key_list = ["option1","option2","option3","option4"]
> pre_set =WordBase.objects.order_by('?')[:4]
> for pre_ser_odd in pre_set:
> pre_word.append(pre_ser_odd.word)
> pre_mean.append(pre_ser_odd.mean)
> pre_ques["word"] = random.choice(pre_word)
> while option_key:
> option_key = random.choice(key_list)
> option_value = random.choice(pre_mean)
> pre_ques[option_key] = option_value
> key_list.remove(option_key)
> pre_mean.remove(option_value)
> context = RequestContext(request)
> return 
> render_to_response('tag_study/test_words.html',{"pre_ques":pre_ques}, context)
> 
> I have no idea about the error, the tracebank is 
> UnboundLocalError at /tag_study/test_words/
> 
> local variable 'pre_ques' referenced before assignment
> 
> 
> -- 
> 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/0f7e7890-322f-4b7f-ad45-b485ed1833ae%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...@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/7270DFB9-6473-455B-942B-2A9A189EF97C%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to fix the UnboundLocalError

2015-05-11 Thread 田福顿
*This is my code, *

def test_words(request):
if request.method == "POST":
i_d = request.user.id
pre_word = []
pre_mean = []
pre_ques = 
{"word":"","option1":"","option2":"","option3":"","option4":""}
key_list = ["option1","option2","option3","option4"]
pre_set =WordBase.objects.order_by('?')[:4]
for pre_ser_odd in pre_set:
pre_word.append(pre_ser_odd.word)
pre_mean.append(pre_ser_odd.mean)
pre_ques["word"] = random.choice(pre_word)
while option_key:
option_key = random.choice(key_list)
option_value = random.choice(pre_mean)
pre_ques[option_key] = option_value
key_list.remove(option_key)
pre_mean.remove(option_value)
context = RequestContext(request)
return 
render_to_response('tag_study/test_words.html',{"pre_ques":pre_ques}, 
context)

*I have no idea about the error, the tracebank is *
*UnboundLocalError at /tag_study/test_words/*

*local variable 'pre_ques' referenced before assignment*


-- 
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/0f7e7890-322f-4b7f-ad45-b485ed1833ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


rollback the update query

2015-05-11 Thread Simran Singh
I am really new to Django and I am using Django 1.8. Many of the 
manual_transaction features have been depreciated in this. I have used 
*@transaction.atomic(None, 
True)* to pack the transaction and rollback the updates if at any point the 
condition is not met. 
I tried to store the transaction in savepoint and used  *savepoint_rollback* 
or *savepoint_commit* as per the condition. But I am having no luck here. 
No matter where the control goes but as soon as atomic block ends, it is 
committing the changes in mysql db.  
Any kind of help or leads would be highly appreciated.

-- 
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/7067ae6c-adaf-4b6b-beb5-91e898901e9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django 1.7 - data migration which needs content types populated

2015-05-11 Thread Santiago L
Hi,

I'm migrating an app from Django 1.6 to 1.7 and I need to create a data 
migration to load some initial data.

Some of the migrations requires that Content Types are populated in order 
to create some objects with Generic Relations.
# models.py

class TincHost(models.Model):
name = models.CharField(max_length=32, unique=True)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()


class Server(models.Model):
name = models.CharField(max_length=256, unique=True)
tinc = generic.GenericRelation(TincHost)


# migrations/0002_initial_data.py

def create_tinc_server(apps, schema_editor):
# ...
TincHost.objects.create(content_type=ctype, object_id=1, name='server')


class Migration(migrations.Migration):
dependencies = [ 
('contenttypes', '0001_initial'),
('myapp', '0001_initial'),
]   

operations = [ 
migrations.RunPython(create_tinc_server)
] 


This page[1] suggests adding this code to the migration:

from django.contrib.contenttypes.management import update_all_contenttypes
update_all_contenttypes()


It works, but there is a better or standar way to achieve that?

[1] http://stackoverflow.com/q/26464838/1538221

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/5b2d48da-41b3-404d-abff-6c17c017aa10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django inline formset(UI) delete/remove

2015-05-11 Thread Ajay Kumar
I'm trying to do a inline formset with UI not with dajngo built in 
inlineformset_factory form.Here i'm done with add_view and edit_view.Here 
in the edit view i can update the existing record for the both parent and 
child model,and can add new record to the child model.But i cant remove the 
existing record from the child model in inline formset.Every thing is fine 
working at client side.When i click remove button from the UI, the record 
is removed by javascript,But in server side, in the edit_view the #Delete 
Existing record block cloud take the delete/remove functionality.I tried in 
many possible ways but i can't make the delete query for the removed items 
form the client side.

*models.py*

from django.db import models
class Category(models.Model):
name=   models.CharField(max_length=128)

def __unicode__(self):
return self.name
class Product(models.Model):
category=   models.ForeignKey(Category)
name=   models.CharField(max_length=128)
price   =   models.CharField(max_length=128)



views.py

def add(request):
context =  RequestContext(request)
if request.method == 'POST':
category = Category.objects.create(name = request.POST['category'])
try:
for n in range(1,7):
product = Product.objects.create(category= 
category,name=request.POST['name_'+str(n)],price=request.POST['price_'+str(n)])
except KeyError:
pass
return HttpResponseRedirect('/')
return render_to_response('add.html',context)
def edit(request,pk):
category = get_object_or_404(Category,id=pk)
product = Product.objects.filter(category=category)
product_count = product.count()
context =  RequestContext(request)
if request.method == 'POST':
for c in Category.objects.filter(id = category.id):
c.name = request.POST['category']
c.save()
try:
#Update Existing record(child)
for p,n in zip(Product.objects.filter(category = c),range(1,7)):
p.name = request.POST['name_'+str(n)]
p.price = request.POST['price_'+str(n)]
p.save()
except KeyError:
#Delete Existing record(child)
try:
for d in range(1,7):
for i in 
Product.objects.all().filter(name=request.POST.get('name_'+str(d)),price=request.POST.get('price_'+str(d))):
print i.name

except KeyError:
pass
else:
#Add new record(child)
try:
for r in range(1,7):
product,created = 
Product.objects.update_or_create(category= 
category,name=request.POST['name_'+str(r)],price=request.POST['price_'+str(r)])
except KeyError:
pass
return HttpResponseRedirect('/')
args = {'category':category,'product':product,'product_count':product_count}
return render_to_response('edit.html',args,context)




add.html

Add
var i = 1;
function addProduct(){
if (i <= 5){
i++;
var div = document.createElement('div');
div.innerHTML = 'Name:Price:';
document.getElementById('products').appendChild(div);
}}

function removeProduct(div) {   
document.getElementById('products').removeChild( div.parentNode );
i--;}
{% csrf_token %}
Category



Product

(limit 6)
Name:Price:









edit.html

Edit
var i = {{product_count}};

function addProduct(){
if (i <= 5){
i++;
var div = document.createElement('div');
div.innerHTML = 'Name:Price:';
document.getElementById('products').appendChild(div);
}}

function removeProduct(div) {   
document.getElementById('products').removeChild( div.parentNode );
i--;}
{% csrf_token %}
Category



Product



(limit 6)
{% for list in product %}

Name:Price:

{% endfor %}









-- 
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 

Re: Admin site in Django 1.8 tutorial giving CSRF errors

2015-05-11 Thread aRkadeFR

Can you provide us more information?
Your url / views + admin.py and the settings
at least?

Thanks

On 05/07/2015 05:36 PM, David Riddle wrote:

No I have not made any changes to the admin templates. I simply
followed the instructions in the tutorial. I am using Django's
runserver per the tutorial instructions. I am totally stumped.

David

On Thu, May 7, 2015 at 3:04 AM, aRkadeFR  wrote:

Hey,

You shouldn't see these errors since the templates with the form
and so the CSRF token are generated from the contrib app admin.

Could you provide us more details of the error? Did you override
the admin templates?

Thanks,

aRkadeFR


On 05/06/2015 10:03 PM, David Riddle wrote:

Hi,

I am working through the Django 1.8 tutorial. I finished part one and
am starting on part 2. I created an admin user but when I login to the
/admin page I receive a 403 Error because CSRF verification failed.

https://docs.djangoproject.com/en/1.8/intro/tutorial02/

Any idea what the problem is?

Thanks,

David R.


--
aRkadeFR

--
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/554B1CA7.2090800%40arkade.info.
For more options, visit https://groups.google.com/d/optout.





--
aRkadeFR

--
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/555061BD.1090700%40arkade.info.
For more options, visit https://groups.google.com/d/optout.