Re: Looping through my POST data?

2007-07-29 Thread Alvin

That is what programming language? Note you can name what? Thanks !


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looping through my POST data?

2007-07-28 Thread Malcolm Tredinnick

On Sat, 2007-07-28 at 19:44 -0700, Greg wrote:
> I tried to implement the above view.  However, I'm having errors.
> Again i think it has to do with the u character in my dict.  Here is
> my view:
[... snipped ...]
> This is the error I get:
> 
> MultiValueDictKeyError at /rugs/cart/addpad/
> "Key 1 not found in  u'2': [u'1'], u'5': [u'0'], u'4': [u'0'], u'7': [u'0'], u'6': [u'0'],
> u'8': [u'0']}>"
> 
> It can't find the key 1...because the key is actually u'1'???  I don't
> know where the u is coming from.

Form data values are always strings. The u'1' means it's a Unicode
string in Python, but it's still a string. The fact is, we have no way
of knowing, when somebody sends the byte for "1", whether they mean a
string or an integer, so we don't guess.

This is normally why helper functions, such as a newforms.Form subclass
are normally used: it can validate that the data is what you are
expecting (integers in this case) and convert them to the correct Python
types.

If you can't model the submitted data as a form somehow (e.g. if it's
not regular enough), you are going to have to convert the values to the
right Python types yourself. Form data names are always strings
(essentially), so converting them won't be too useful.

Possibly the solution in your case is to simply coerce the id values to
Unicode strings (even normal strings will do) before comparison. So
something like

if request.POST[str(a.id)] != 0:
# ...

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looping through my POST data?

2007-07-28 Thread Greg

I tried to implement the above view.  However, I'm having errors.
Again i think it has to do with the u character in my dict.  Here is
my view:

def addpad(request):
if request.method == 'POST':
pads = request.session.get('pad', [])
pad = RugPad.objects.all()
#assert False, pad
for a in pad:
if request.POST[a.id] != 0:
opad = RugPad.objects.get(id=a)
s = opad.size
p = opad.price
pads.append({'size': s, 'price': p, 'quanity': 
request[a]})
request.session['pad'] = pads
return HttpResponseRedirect("/rugs/cart/checkout")

///

This is the error I get:

MultiValueDictKeyError at /rugs/cart/addpad/
"Key 1 not found in "

It can't find the key 1...because the key is actually u'1'???  I don't
know where the u is coming from.

Thanks

