List Info

Thread: newbie question regarding newForm POST information




newbie question regarding newForm POST information
country flaguser name
United States
2007-03-30 11:42:40
Is it possible to access the POST information from within my
forms.py
file after a page submission?  I am confused on how to
access this
information from within the constructor of if I can even do
this.

--------------
forms.py
--------------
from django import newforms as forms
class CustomerAdd(forms.Form):
    def __init__(self, *args, **kwargs):
        super(CustomerAdd, self).__init__( *args, **kwargs)

----------------
views.py
----------------
if request.method == 'POST':
        form = CustomerAdd(request.POST)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: newbie question regarding newForm POST information
country flaguser name
United States
2007-03-30 14:23:40
I'm a bit confused by what you're trying to do with the
actual data
itself...

I haven't used newforms a great deal yet, but anytime that
it has been
necessary to modify data coming in from request.POST I've
either done
it within the view itself or within the newforms data
validation
system.

for example, on a Registration Form:

def clean_passwordconfirm(self):
        "cofirms that both passwords match"

        if self.clean_data['password'] ==
self.clean_data['passwordconfirm']:
            return self.clean_data['password']
        else:
            raise forms.ValidationError('Password and
Confirm are not
the same.')

This accesses data from within the form itself (which I have
in
forms.py)

Is this what you were looking for or were you trying to do
something
more complicated?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: newbie question regarding newForm POST information
country flaguser name
United States
2007-03-30 16:35:29
I see what you are saying, but I was trying to do something
a little
more complicated.  I wasn't trying to validate any data, but
rather
load choices into a select box based on information from the
POST.  I
have 2 select boxes in a form where one has info regarding
all the
countries in the world.  Onces the user selects a country, I
populate
another select box with all the states for that country.  I
decided to
do most of this with javascript and got it working that
way.

But then I ran into another problem.  If the page has an
error and is
reloaded then the states aren't populated in the select box
again.  I
had to update the constructor in my form and update those
select boxes
manually with the correct choices.  What I didn't know
previously was
a form constructor always has a self.data variable once a
request is
passed in.  Here is my code if anyone is interested:

from main_site.static.models import StaticCountries,
StaticRegions
def __init__(self, *args, **kwargs):
        super(CustomerAdd, self).__init__( *args, **kwargs)

        #checking if this is post information
        if (self.is_bound == True):
            #we have to check if the user selected a country
in
mailing/shipping/or billing select boxes
            #...if they did, then we have to populate the
state select
box
            #   with the corresponding states for that
country
            if (self.data.get('mailing_country') !=
"None"):
                self.fields['mailing_state'].choices =
([x.region,
x.region] for x in
StaticRegions.objects.filter(country_code=self.data.get('mai
ling_country')).order_by("region"))



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )