Discussion:
Need help: request.POST.copy() ?
(too old to reply)
hank23
2011-04-01 00:48:42 UTC
Permalink
I need to know when I can or should use request.POST.copy() when
processing screens, as opposed to when not to use it. I've used it
some, on one screen in particular, which seems to work fine for
displaying the data that I want to display, when I put the data on the
screen programatically from within a view. However when I try to alter
the data manually by keying it in from my keyboard, or selecting an
option from a dropdown, nothing seems to show up changed the next time
that submit the form to the view and look at the data posted. So I'm
wondering if there is something else going on or if this problem is
some kind of side effect of using request.POST.copy()?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Sam Walters
2011-04-01 01:07:40 UTC
Permalink
Hi hank23
request.POST would be immutable.

"QueryDict instances are immutable, unless you create a copy() of
them. That means you can't change attributes of request.POST and
request.GET directly."

http://docs.djangoproject.com/en/dev/ref/request-response/


So I'm
Post by hank23
wondering if there is something else going on or if this problem is
some kind of side effect of using request.POST.copy()?
I dont know what you mean by side-effect.

I copy/instantiate querydicts all the time never had any problems.
Dont forget if you can use python to clone objects :)

cheers

sam_W
Post by hank23
I need to know when I can or should use request.POST.copy() when
processing screens, as opposed to when not to use it. I've used it
some, on one screen in particular, which seems to work fine for
displaying the data that I want to display, when I put the data on the
screen programatically from within a view. However when I try to alter
the data manually by keying it in from my keyboard, or selecting an
option from a dropdown, nothing seems to show up changed the next time
that submit the form to the view and look at the data posted. So I'm
wondering if there is something else going on or if this problem is
some kind of side effect of using request.POST.copy()?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
hank23
2011-04-01 01:24:54 UTC
Permalink
Currently I have logic in place that makes a copy of request.POST so
it can put data from a record using a key, gotten from the previous
bunch of POSTed data, on the screen for display purposes. This all
works fine. But when I go in and alter some of the data being
displayed then the next time I submit the form the data that I just
entered is not displaying in the request.POST dictionary when I look
at it. So what am I apparently not doing right to cause the data to be
lost? I display the data to the screen after making a copy of
request.POST (request.POST.copy()) like this:

request.POST['title'] = record.title

I actually call sub views from the main view which processes this
screen, display the data as shown above as well as capture the changes
to the request.POST dictionary like this:

title = request.POST['title']

After trying to capture the data this way then I try to write it to
the database, but nothing new is being saved, so that's why I'm
wondering why no new data is being saved.
Post by Sam Walters
Hi hank23
request.POST would be immutable.
"QueryDict instances are immutable, unless you create a copy() of
them. That means you can't change attributes of request.POST and
request.GET directly."
http://docs.djangoproject.com/en/dev/ref/request-response/
So I'm
Post by hank23
wondering if there is something else going on or if this problem is
some kind of side effect of using request.POST.copy()?
I dont know what you mean by side-effect.
I copy/instantiate querydicts all the time never had any problems.
Dont forget if you can use python to clone objects :)
cheers
sam_W
Post by hank23
I need to know when I can or should use request.POST.copy() when
processing screens, as opposed to when not to use it. I've used it
some, on one screen in particular, which seems to work fine for
displaying the data that I want to display, when I put the data on the
screen programatically from within a view. However when I try to alter
the data manually by keying it in from my keyboard, or selecting an
option from a dropdown, nothing seems to show up changed the next time
that submit the form to the view and look at the data posted. So I'm
wondering if there is something else going on or if this problem is
some kind of side effect of using request.POST.copy()?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.- Hide quoted text -
- Show quoted text -
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
hank23
2011-04-01 01:30:42 UTC
Permalink
Sorry the last example I gave maybe wrong. I think I'm actually
getting the data back out using the cleaned_data. I'm trying to do
this from memory, since this is a work problem and I've been
struggling with it since the middle of this afternoon and it's been
very frustrating.
Post by hank23
Currently I have logic in place that makes a copy of request.POST so
it can put data from a record using a key, gotten from the previous
bunch of POSTed data, on the screen for display purposes. This all
works fine. But when I go in and alter some of the data being
displayed then the next time I submit the form the data that I just
entered is not displaying in the request.POST dictionary when I look
at it. So what am I apparently not doing right to cause the data to be
lost? I display the data to the screen after making a copy of
request.POST['title'] = record.title
I actually call sub views from the main view which processes this
screen, display the data as shown above as well as capture the changes
title = request.POST['title']
After trying to capture the data this way then I try to write it to
the database, but nothing new is being saved, so that's why I'm
wondering why no new data  is being saved.
Post by Sam Walters
Hi hank23
request.POST would be immutable.
"QueryDict instances are immutable, unless you create a copy() of
them. That means you can't change attributes of request.POST and
request.GET directly."
http://docs.djangoproject.com/en/dev/ref/request-response/
So I'm
Post by hank23
wondering if there is something else going on or if this problem is
some kind of side effect of using request.POST.copy()?
I dont know what you mean by side-effect.
I copy/instantiate querydicts all the time never had any problems.
Dont forget if you can use python to clone objects :)
cheers
sam_W
Post by hank23
I need to know when I can or should use request.POST.copy() when
processing screens, as opposed to when not to use it. I've used it
some, on one screen in particular, which seems to work fine for
displaying the data that I want to display, when I put the data on the
screen programatically from within a view. However when I try to alter
the data manually by keying it in from my keyboard, or selecting an
option from a dropdown, nothing seems to show up changed the next time
that submit the form to the view and look at the data posted. So I'm
wondering if there is something else going on or if this problem is
some kind of side effect of using request.POST.copy()?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.-Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Sam Walters
2011-04-01 02:12:14 UTC
Permalink
Yes, Id really need to see some code to work it out.

