saving data using cleaned data method

2015-04-15 Thread Arumuga Odhuvar Sekkizhar
Good Morning,
I am trying to save data in the table using cleaned data by get and post
method in the view.
How will I trace step by step the movement of data which is  to be saved in
the database?

My problem is there is know error while running the program. But i did not
see any data saved in the table in postgres. Where is the data? where can i
find the data? [ i Used IPDP() ]

*View*

def post(self,request,**kwargs):
if request.method == 'POST':


form=dms_school_gis_info_form(request.POST)

if form.is_valid():
form.process()

cd = dms_school_gis_info(
tempid_id = form.cleaned_data['tempid'],
latitude=form.cleaned_data['latitude'],
longitude=form.cleaned_data['longitude'],
)
cd.save()

*Form*

class dms_school_gis_info_form(forms.Form):
tempid = forms.CharField()
latitude=forms.CharField()
longitude=forms.CharField()

def process(self):
cd = self.cleaned_data



Please help me

Sekkizhar

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


Django Userena 'OrderedDict' object has no attribute 'keyOrder'

2015-04-15 Thread willyhakim
Hi everyone,
I am using django-userena and extend the form class to add some of my own 
fields. I followed
the demo and still get the above error. Anyone know what I am doing wrong?

class SignupFormExtra(SignupForm):
""" 
A form to demonstrate how to add extra fields to the signup form, in 
this
case adding the first and last name.

"""
first_name = forms.CharField(label=_(u'First name'),
 max_length=30,
 required=True)

last_name = forms.CharField(label=_(u'Last name'),
max_length=30,
required=False)
industry = forms.CharField(label=_(u'Industry'),
max_length=50,
required=False)
title = forms.CharField(label=_(u'title'),
max_length=50,
required=False)

def __init__(self, *args, **kw):
"""

A bit of hackery to get the first name and last name at the top of 
the
form instead at the end.

"""
super(SignupFormExtra, self).__init__(*args, **kw)
# Put the first and last name at the top
new_order = self.fields.keyOrder[-2]
new_order.insert(0, 'first_name')
new_order.insert(1, 'last_name')
new_order.insert(2, 'industry')
new_order.insert(3, 'title')
self.fields.keyOrder = new_order

def save(self):
""" 
Override the save method to save the first and last name to the user
field.
"""
# First save the parent form and get the user.
new_user = super(SignupFormExtra, self).save()

new_user.first_name = self.cleaned_data['first_name']
new_user.last_name = self.cleaned_data['last_name']
new_user.industry = self.cleaned_data['industry']
new_user.title = self.cleaned_data['title']
new_user.save()

# Userena expects to get the new user from this form, so return the 
new
# user.
return new_user

-- 
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/dbb1f624-29a4-4f57-b03e-25e46dac968e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Henry Versemann
ok.

On Wednesday, April 15, 2015 at 3:39:26 PM UTC-5, Vijay Khemlani wrote:
>
> tblEntryObj seems to be an instance of your model, it is not a dictionary, 
> so normally it wouldn't have a "keys" method.
>
> On Wed, Apr 15, 2015 at 5:32 PM, Henry Versemann  > wrote:
>
>> Vijay,
>>
>> I tried your method, and while it got me the table class that I wanted, 
>> for some reason when I try to get into the actual list of entries in the 
>> desired table, I can't seem to get to either the keys or values of any of 
>> the list objects.
>> So I'm not sure what's going on.
>> Here's some condensed code of what I've done so far:
>>
>> for entry in tblsLst:
>> entryKeys = entry.keys()
>> table_name = str(entryKeys[0])
>> table_class = get_model('canvas_app',table_name)
>> tblEntryLst = table_class.objects.all()
>> lstLgth = len(tblEntryLst)
>> for loopindx in range(lstLgth):
>> tblEntryObj = tblEntryLst[loopindx]
>> tblEntryObjKeys = tblEntryObj.keys()
>>
>> And I seem to be getting an AttributeError exception on the last line 
>> above.
>> When I print the size or contents (table objects format (the objects are 
>> listed like this:
>>
>> 
>>
>> ) no internal value to see) of the tblEntryLst everything looks right.
>> Is there anything you can suggest for determining where the problem might 
>> be?
>>
>> Thanks for the help.
>>
>> Henry
>>
>>
>> On Wednesday, April 15, 2015 at 12:43:28 PM UTC-5, Vijay Khemlani wrote:
>>
>>> You can use get_model
>>>
>>> from django.db.models.loading import get_model
>>>
>>> YourModel = get_model('your_app', tableName)
>>>
>>> On Wed, Apr 15, 2015 at 2:01 PM, Tim Chase  
>>> wrote:
>>>
 On 2015-04-15 09:45, Henry Versemann wrote:
 > My problem is since the logic won't know which tables will be in
 > the incoming list I need to try to reference the entries in each
 > table using some kind of evaluated version of a variable containing
 > the name of each table, as I iterate through the list.
 >
 > I'm sure I could do this using an "eval" statement like this
 >
 > tblComannd = "tblEntryLst = " + str(tableName) + ".objects.all()"
 >
 > eval(tblComannd)

 Since it's just Python, you can create mappings of the table-objects,
 and then get attributes on them.

   table_names = {
 "tblA": tblA,
 "tblB": tblB,
 "tblRenamed": tblXYZ,
 }

   for name, cls in table_names.items():
 log.info("Dumping %s", name)
 for item in cls.objects.all():
   write_to_file(item)

 Presumably, these classes come from some namespace like a module, so
 you can even do something like

   import models
   table_names = ["tblA", "tblB"]
   for name in table_names:
 log.info("Dumping %s", name)
 cls = getattr(models, name)
 for item in cls.objects.all():
   write_to_file(item)

 -tim



 --
 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...@googlegroups.com.
 To post to this group, send email to django...@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/20150415120110.77c4ea6f%40bigbox.christie.dr.
 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...@googlegroups.com .