On Jul 28, 10:25 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Right... because, unless I'm misunderstanding your code... you're
> creating a select drop down for each of your RugPad entires with the
> RugPad id.  So you know that the request.POST is going to have entries
> for each id...
>
> But..I think it should be this:
> opads = RugPad.objects.all()
> for a in opads:
>  if request.POST[a.id] != 0:
>opad = RugPad.objects.get(id=a)
>s = opad.size
>p = opad.price
>pads.append({'size': s, 'price': p})
>
> So now you'd be iterating through each of your rug pads, and checking
> to see if the corresponding drop down had a non-zero value selected,
> instead of iterating all of the request.POST keys.  This way you can
> have other items in your form if needed.
>
> On Jul 28, 10:58 am, Greg <[EMAIL PROTECTED]> wrote:
>
> > Carole,
> > So your saying that I should do:
>
> > opad = RugPad.objects.all()
> > for a in opad.id
> > if request[a] != 0
> > .#add to session
>
> > On Jul 28, 8:43 am, "[EMAIL PROTECTED]"
>
> > <[EMAIL PROTECTED]> wrote:
> > > Greg... I'm curious as to why you're iterating over the entire
> > > request.POST  when you could just use the id of each pad that you've
> > > previously passed to your template to retrieve it from the
> > > request.POST dict, as that is what you've named your select statements
> > > with?
>
> > > While iterating through all of the request.POST key/value pairs works,
> > > if you choose to later add any other inputs to your screen that aren't
> > > drop downs for your CarpetPads, you'll have to add special code for
> > > each of them so that your code won't attempt to add a RugPad for those
> > > key/value pairs.  Just wanted to point that out, in case you might
> > > need to do that later.
>
> > > Carole
>
> > > On Jul 28, 9:15 am, Greg <[EMAIL PROTECTED]> wrote:
>
> > > > Nathan,
> > > > Thanks for your help...I got it working.  This is what I used:
>
> > > > if values != list("0"):
>
> > > > Is that what you were recommending?  Because I couldn't convert a list
> > > > (values) to a int.  Since values was a list I decided to convert my
> > > > int to a list and that worked.  Can you tell me what the u stands for
> > > > when i do a 'assert False, values':  It returns a [u'0'].  Why doesn't
> > > > it just return a ['0']?  Also, it there anyway that I can convert the
> > > > 'values' variable to a int so that I can do a comparison without
> > > > converting the 0 to a list?
>
> > > > Thanks
>
> > > > On Jul 28, 2:57 am, Nathan Ostgard <[EMAIL PROTECTED]> wrote:
>
> > > > > To illustrate with the Python shell:
>
> > > > > >>> 0 == "0"
> > > > > False
> > > > > >>> 0 == int("0")
>
> > > > > True
>
> > > > > On Jul 27, 11:10 pm, Sean Perry <[EMAIL PROTECTED]> wrote:
>
> > > > > > On Jul 27, 2007, at 10:36 PM, Greg wrote:
>
> > > > > > > AssertionError at /rugs/cart/addpad/
> > > > > > > [u'0']
>
> > > > > > > Does that mean that the value is 0?  below is my view function and
> > > > > > > template code:
>
> > > > > > That little 'u' in front of the '0' means unicode so the value is 
> > > > > > the
> > > > > > unicode string "0" not the number zero. Very different as far as
> > > > > > Python is concerned. You may be used to other scripting languages
> > > > > > that auto-convert. Python is not one of them.
>
> > > > > > try:
> > > > > >  num = int(values)
> > > > > >  if num == 0:
> > > > > >  deal_with_zero()
> > > > > >  else:
> > > > > >  deal_with_number(num)
> > > > > > except ValueError:
> > > > > > # hmm, values is a string, not a number
> > > > > > deal_with_a_string(values)
>
> > > > Hope that helps.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, 

Re: Looping through my POST data?

2007-07-28 Thread [EMAIL PROTECTED]

Right... because, unless I'm misunderstanding your code... you're
creating a select drop down for each of your RugPad entires with the
RugPad id.  So you know that the request.POST is going to have entries
for each id...

But..I think it should be this:
opads = RugPad.objects.all()
for a in opads:
 if request.POST[a.id] != 0:
   opad = RugPad.objects.get(id=a)
   s = opad.size
   p = opad.price
   pads.append({'size': s, 'price': p})

So now you'd be iterating through each of your rug pads, and checking
to see if the corresponding drop down had a non-zero value selected,
instead of iterating all of the request.POST keys.  This way you can
have other items in your form if needed.


On Jul 28, 10:58 am, Greg <[EMAIL PROTECTED]> wrote:
> Carole,
> So your saying that I should do:
>
> opad = RugPad.objects.all()
> for a in opad.id
> if request[a] != 0
> .#add to session
>
> On Jul 28, 8:43 am, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > Greg... I'm curious as to why you're iterating over the entire
> > request.POST  when you could just use the id of each pad that you've
> > previously passed to your template to retrieve it from the
> > request.POST dict, as that is what you've named your select statements
> > with?
>
> > While iterating through all of the request.POST key/value pairs works,
> > if you choose to later add any other inputs to your screen that aren't
> > drop downs for your CarpetPads, you'll have to add special code for
> > each of them so that your code won't attempt to add a RugPad for those
> > key/value pairs.  Just wanted to point that out, in case you might
> > need to do that later.
>
> > Carole
>
> > On Jul 28, 9:15 am, Greg <[EMAIL PROTECTED]> wrote:
>
> > > Nathan,
> > > Thanks for your help...I got it working.  This is what I used:
>
> > > if values != list("0"):
>
> > > Is that what you were recommending?  Because I couldn't convert a list
> > > (values) to a int.  Since values was a list I decided to convert my
> > > int to a list and that worked.  Can you tell me what the u stands for
> > > when i do a 'assert False, values':  It returns a [u'0'].  Why doesn't
> > > it just return a ['0']?  Also, it there anyway that I can convert the
> > > 'values' variable to a int so that I can do a comparison without
> > > converting the 0 to a list?
>
> > > Thanks
>
> > > On Jul 28, 2:57 am, Nathan Ostgard <[EMAIL PROTECTED]> wrote:
>
> > > > To illustrate with the Python shell:
>
> > > > >>> 0 == "0"
> > > > False
> > > > >>> 0 == int("0")
>
> > > > True
>
> > > > On Jul 27, 11:10 pm, Sean Perry <[EMAIL PROTECTED]> wrote:
>
> > > > > On Jul 27, 2007, at 10:36 PM, Greg wrote:
>
> > > > > > AssertionError at /rugs/cart/addpad/
> > > > > > [u'0']
>
> > > > > > Does that mean that the value is 0?  below is my view function and
> > > > > > template code:
>
> > > > > That little 'u' in front of the '0' means unicode so the value is the
> > > > > unicode string "0" not the number zero. Very different as far as
> > > > > Python is concerned. You may be used to other scripting languages
> > > > > that auto-convert. Python is not one of them.
>
> > > > > try:
> > > > >  num = int(values)
> > > > >  if num == 0:
> > > > >  deal_with_zero()
> > > > >  else:
> > > > >  deal_with_number(num)
> > > > > except ValueError:
> > > > > # hmm, values is a string, not a number
> > > > > deal_with_a_string(values)
>
> > > Hope that helps.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looping through my POST data?