A bit hard to work out wether you're returning the request.POST.copy()
and wether this is instantiated in a new form instance and returned.
Eg: if form validation fails.
Or wether you are having trouble redisplaying the original
request.POST data in a new form or one thats failed evaluation?

Once again would need to see the some code.
Post by hank23
Post by hank23
I actually call sub views from the main view which processes this
screen, display the data as shown above as well as capture the changes
title = request.POST['title']
Hmm, dont forget:
http://en.wikipedia.org/wiki/Pass_by_reference

Here is some of my basic code... eg: adding a new param 'IP address'
to request.POST form data for evaluation. This might help.

def contact(request):
from hvv.contact.forms import ContactEmailForm
#form validation: Note: ip address is not form data, is validated
as form and added to formdata by 'getIpAddr()'
if request.is_ajax() and request.POST:
#Note: copy() makes QueryDict Mutable
data = QueryDict(request.POST['form']).copy()
data.update({'ipaddress': getIpAddr(request) })
form = ContactEmailForm(data)
if form.is_valid():
n_email = form.cleaned_data['email']
n_subject = form.cleaned_data['subject']
n_message = form.cleaned_data['message']
n_ipaddr = form.cleaned_data['ipaddress']

saveInDb(n_email, n_subject, n_message, n_ipaddr)
sendEmail(n_email, n_subject, n_message, n_ipaddr)