>> To post to this group, send email to django...@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/3d659059-6219-4266-93f9-4e56dc348e49%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/0b22355b-91b4-4f10-92df-83cbaa83a64a%40googlegroups.com.
For more options, visit https://groups.google.com/

Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Vijay Khemlani
tblEntryObj seems to be an instance of your model, it is not a dictionary,
so normally it wouldn't have a "keys" method.

On Wed, Apr 15, 2015 at 5:32 PM, Henry Versemann 
wrote:

> Vijay,
>
> I tried your method, and while it got me the table class that I wanted,
> for some reason when I try to get into the actual list of entries in the
> desired table, I can't seem to get to either the keys or values of any of
> the list objects.
> So I'm not sure what's going on.
> Here's some condensed code of what I've done so far:
>
> for entry in tblsLst:
> entryKeys = entry.keys()
> table_name = str(entryKeys[0])
> table_class = get_model('canvas_app',table_name)
> tblEntryLst = table_class.objects.all()
> lstLgth = len(tblEntryLst)
> for loopindx in range(lstLgth):
> tblEntryObj = tblEntryLst[loopindx]
> tblEntryObjKeys = tblEntryObj.keys()
>
> And I seem to be getting an AttributeError exception on the last line
> above.
> When I print the size or contents (table objects format (the objects are
> listed like this:
>
> 
>
> ) no internal value to see) of the tblEntryLst everything looks right.
> Is there anything you can suggest for determining where the problem might
> be?
>
> Thanks for the help.
>
> Henry
>
>
> On Wednesday, April 15, 2015 at 12:43:28 PM UTC-5, Vijay Khemlani wrote:
>
>> You can use get_model
>>
>> from django.db.models.loading import get_model
>>
>> YourModel = get_model('your_app', tableName)
>>
>> On Wed, Apr 15, 2015 at 2:01 PM, Tim Chase 
>> wrote:
>>
>>> On 2015-04-15 09:45, Henry Versemann wrote:
>>> > My problem is since the logic won't know which tables will be in
>>> > the incoming list I need to try to reference the entries in each
>>> > table using some kind of evaluated version of a variable containing
>>> > the name of each table, as I iterate through the list.
>>> >
>>> > I'm sure I could do this using an "eval" statement like this
>>> >
>>> > tblComannd = "tblEntryLst = " + str(tableName) + ".objects.all()"
>>> >
>>> > eval(tblComannd)
>>>
>>> Since it's just Python, you can create mappings of the table-objects,
>>> and then get attributes on them.
>>>
>>>   table_names = {
>>> "tblA": tblA,
>>> "tblB": tblB,
>>> "tblRenamed": tblXYZ,
>>> }
>>>
>>>   for name, cls in table_names.items():
>>> log.info("Dumping %s", name)
>>> for item in cls.objects.all():
>>>   write_to_file(item)
>>>
>>> Presumably, these classes come from some namespace like a module, so
>>> you can even do something like
>>>
>>>   import models
>>>   table_names = ["tblA", "tblB"]
>>>   for name in table_names:
>>> log.info("Dumping %s", name)
>>> cls = getattr(models, name)
>>> for item in cls.objects.all():
>>>   write_to_file(item)
>>>
>>> -tim
>>>
>>>
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@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/20150415120110.77c4ea6f%40bigbox.christie.dr.
>>> 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/3d659059-6219-4266-93f9-4e56dc348e49%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/CALn3ei1mbXGN3PNWpnqg0Cjg-rvOP738U5dqDEAY_0%2B%3DAy-Zpw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Henry Versemann
Vijay,

I tried your method, and while it got me the table class that I wanted, for 
some reason when I try to get into the actual list of entries in the 
desired table, I can't seem to get to either the keys or values of any of 
the list objects.
So I'm not sure what's going on.
Here's some condensed code of what I've done so far:

for entry in tblsLst:
entryKeys = entry.keys()
table_name = str(entryKeys[0])
table_class = get_model('canvas_app',table_name)
tblEntryLst = table_class.objects.all()
lstLgth = len(tblEntryLst)
for loopindx in range(lstLgth):
tblEntryObj = tblEntryLst[loopindx]
tblEntryObjKeys = tblEntryObj.keys()