2007-07-28 Thread Greg

Carole,
So your saying that I should do:

opad = RugPad.objects.all()
for a in opad.id
if request[a] != 0
.#add to session




On Jul 28, 8:43 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Greg... I'm curious as to why you're iterating over the entire
> request.POST  when you could just use the id of each pad that you've
> previously passed to your template to retrieve it from the
> request.POST dict, as that is what you've named your select statements
> with?
>
> While iterating through all of the request.POST key/value pairs works,
> if you choose to later add any other inputs to your screen that aren't
> drop downs for your CarpetPads, you'll have to add special code for
> each of them so that your code won't attempt to add a RugPad for those
> key/value pairs.  Just wanted to point that out, in case you might
> need to do that later.
>
> Carole
>
> On Jul 28, 9:15 am, Greg <[EMAIL PROTECTED]> wrote:
>
> > Nathan,
> > Thanks for your help...I got it working.  This is what I used:
>
> > if values != list("0"):
>
> > Is that what you were recommending?  Because I couldn't convert a list
> > (values) to a int.  Since values was a list I decided to convert my
> > int to a list and that worked.  Can you tell me what the u stands for
> > when i do a 'assert False, values':  It returns a [u'0'].  Why doesn't
> > it just return a ['0']?  Also, it there anyway that I can convert the
> > 'values' variable to a int so that I can do a comparison without
> > converting the 0 to a list?
>
> > Thanks
>
> > On Jul 28, 2:57 am, Nathan Ostgard <[EMAIL PROTECTED]> wrote:
>
> > > To illustrate with the Python shell:
>
> > > >>> 0 == "0"
> > > False
> > > >>> 0 == int("0")
>
> > > True
>
> > > On Jul 27, 11:10 pm, Sean Perry <[EMAIL PROTECTED]> wrote:
>
> > > > On Jul 27, 2007, at 10:36 PM, Greg wrote:
>
> > > > > AssertionError at /rugs/cart/addpad/
> > > > > [u'0']
>
> > > > > Does that mean that the value is 0?  below is my view function and
> > > > > template code:
>
> > > > That little 'u' in front of the '0' means unicode so the value is the
> > > > unicode string "0" not the number zero. Very different as far as
> > > > Python is concerned. You may be used to other scripting languages
> > > > that auto-convert. Python is not one of them.
>
> > > > try:
> > > >  num = int(values)
> > > >  if num == 0:
> > > >  deal_with_zero()
> > > >  else:
> > > >  deal_with_number(num)
> > > > except ValueError:
> > > > # hmm, values is a string, not a number
> > > > deal_with_a_string(values)
>
> >
> > Hope that helps.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looping through my POST data?

2007-07-28 Thread [EMAIL PROTECTED]