return render_to_response('contact.html', {
'form':ContactEmailForm(), 'message':'Thankyou. Your message was
sent!.' }, context_instance=RequestContext(request))
else:
return render_to_response('contact.html', { 'form':form },
context_instance=RequestContext(request))
form = ContactEmailForm()
return render_to_response('contact.html', { 'form':form },
context_instance=RequestContext(request))

cheers

sam_w
Post by hank23
Sorry the last example I gave maybe wrong. I think I'm actually
getting the data back out using the cleaned_data. I'm trying to do
this from memory, since this is a work problem and I've been
struggling with it since the middle of this afternoon and it's been
very frustrating.
Post by hank23
Currently I have logic in place that makes a copy of request.POST so
it can put data from a record using a key, gotten from the previous
bunch of POSTed data, on the screen for display purposes. This all
works fine. But when I go in and alter some of the data being
displayed then the next time I submit the form the data that I just
entered is not displaying in the request.POST dictionary when I look
at it. So what am I apparently not doing right to cause the data to be
lost? I display the data to the screen after making a copy of
request.POST['title'] = record.title
I actually call sub views from the main view which processes this
screen, display the data as shown above as well as capture the changes
title = request.POST['title']
After trying to capture the data this way then I try to write it to
the database, but nothing new is being saved, so that's why I'm
wondering why no new data  is being saved.
Post by Sam Walters
Hi hank23
request.POST would be immutable.
"QueryDict instances are immutable, unless you create a copy() of
them. That means you can't change attributes of request.POST and
request.GET directly."
http://docs.djangoproject.com/en/dev/ref/request-response/
So I'm
Post by hank23
wondering if there is something else going on or if this problem is
some kind of side effect of using request.POST.copy()?
I dont know what you mean by side-effect.
I copy/instantiate querydicts all the time never had any problems.
Dont forget if you can use python to clone objects :)
cheers
sam_W
Post by hank23
I need to know when I can or should use request.POST.copy() when
processing screens, as opposed to when not to use it. I've used it
some, on one screen in particular, which seems to work fine for
displaying the data that I want to display, when I put the data on the
screen programatically from within a view. However when I try to alter
the data manually by keying it in from my keyboard, or selecting an
option from a dropdown, nothing seems to show up changed the next time
that submit the form to the view and look at the data posted. So I'm
wondering if there is something else going on or if this problem is
some kind of side effect of using request.POST.copy()?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.-Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
--
You received this message because you are subscribed to the Google Groups "Django users" group.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
hank23
2011-04-01 02:26:34 UTC
Permalink
Thanks. I will recheck my code and see if I can fix it. If I'm not
successful in fixing it, I'll be back on tomorrow asking some more
questions. Thanks again for the help and suggestions.
Post by Sam Walters
Yes, Id really need to see some code to work it out.
A bit hard to work out wether you're returning the request.POST.copy()
and wether this is instantiated in a new form instance and returned.
Eg: if form validation fails.
Or wether you are  having trouble redisplaying the original
request.POST data in a new form or one thats failed evaluation?
Once again would need to see the some code.
Post by hank23
Post by hank23
I actually call sub views from the main view which processes this
screen, display the data as shown above as well as capture the changes
title = request.POST['title']
Hmm, dont forget:http://en.wikipedia.org/wiki/Pass_by_reference
Here is some of my basic code... eg: adding a new param 'IP address'
to request.POST form data for evaluation. This might help.
    from hvv.contact.forms import ContactEmailForm
    #form validation: Note: ip address is not form data, is validated
as form and added to formdata by 'getIpAddr()'
        #Note: copy() makes QueryDict Mutable
        data = QueryDict(request.POST['form']).copy()
        data.update({'ipaddress': getIpAddr(request) })
        form = ContactEmailForm(data)
            n_email = form.cleaned_data['email']
            n_subject = form.cleaned_data['subject']
            n_message = form.cleaned_data['message']
            n_ipaddr = form.cleaned_data['ipaddress']
            saveInDb(n_email, n_subject, n_message, n_ipaddr)
            sendEmail(n_email, n_subject, n_message, n_ipaddr)
            return render_to_response('contact.html', {
'form':ContactEmailForm(), 'message':'Thankyou. Your message was
sent!.' }, context_instance=RequestContext(request))
            return render_to_response('contact.html', { 'form':form },
context_instance=RequestContext(request))
    form = ContactEmailForm()
    return render_to_response('contact.html', { 'form':form },
context_instance=RequestContext(request))
cheers
sam_w
Post by hank23
Sorry the last example I gave maybe wrong. I think I'm actually
getting the data back out using the cleaned_data. I'm trying to do
this from memory, since this is a work problem and I've been
struggling with it since the middle of this afternoon and it's been
very frustrating.
Post by hank23
Currently I have logic in place that makes a copy of request.POST so
it can put data from a record using a key, gotten from the previous
bunch of POSTed data, on the screen for display purposes. This all
works fine. But when I go in and alter some of the data being
displayed then the next time I submit the form the data that I just
entered is not displaying in the request.POST dictionary when I look
at it. So what am I apparently not doing right to cause the data to be
lost? I display the data to the screen after making a copy of
request.POST['title'] = record.title
I actually call sub views from the main view which processes this
screen, display the data as shown above as well as capture the changes
title = request.POST['title']
After trying to capture the data this way then I try to write it to
the database, but nothing new is being saved, so that's why I'm
wondering why no new data  is being saved.
Post by Sam Walters
Hi hank23
request.POST would be immutable.
"QueryDict instances are immutable, unless you create a copy() of
them. That means you can't change attributes of request.POST and
request.GET directly."
http://docs.djangoproject.com/en/dev/ref/request-response/
So I'm
Post by hank23
wondering if there is something else going on or if this problem is
some kind of side effect of using request.POST.copy()?
I dont know what you mean by side-effect.
I copy/instantiate querydicts all the time never had any problems.
Dont forget if you can use python to clone objects :)
cheers
sam_W
Post by hank23
I need to know when I can or should use request.POST.copy() when
processing screens, as opposed to when not to use it. I've used it
some, on one screen in particular, which seems to work fine for
displaying the data that I want to display, when I put the data on the
screen programatically from within a view. However when I try to alter
the data manually by keying it in from my keyboard, or selecting an
option from a dropdown, nothing seems to show up changed the next time
that submit the form to the view and look at the data posted. So I'm
wondering if there is something else going on or if this problem is
some kind of side effect of using request.POST.copy()?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.-Hidequoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
--
You received this message because you are subscribed to the Google Groups "Django users" group.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.- Hide quoted text -
- Show quoted text -
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Continue reading on narkive:
Loading...