And I seem to be getting an AttributeError exception on the last line above.
When I print the size or contents (table objects format (the objects are 
listed like this:



) no internal value to see) of the tblEntryLst everything looks right.
Is there anything you can suggest for determining where the problem might 
be?

Thanks for the help.

Henry


On Wednesday, April 15, 2015 at 12:43:28 PM UTC-5, Vijay Khemlani wrote:

> You can use get_model
>
> from django.db.models.loading import get_model
>
> YourModel = get_model('your_app', tableName)
>
> On Wed, Apr 15, 2015 at 2:01 PM, Tim Chase  > wrote:
>
>> On 2015-04-15 09:45, Henry Versemann wrote:
>> > My problem is since the logic won't know which tables will be in
>> > the incoming list I need to try to reference the entries in each
>> > table using some kind of evaluated version of a variable containing
>> > the name of each table, as I iterate through the list.
>> >
>> > I'm sure I could do this using an "eval" statement like this
>> >
>> > tblComannd = "tblEntryLst = " + str(tableName) + ".objects.all()"
>> >
>> > eval(tblComannd)
>>
>> Since it's just Python, you can create mappings of the table-objects,
>> and then get attributes on them.
>>
>>   table_names = {
>> "tblA": tblA,
>> "tblB": tblB,
>> "tblRenamed": tblXYZ,
>> }
>>
>>   for name, cls in table_names.items():
>> log.info("Dumping %s", name)
>> for item in cls.objects.all():
>>   write_to_file(item)
>>
>> Presumably, these classes come from some namespace like a module, so
>> you can even do something like
>>
>>   import models
>>   table_names = ["tblA", "tblB"]
>>   for name in table_names:
>> log.info("Dumping %s", name)
>> cls = getattr(models, name)
>> for item in cls.objects.all():
>>   write_to_file(item)
>>
>> -tim
>>
>>
>>
>> --
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/20150415120110.77c4ea6f%40bigbox.christie.dr
>> .
>> 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/3d659059-6219-4266-93f9-4e56dc348e49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Henry Versemann
Thanks for the help Stephen.

On Wednesday, April 15, 2015 at 11:53:09 AM UTC-5, Stephen Butler wrote:
>
> Or, if you know all the Model classes are in the same module that 
> you've imported, it should be as easy as: 
>
> from myapp import models 
>
> model_class = getattr(models, tableName) 
>
> On Wed, Apr 15, 2015 at 11:50 AM, Stephen J. Butler 
> > wrote: 
> > Classes (MyModel) are attributes of the module (myapp.models). No 
> > reason to use eval. You can get the module from importlib and then the 
> > class from using getattr() on the module. 
> > 
> > 
> http://stackoverflow.com/questions/10773348/get-python-class-object-from-string
>  
> > 
> > 
> > 
> > On Wed, Apr 15, 2015 at 11:45 AM, Henry Versemann  > wrote: 
> >> I have an incoming list of DB table names associated with my 
> application. I 
> >> want to iterate through this list of table names getting all of the 
> entries 
> >> for each table and then print some data from each tables' entry to a 
> file. 
> >> I've tried to write this so I can use it for as many app-associated 
> tables 
> >> as possible. 
> >> 
> >> My problem is since the logic won't know which tables will be in the 
> >> incoming list I need to try to reference the entries in each table 
> using 
> >> some kind of evaluated version of a variable containing the name of 
> each 
> >> table, as I iterate through the list. 
> >> 
> >> I'm sure I could do this using an "eval" statement like this 
> >> 
> >> tblComannd = "tblEntryLst = " + str(tableName) + ".objects.all()" 
> >> 
> >> eval(tblComannd) 
> >> 
> >> but I also know that the "eval" statement is not the safest thing to 
> use. 
> >> 
> >> So far I've tried to reference the table name in the following ways: 
> >> 
> >> tblEntryLst = str(tableName).objects.all() 
> >> tblEntryLst = tableName.objects.all() 
> >> 
> >> with no success at all and only an AttributeError exception being the 
> >> result. 
> >> 
> >> I think its possible since I've successfully done some similar things 
> with 
> >> referencing and saving the values of unknown keys for dictionaries 
> similar 
> >> to this: 
> >> 
> >> new_dictionary[str(extracted_key)] = old_dictionary[str(extracted_key)] 
> >> 
> >> but don't know this for sure. 
> >> 
> >> Can someone please confirm if this is indeed possible to do or not, and 
> if 
> >> so give a general format or example for how to do it? 
> >> 
> >> Any help would be much appreciated. 
> >> 
> >> Thanks. 
> >> 
> >> Henry 
> >> 
> >> 
> >> -- 
> >> 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...@googlegroups.com . 
> >> To post to this group, send email to django...@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/e3430efb-7fc2-4baf-931b-6ec8d8580315%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/83866de5-07b8-4b1a-85ef-3b1993539494%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Static folder generation on runserver