Greg... I'm curious as to why you're iterating over the entire
request.POST  when you could just use the id of each pad that you've
previously passed to your template to retrieve it from the
request.POST dict, as that is what you've named your select statements
with?

While iterating through all of the request.POST key/value pairs works,
if you choose to later add any other inputs to your screen that aren't
drop downs for your CarpetPads, you'll have to add special code for
each of them so that your code won't attempt to add a RugPad for those
key/value pairs.  Just wanted to point that out, in case you might
need to do that later.

Carole

On Jul 28, 9:15 am, Greg <[EMAIL PROTECTED]> wrote:
> Nathan,
> Thanks for your help...I got it working.  This is what I used:
>
> if values != list("0"):
>
> Is that what you were recommending?  Because I couldn't convert a list
> (values) to a int.  Since values was a list I decided to convert my
> int to a list and that worked.  Can you tell me what the u stands for
> when i do a 'assert False, values':  It returns a [u'0'].  Why doesn't
> it just return a ['0']?  Also, it there anyway that I can convert the
> 'values' variable to a int so that I can do a comparison without
> converting the 0 to a list?
>
> Thanks
>
> On Jul 28, 2:57 am, Nathan Ostgard <[EMAIL PROTECTED]> wrote:
>
> > To illustrate with the Python shell:
>
> > >>> 0 == "0"
> > False
> > >>> 0 == int("0")
>
> > True
>
> > On Jul 27, 11:10 pm, Sean Perry <[EMAIL PROTECTED]> wrote:
>
> > > On Jul 27, 2007, at 10:36 PM, Greg wrote:
>
> > > > AssertionError at /rugs/cart/addpad/
> > > > [u'0']
>
> > > > Does that mean that the value is 0?  below is my view function and
> > > > template code:
>
> > > That little 'u' in front of the '0' means unicode so the value is the
> > > unicode string "0" not the number zero. Very different as far as
> > > Python is concerned. You may be used to other scripting languages
> > > that auto-convert. Python is not one of them.
>
> > > try:
> > >  num = int(values)
> > >  if num == 0:
> > >  deal_with_zero()
> > >  else:
> > >  deal_with_number(num)
> > > except ValueError:
> > > # hmm, values is a string, not a number
> > > deal_with_a_string(values)
>
> > > Hope that helps.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looping through my POST data?

2007-07-28 Thread Greg

Nathan,
Thanks for your help...I got it working.  This is what I used:

if values != list("0"):

Is that what you were recommending?  Because I couldn't convert a list
(values) to a int.  Since values was a list I decided to convert my
int to a list and that worked.  Can you tell me what the u stands for
when i do a 'assert False, values':  It returns a [u'0'].  Why doesn't
it just return a ['0']?  Also, it there anyway that I can convert the
'values' variable to a int so that I can do a comparison without
converting the 0 to a list?

Thanks

On Jul 28, 2:57 am, Nathan Ostgard <[EMAIL PROTECTED]> wrote:
> To illustrate with the Python shell:
>
> >>> 0 == "0"
> False
> >>> 0 == int("0")
>
> True
>
> On Jul 27, 11:10 pm, Sean Perry <[EMAIL PROTECTED]> wrote:
>
> > On Jul 27, 2007, at 10:36 PM, Greg wrote:
>
> > > AssertionError at /rugs/cart/addpad/
> > > [u'0']
>
> > > Does that mean that the value is 0?  below is my view function and
> > > template code:
>
> > That little 'u' in front of the '0' means unicode so the value is the
> > unicode string "0" not the number zero. Very different as far as
> > Python is concerned. You may be used to other scripting languages
> > that auto-convert. Python is not one of them.
>
> > try:
> >  num = int(values)
> >  if num == 0:
> >  deal_with_zero()
> >  else:
> >  deal_with_number(num)
> > except ValueError:
> > # hmm, values is a string, not a number
> > deal_with_a_string(values)
>
> > Hope that helps.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looping through my POST data?

2007-07-28 Thread Nathan Ostgard

To illustrate with the Python shell:

>>> 0 == "0"
False
>>> 0 == int("0")
True

On Jul 27, 11:10 pm, Sean Perry <[EMAIL PROTECTED]> wrote:
> On Jul 27, 2007, at 10:36 PM, Greg wrote:
>
> > AssertionError at /rugs/cart/addpad/
> > [u'0']
>
> > Does that mean that the value is 0?  below is my view function and
> > template code:
>
> That little 'u' in front of the '0' means unicode so the value is the
> unicode string "0" not the number zero. Very different as far as
> Python is concerned. You may be used to other scripting languages
> that auto-convert. Python is not one of them.
>
> try:
>  num = int(values)
>  if num == 0:
>  deal_with_zero()
>  else:
>  deal_with_number(num)
> except ValueError:
> # hmm, values is a string, not a number
> deal_with_a_string(values)
>
> Hope that helps.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looping through my POST data?

2007-07-28 Thread Sean Perry

On Jul 27, 2007, at 10:36 PM, Greg wrote:
> AssertionError at /rugs/cart/addpad/
> [u'0']
>
> Does that mean that the value is 0?  below is my view function and
> template code:

That little 'u' in front of the '0' means unicode so the value is the  
unicode string "0" not the number zero. Very different as far as  
Python is concerned. You may be used to other scripting languages  
that auto-convert. Python is not one of them.

try:
 num = int(values)
 if num == 0:
 deal_with_zero()
 else:
 deal_with_number(num)
except ValueError:
# hmm, values is a string, not a number
deal_with_a_string(values)

Hope that helps.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looping through my POST data?

2007-07-27 Thread Greg

Nathan,
Thanks for the iteritems() method.  I implemented that into my code.
However, 'if values != 0:' never evaluates to False.  Even though some
of the forms elements values are 0.  For example when I do a assert
False, values on one of those elements I see:

AssertionError at /rugs/cart/addpad/
[u'0']

Does that mean that the value is 0?  below is my view function and
template code:

//
def addpad(request):
if request.method == 'POST':
pads = request.session.get('pad', [])
for a, values in request.POST.iteritems():
#assert False, values
if values != 0:
opad = RugPad.objects.get(id=a)
s = opad.size
p = opad.price
pads.append({'size': s, 'price': p})
request.session['pad'] = pads
else:
assert False, "It got here" #It never gets here
return render_to_response('addpad.html', {'spad':
request.session['pad']})

/

{% for a in pad %}

 
  
   ---
   1
   2
   3
   4
   5
   {{ a.size }} -- ${{ a.price }}
 

{% endfor %}

/

I'm thinking that my values variable is not a int.  I tried
int(values) but that still didn't work.  How do I get it so that
values is a int so that I can do 'if values != 0:'?

Thanks


On Jul 27, 8:49 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> I'm not sure if I'm following what your saying...but this is what I
> think you want to do:
>
> if request.method == 'POST':
>pads = request.session.get('pad', [])
>for pad in pads:
> if request.POST[pad.id] <> '---': # the select
> name should be the pad id based on your template code
> # do something here ... because it wasn't
> ---
>
> On Jul 27, 5:54 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > I'm trying to loop through my POST data.  However I am having
> > difficulties.  I think my 'for' statement might be wrong.  Below is my
> > function and template code
>
> >  View function
>
> > def addpad(request):
> > if request.method == 'POST':
> > pads = request.session.get('pad', [])
> > i = 0
> > b = 1
> > for a in request.POST:
> > if a != '---':
> > opad = RugPad.objects.get(id=b)
> > s = opad.size
> > p = opad.price
> > pads.append({'size': s, 'price': p})
> > request.session['pad'] = pads
> > i = i + 1
> > b = b + 1
> > return render_to_response('addpad.html', {'spad':
> > request.session['pad']})
>
> > / Template File
>
> > {% for a in pad %}
> > 
> >  
> >   
> >---
> >1
> >2
> >3
> >4
> >5
> >{{ a.size }} -- ${{ a.price }}
> >  
> > 
> > {% endfor %}
>
> > //
>
> > Notice how my 'for' statement is listed as ' for a in request.POST:
> > '.  However, when i do a 'assert False, a' it always returns the value
> > '1'.  I need to get the value of each select statement.  Such as (---,
> > 1,2,3,4,5).
>
> > Is that 'for' statement returning me the value of each select
> > statement?
>
> > Thanks


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looping through my POST data?

2007-07-27 Thread [EMAIL PROTECTED]