2015-04-15 Thread Camilo Nova
 

Hi all, does anyone knows why ./manage.py runserver copy the static folder 
like if I run ./manage.py collectstatic ?

It began to happen since django 1.7

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/1a53d46b-1f16-42d2-9eb3-9fa298f3bc40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Vijay Khemlani
You can use get_model

from django.db.models.loading import get_model

YourModel = get_model('your_app', tableName)

On Wed, Apr 15, 2015 at 2:01 PM, Tim Chase 
wrote:

> On 2015-04-15 09:45, Henry Versemann wrote:
> > My problem is since the logic won't know which tables will be in
> > the incoming list I need to try to reference the entries in each
> > table using some kind of evaluated version of a variable containing
> > the name of each table, as I iterate through the list.
> >
> > I'm sure I could do this using an "eval" statement like this
> >
> > tblComannd = "tblEntryLst = " + str(tableName) + ".objects.all()"
> >
> > eval(tblComannd)
>
> Since it's just Python, you can create mappings of the table-objects,
> and then get attributes on them.
>
>   table_names = {
> "tblA": tblA,
> "tblB": tblB,
> "tblRenamed": tblXYZ,
> }
>
>   for name, cls in table_names.items():
> log.info("Dumping %s", name)
> for item in cls.objects.all():
>   write_to_file(item)
>
> Presumably, these classes come from some namespace like a module, so
> you can even do something like
>
>   import models
>   table_names = ["tblA", "tblB"]
>   for name in table_names:
> log.info("Dumping %s", name)
> cls = getattr(models, name)
> for item in cls.objects.all():
>   write_to_file(item)
>
> -tim
>
>
>
> --
> 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/20150415120110.77c4ea6f%40bigbox.christie.dr
> .
> 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/CALn3ei33E%2BkH63sCXWx_Y7xPSa91Kv_JB4kYHZt_djvF46LUyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Tim Chase
On 2015-04-15 09:45, Henry Versemann wrote:
> My problem is since the logic won't know which tables will be in
> the incoming list I need to try to reference the entries in each
> table using some kind of evaluated version of a variable containing
> the name of each table, as I iterate through the list.
> 
> I'm sure I could do this using an "eval" statement like this
> 
> tblComannd = "tblEntryLst = " + str(tableName) + ".objects.all()"
> 
> eval(tblComannd)

Since it's just Python, you can create mappings of the table-objects,
and then get attributes on them.

  table_names = {
"tblA": tblA,
"tblB": tblB,
"tblRenamed": tblXYZ,
}

  for name, cls in table_names.items():
log.info("Dumping %s", name)
for item in cls.objects.all():
  write_to_file(item)

Presumably, these classes come from some namespace like a module, so
you can even do something like

  import models
  table_names = ["tblA", "tblB"]
  for name in table_names:
log.info("Dumping %s", name)
cls = getattr(models, name)
for item in cls.objects.all():
  write_to_file(item)

-tim



-- 
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/20150415120110.77c4ea6f%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Stephen J. Butler
Or, if you know all the Model classes are in the same module that
you've imported, it should be as easy as:

from myapp import models

model_class = getattr(models, tableName)

On Wed, Apr 15, 2015 at 11:50 AM, Stephen J. Butler
 wrote:
> Classes (MyModel) are attributes of the module (myapp.models). No
> reason to use eval. You can get the module from importlib and then the
> class from using getattr() on the module.
>
> http://stackoverflow.com/questions/10773348/get-python-class-object-from-string
>
>
>
> On Wed, Apr 15, 2015 at 11:45 AM, Henry Versemann  
> wrote:
>> I have an incoming list of DB table names associated with my application. I
>> want to iterate through this list of table names getting all of the entries
>> for each table and then print some data from each tables' entry to a file.
>> I've tried to write this so I can use it for as many app-associated tables
>> as possible.
>>
>> My problem is since the logic won't know which tables will be in the
>> incoming list I need to try to reference the entries in each table using
>> some kind of evaluated version of a variable containing the name of each
>> table, as I iterate through the list.
>>
>> I'm sure I could do this using an "eval" statement like this
>>
>> tblComannd = "tblEntryLst = " + str(tableName) + ".objects.all()"
>>
>> eval(tblComannd)
>>
>> but I also know that the "eval" statement is not the safest thing to use.
>>
>> So far I've tried to reference the table name in the following ways:
>>
>> tblEntryLst = str(tableName).objects.all()
>> tblEntryLst = tableName.objects.all()
>>
>> with no success at all and only an AttributeError exception being the
>> result.
>>
>> I think its possible since I've successfully done some similar things with
>> referencing and saving the values of unknown keys for dictionaries similar
>> to this:
>>
>> new_dictionary[str(extracted_key)] = old_dictionary[str(extracted_key)]
>>
>> but don't know this for sure.
>>
>> Can someone please confirm if this is indeed possible to do or not, and if
>> so give a general format or example for how to do it?
>>
>> Any help would be much appreciated.
>>
>> Thanks.
>>
>> Henry
>>
>>
>> --
>> 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/e3430efb-7fc2-4baf-931b-6ec8d8580315%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/CAD4ANxUqGKChACN9ecPMVoUKEfWz7yO_GUHc%3DqTQQVJ2-JMM_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Stephen J. Butler
Classes (MyModel) are attributes of the module (myapp.models). No
reason to use eval. You can get the module from importlib and then the
class from using getattr() on the module.

http://stackoverflow.com/questions/10773348/get-python-class-object-from-string



On Wed, Apr 15, 2015 at 11:45 AM, Henry Versemann  wrote:
> I have an incoming list of DB table names associated with my application. I
> want to iterate through this list of table names getting all of the entries
> for each table and then print some data from each tables' entry to a file.
> I've tried to write this so I can use it for as many app-associated tables
> as possible.
>
> My problem is since the logic won't know which tables will be in the
> incoming list I need to try to reference the entries in each table using
> some kind of evaluated version of a variable containing the name of each
> table, as I iterate through the list.
>
> I'm sure I could do this using an "eval" statement like this
>
> tblComannd = "tblEntryLst = " + str(tableName) + ".objects.all()"
>
> eval(tblComannd)
>
> but I also know that the "eval" statement is not the safest thing to use.
>
> So far I've tried to reference the table name in the following ways:
>
> tblEntryLst = str(tableName).objects.all()
> tblEntryLst = tableName.objects.all()
>
> with no success at all and only an AttributeError exception being the
> result.
>
> I think its possible since I've successfully done some similar things with
> referencing and saving the values of unknown keys for dictionaries similar
> to this:
>
> new_dictionary[str(extracted_key)] = old_dictionary[str(extracted_key)]
>
> but don't know this for sure.
>
> Can someone please confirm if this is indeed possible to do or not, and if
> so give a general format or example for how to do it?
>
> Any help would be much appreciated.
>
> Thanks.
>
> Henry
>
>
> --
> 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/e3430efb-7fc2-4baf-931b-6ec8d8580315%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/CAD4ANxUUpEdBcyDv8vJFWsJGdCMuXkmXs9SBf_STz5%3D9-Jw78w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


.get() has unexpected behaviour on a queryset after previously applying .order_by().distinct()

2015-04-15 Thread Nick Smith
>>> from django.db.models import models
>>> class MarketPrice(models.Model):
market = models.CharField(max_length=30)
crop = models.CharField(max_length=30)
price = models.PositiveSmallIntegerField()
date = models.DateField()

def __str__(self):
return "{}, {}, {}, {}".format(
self.market,
self.crop,
self,price,
self.date
)

>>> FIXTURES = [
('London', 'carrots', 15, datetime.date(2015, 1, 1)),
('London', 'carrots', 20, datetime.date(2015, 1, 2)),

('London', 'potatoes', 12, datetime.date(2015, 1, 1)),
('London', 'potatoes', 14, datetime.date(2015, 1, 2)),

('Manchester', 'carrots', 18, datetime.date(2015, 1, 1)),
('Manchester', 'carrots', 21, datetime.date(2015, 1, 2)),

('Manchester', 'potatoes', 10, datetime.date(2015, 1, 1)),
('Manchester', 'potatoes', 12, datetime.date(2015, 1, 2)),
]

>>> for market, crop, price, date in FIXTURES:
MarketPrice.objects.create(market=market,
   crop=crop,
   price=price,
   date=date)

We want to get only the latest prices for every possible combination of 
markets and crops...

>>> prices = (MarketPrice.objects
  .order_by('market', 'commodity', '-date')
  .distinct('market', 'commodity'))
[, , , ]

.filter() works as expected

>>> prices.filter(market='Manchester', crop='carrots')
[]

but .get is totally unexpected

>>> prices.get(market='Manchester', crop='carrots')