I'm not sure if I'm following what your saying...but this is what I
think you want to do:

if request.method == 'POST':
   pads = request.session.get('pad', [])
   for pad in pads:
if request.POST[pad.id] <> '---': # the select
name should be the pad id based on your template code
# do something here ... because it wasn't
---


On Jul 27, 5:54 pm, Greg <[EMAIL PROTECTED]> wrote:
> I'm trying to loop through my POST data.  However I am having
> difficulties.  I think my 'for' statement might be wrong.  Below is my
> function and template code
>
>  View function
>
> def addpad(request):
> if request.method == 'POST':
> pads = request.session.get('pad', [])
> i = 0
> b = 1
> for a in request.POST:
> if a != '---':
> opad = RugPad.objects.get(id=b)
> s = opad.size
> p = opad.price
> pads.append({'size': s, 'price': p})
> request.session['pad'] = pads
> i = i + 1
> b = b + 1
> return render_to_response('addpad.html', {'spad':
> request.session['pad']})
>
> / Template File
>
> {% for a in pad %}
> 
>  
>   
>---
>1
>2
>3
>4
>5
>{{ a.size }} -- ${{ a.price }}
>  
> 
> {% endfor %}
>
> //
>
> Notice how my 'for' statement is listed as ' for a in request.POST:
> '.  However, when i do a 'assert False, a' it always returns the value
> '1'.  I need to get the value of each select statement.  Such as (---,
> 1,2,3,4,5).
>
> Is that 'for' statement returning me the value of each select
> statement?
>
> Thanks


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Looping through my POST data?

2007-07-27 Thread Nathan Ostgard

request.POST is a dictionary, not a list, so a for loop like yours is
iterating over the keys of the dict. to get the values, you can do:

for value in request.POST.itervalues():

to iterate over both keys and values:

for a, value in request.POST.iteritems():

On Jul 27, 2:54 pm, Greg <[EMAIL PROTECTED]> wrote:
> I'm trying to loop through my POST data.  However I am having
> difficulties.  I think my 'for' statement might be wrong.  Below is my
> function and template code
>
>  View function
>
> def addpad(request):
> if request.method == 'POST':
> pads = request.session.get('pad', [])
> i = 0
> b = 1
> for a in request.POST:
> if a != '---':
> opad = RugPad.objects.get(id=b)
> s = opad.size
> p = opad.price
> pads.append({'size': s, 'price': p})
> request.session['pad'] = pads
> i = i + 1
> b = b + 1
> return render_to_response('addpad.html', {'spad':
> request.session['pad']})
>
> / Template File
>
> {% for a in pad %}
> 
>  
>   
>---
>1
>2
>3
>4
>5
>{{ a.size }} -- ${{ a.price }}
>  
> 
> {% endfor %}
>
> //
>
> Notice how my 'for' statement is listed as ' for a in request.POST:
> '.  However, when i do a 'assert False, a' it always returns the value
> '1'.  I need to get the value of each select statement.  Such as (---,
> 1,2,3,4,5).
>
> Is that 'for' statement returning me the value of each select
> statement?
>
> Thanks


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Looping through my POST data?

2007-07-27 Thread Greg

I'm trying to loop through my POST data.  However I am having
difficulties.  I think my 'for' statement might be wrong.  Below is my
function and template code

 View function

def addpad(request):
if request.method == 'POST':
pads = request.session.get('pad', [])
i = 0
b = 1
for a in request.POST:
if a != '---':
opad = RugPad.objects.get(id=b)
s = opad.size
p = opad.price
pads.append({'size': s, 'price': p})
request.session['pad'] = pads
i = i + 1
b = b + 1
return render_to_response('addpad.html', {'spad':
request.session['pad']})

/ Template File

{% for a in pad %}

 
  
   ---
   1
   2
   3
   4
   5
   {{ a.size }} -- ${{ a.price }}
 

{% endfor %}

//

Notice how my 'for' statement is listed as ' for a in request.POST:
'.  However, when i do a 'assert False, a' it always returns the value
'1'.  I need to get the value of each select statement.  Such as (---,
1,2,3,4,5).

Is that 'for' statement returning me the value of each select
statement?

Thanks


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---