not only does it return the 'wrong' entry, but one which didn't even seem 
to be in prices (because it's a distinct queryset)

It looks and feels even weirder if you apply the filtering first:

>>> prices = (MarketPrice.objects
  .filter(market='Manchester', crop='carrots')
  .order_by('market', 'commodity', '-date')
  .distinct('market', 'commodity'))
>>> prices
[]

>>> prices.get(market='Manchester', crop='carrots')


There's a note seemingly related to this at 
https://docs.djangoproject.com/en/1.7/ref/models/querysets/#django.db.models.query.QuerySet.distinct,
 
but I'm not clear how it directly describes what I'm seeing here.

The line which seems to be causing this is from 
https://github.com/django/django/commit/e4757ec7afd54861e0c34d9b0f5edbbac4e2b860,
 
which strips the ordering I've previously applied

>>> prices
[]

>>> prices.order_by()
[]

Is this intended behaviour?

PS the above code examples are untested, manually-typed pseudocode for the 
sake of keeping the example simple.

-- 
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/50f5ba71-bb20-42f4-96bd-3f1ce17338bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Trying to avoid using the "eval" command/statement

2015-04-15 Thread Henry Versemann
I have an incoming list of DB table names associated with my application. I 
want to iterate through this list of table names getting all of the 
entries for each table and then print some data from each tables' entry to 
a file. I've tried to write this so I can use it for as many 
app-associated tables as possible.

My problem is since the logic won't know which tables will be in the 
incoming list I need to try to reference the entries in each table 
using some kind of evaluated version of a variable containing the name of 
each table, as I iterate through the list.

I'm sure I could do this using an "eval" statement like this

tblComannd = "tblEntryLst = " + str(tableName) + ".objects.all()"

eval(tblComannd)

but I also know that the "eval" statement is not the safest thing to use.

So far I've tried to reference the table name in the following ways:

tblEntryLst = str(tableName).objects.all()
tblEntryLst = tableName.objects.all()

with no success at all and only an AttributeError exception being the 
result.

I think its possible since I've successfully done some similar things with 
referencing and saving the values of unknown keys for dictionaries similar 
to this:

new_dictionary[str(extracted_key)] = old_dictionary[str(extracted_key)]

but don't know this for sure.

Can someone please confirm if this is indeed possible to do or not, and if 
so give a general format or example for how to do it?

Any help would be much appreciated.

Thanks.

Henry
 

-- 
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/e3430efb-7fc2-4baf-931b-6ec8d8580315%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Possible bug with django site frameworks swapping between 2 sites every request

2015-04-15 Thread Stephen J. Butler
https://docs.djangoproject.com/en/1.8/topics/cache/#dummy-caching-for-development

On Wed, Apr 15, 2015 at 8:47 AM, Joe  wrote:

> How do you set it to the dummy cache?
>
> On Saturday, April 11, 2015 at 2:06:10 PM UTC-7, Stephen Butler wrote:
>>
>> What happens if you disable all caching (try setting it to the dummy
>> cache).
>>
>> Also, you really shouldn't put your python code in your server's
>> DocumentRoot. There's absolutely no reason to do it that way. You're just
>> asking to have your settings.py file exposed by a misconfigured apache
>> instance.
>>
>> On Sat, Apr 11, 2015 at 10:02 AM, Joe  wrote:
>>
>>>
>>> I am using django's sites framework with dajngo 1.7. I am calling the
>>> site name through a context processor like below. The problem is that every
>>> time the page loads, it switches between site1 and site2:
>>>
>>> def site_info(request):
>>>
>>> Site.objects.clear_cache()# i tried with and without this
>>> site = get_current_site(request)
>>> site_detail = SiteDetail.objects.get(site_id=site.id)
>>>
>>>
>>> return {
>>> 'site_domain': site.domain,
>>> 'site_name': site.name,
>>> 'site_short_name': site_detail.short_name,
>>> }
>>>
>>> In my template I simply refer to the site name to do some logic and it
>>> switches back and forth between 2 of my sites on every request:
>>>
>>> {% if site_name = 'Site 1' %}
>>> 
>>> {% elif site_name = 'Site 2' %}
>>> 
>>> {% endif %}
>>>
>>> My httpd.conf looks like this:
>>>
>>> 
>>> ServerName mysite1.com
>>> DocumentRoot /var/www/html/mysitedjango
>>> WSGIScriptAlias / 
>>> /var/www/html/mysitedjango/mysite1/mysite1_wsgi.py
>>> 
>>> ServerName mysite2.com
>>> DocumentRoot /var/www/html/mysitedjango
>>> WSGIScriptAlias / 
>>> /var/www/html/mysitedjango/mysite1/mysite2_wsgi.py
>>>
>>>
>>> Alias /static/ /var/www/html/mysitedjango/shared/static/
>>> Order deny,allowAllow 
>>> from all
>>> WSGIPythonPath /var/www/html/mysitedjango
>>> Order deny,allowAllow 
>>> from all
>>>
>>> Is this a bug? How can I stop swapping and make each site completely
>>> sandboxed?
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@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/70ef019a-09a0-408c-9118-12f94fb2d157%
>>> 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/f9669c4c-de17-4b56-a6be-3db7a485e81d%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/CAD4ANxXqO0C%2B6yc0m1xQynS%3D7mJcHY9fAEHU725ERvb%3D8vMc_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Possible bug with django site frameworks swapping between 2 sites every request

2015-04-15 Thread Joe
How do you set it to the dummy cache?

On Saturday, April 11, 2015 at 2:06:10 PM UTC-7, Stephen Butler wrote:
>
> What happens if you disable all caching (try setting it to the dummy 
> cache).
>
> Also, you really shouldn't put your python code in your server's 
> DocumentRoot. There's absolutely no reason to do it that way. You're just 
> asking to have your settings.py file exposed by a misconfigured apache 
> instance.
>
> On Sat, Apr 11, 2015 at 10:02 AM, Joe > 
> wrote:
>
>>
>> I am using django's sites framework with dajngo 1.7. I am calling the 
>> site name through a context processor like below. The problem is that every 
>> time the page loads, it switches between site1 and site2:
>>
>> def site_info(request):
>>
>> Site.objects.clear_cache()# i tried with and without this
>> site = get_current_site(request)
>> site_detail = SiteDetail.objects.get(site_id=site.id)
>>
>>
>> return {
>> 'site_domain': site.domain,
>> 'site_name': site.name,
>> 'site_short_name': site_detail.short_name,
>> }
>>
>> In my template I simply refer to the site name to do some logic and it 
>> switches back and forth between 2 of my sites on every request:
>>
>> {% if site_name = 'Site 1' %}
>> 
>> {% elif site_name = 'Site 2' %}
>> 
>> {% endif %}
>>
>> My httpd.conf looks like this:
>>
>> 
>> ServerName mysite1.com
>> DocumentRoot /var/www/html/mysitedjango
>> WSGIScriptAlias / 
>> /var/www/html/mysitedjango/mysite1/mysite1_wsgi.py
>> 
>> ServerName mysite2.com
>> DocumentRoot /var/www/html/mysitedjango
>> WSGIScriptAlias / 
>> /var/www/html/mysitedjango/mysite1/mysite2_wsgi.py
>>
>>
>> Alias /static/ /var/www/html/mysitedjango/shared/static/
>> Order deny,allowAllow 
>> from all
>> WSGIPythonPath /var/www/html/mysitedjango
>> Order deny,allowAllow 
>> from all
>>
>> Is this a bug? How can I stop swapping and make each site completely 
>> sandboxed?
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/70ef019a-09a0-408c-9118-12f94fb2d157%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/f9669c4c-de17-4b56-a6be-3db7a485e81d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Admin should really support Twitter Bootsrap

2015-04-15 Thread bobhaugen
On Monday, April 13, 2015 at 5:16:40 PM UTC-5, Patrick Lemiuex wrote:
>
> It's about time, the django admin tool should support twitter bootstrap 
> markups and styling. This is the third django project where I've had to 
> deal with custom form widgets because the admin tool supports kind of an 
> outdated layout scheme in the admin template.
>
> This also affects a lot of third party apps as well. It would be something 
> worth contributing to the community by me.
>

You don't like any of these?
https://www.djangopackages.com/grids/g/admin-interface/ 

-- 
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/906251c1-d95e-4e2b-bc2b-25cfa4e3f8ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django handle new ManyToManyField items with get_or_create()

2015-04-15 Thread Pavel Kuchin
Hi Filippo,

You can check is form valid or not, then if valid save related model and 
then add M2M objects, like this:

if form.is_valid():

  model_instance = form.save()

 for tag in model_instance.tags.all():
   t, created = Tag.objects.get_or_create(author=request.user, title=tag.title)
   model_instance.tags.add(t)
 return HttpResponseRedirect("/")


Best regards, Pavel


Help me, django-users, you're my only hope :D
>
> Hi all, my name is Filippo, I'm from Italy and I'm totally stuck on this 
> problem...
>
> I have a model with a ManyToManyField and in my view I want to be able to 
> add new options to the generated selectbox.
>
> How can I handle those new items with get_or_create function?
>
> I want to check for form validity before saving it, but it will never be 
> valid because I have to create all the new ManyToMany items. In the 
> meantime, I don't want to add new items if the form is not valid... 
>
> So I'm stuck with this not-working-code:
>
> def add_entry(request):
> if request.method == 'POST':
> form = EntryForm(data=request.POST)
> model_instance = form.save(commit=False)
> for tag in model_instance.tags.all():
> t, created = Tag.objects.get_or_create(author=request.user, 
> title=tag.title)
> model_instance.tags.add(t)
> if form.is_valid():
> model_instance.save()
> return HttpResponseRedirect("/")
> else:
> form = EntryForm()
> return render_to_response(
> 'add_entry.html',
> {'form' : form },
> context_instance=RequestContext(request))
>
>

-- 
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/29fcff84-a42d-4786-a35c-14cd209e10da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: csrf_exempt decorator and class based views

2015-04-15 Thread Andreas Kuhne
First of all, why are you not using the default views that django provides?
In your case all you have to do is subclass the View class
(django.views.generic.View) to get all the functionality that you require
(i.e. you get a post and get method that will automatically be called).

Second of all, check:
https://docs.djangoproject.com/en/1.8/topics/class-based-views/intro/#decorating-the-class.
There you can see howto use a decorator on one method in the class only.

If you used the View class, your "SpecificHandler" should look something
like this:

from django.views.decorators.csrf import csrf_exempt
from django.views.generic import View
from django.utils.decorators import method_decorator

class SpecificHandler(View):
@method_decorator(csrf_exempt)
def post(self, request, *args, **kwargs):
pass


Then you shouldn't have any issues with posting. However, I really don't
see WHY you would want to do that, because in a post the CSRF token is
rather important for security

Regards,

Andréas


2015-04-15 9:21 GMT+02:00 Kishor Pawar :

> Hey Casey,
>
> I followed this doc, but still I am not getting this working.
>
> Do I need to do anything else to get it work?
>
> On Tuesday, 8 March 2011 19:11:32 UTC+5:30, Casey wrote:
>>
>> Have you seen this yet:
>>
>> http://docs.djangoproject.com/en/dev/topics/class-based-
>> views/#decorating-class-based-views
>>
>> I think it answers your question.
>>
>> Hope this helps,
>> Casey
>>
>> On 03/08/2011 08:19 AM, Christo Buschek wrote:
>> > Hello.
>> >
>> > I came across a problem that I don't fully understand. I try to
>> > implement a view where I want to turn csrf protection off. My view is
>> > implemented as a class based view, eg:
>> >
>> > class BaseHandler(object):
>> >  """Base class to provide method lookup per HTTP method."""
>> >  def __call__(self, request, **kwargs):
>> >  self.request = request
>> >  try:
>> >  callback = getattr(self, "do_%s" % request.method)
>> >  except AttributeError:
>> >   allowed_methods = [m.lstrip("do_") for m in dir(self) if
>> > m.startswith("do_")]
>> >   return HttpResponseNotAllowed(allowed_methods)
>> >  return callback(**kwargs)
>> >
>> > class SpecificHandler(BaseHandler):
>> >  """Implement the HTTP methods."""
>> >  def do_POST(self, **kwargs):
>> >  pass
>> >
>> > If I want to use the @csrf_exempt on the class method 'do_POST', it
>> > doesn't get recognised. It is only accepted if I wrap the whole class
>> > inside the decorator, eg:
>> >
>> > # This doesn't work
>> > class SpecificHandler(BaseHandler):
>> >  @csrf_exempt
>> >  def do_POST(self, **kwargs):
>> >  pass
>> >
>> > # This works
>> > @csrf_exempt
>> > class SpecificHandler(BaseHandler):
>> >  def do_POST(self, **kwargs):
>> >  pass
>> >
>> > But I wonder if that is the right way to do because than all class
>> > methods are excepted from the csrf protection.
>> >
>> > 1) Why is the decorator not wrapping the class method (more a python
>> > question I guess)?
>> > 2) Is there any other way how I could turn off the csrf protection for
>> > this single class method?
>> >
>> > Any enlightenment is very much appreciated.
>> >
>> > cheers
>> > Christo
>> >
>>
>>  --
> 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/fd2188e8-d311-4c32-b3a1-37800123fba9%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/CALXYUbn99pZfEESNFBKzUBTPXjdo7o6GXo3XvAwj2%3DFa%3DCFdbg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: csrf_exempt decorator and class based views

2015-04-15 Thread Kishor Pawar
Hey Casey,

I followed this doc, but still I am not getting this working.

Do I need to do anything else to get it work?

On Tuesday, 8 March 2011 19:11:32 UTC+5:30, Casey wrote:
>
> Have you seen this yet:
>
>
> http://docs.djangoproject.com/en/dev/topics/class-based-views/#decorating-class-based-views
>
> I think it answers your question.
>
> Hope this helps,
> Casey
>
> On 03/08/2011 08:19 AM, Christo Buschek wrote:
> > Hello.
> >
> > I came across a problem that I don't fully understand. I try to
> > implement a view where I want to turn csrf protection off. My view is
> > implemented as a class based view, eg:
> >
> > class BaseHandler(object):
> >  """Base class to provide method lookup per HTTP method."""
> >  def __call__(self, request, **kwargs):
> >  self.request = request
> >  try:
> >  callback = getattr(self, "do_%s" % request.method)
> >  except AttributeError:
> >   allowed_methods = [m.lstrip("do_") for m in dir(self) if
> > m.startswith("do_")]
> >   return HttpResponseNotAllowed(allowed_methods)
> >  return callback(**kwargs)
> >
> > class SpecificHandler(BaseHandler):
> >  """Implement the HTTP methods."""
> >  def do_POST(self, **kwargs):
> >  pass
> >
> > If I want to use the @csrf_exempt on the class method 'do_POST', it
> > doesn't get recognised. It is only accepted if I wrap the whole class
> > inside the decorator, eg:
> >
> > # This doesn't work
> > class SpecificHandler(BaseHandler):
> >  @csrf_exempt
> >  def do_POST(self, **kwargs):
> >  pass
> >
> > # This works
> > @csrf_exempt
> > class SpecificHandler(BaseHandler):
> >  def do_POST(self, **kwargs):
> >  pass
> >
> > But I wonder if that is the right way to do because than all class
> > methods are excepted from the csrf protection.
> >
> > 1) Why is the decorator not wrapping the class method (more a python
> > question I guess)?
> > 2) Is there any other way how I could turn off the csrf protection for
> > this single class method?
> >
> > Any enlightenment is very much appreciated.
> >
> > cheers
> > Christo
> >
>
>

-- 
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/fd2188e8-d311-4c32-b3a1-37800123fba9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.