Thursday, March 31, 2011

Re: Need help: request.POST.copy() ?

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.

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

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


On Fri, Apr 1, 2011 at 12:30 PM, hank23 <hversemann@stchas.edu> wrote:
> 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.
>
>
>
> On Mar 31, 8:24 pm, hank23 <hversem...@stchas.edu> wrote:
>> 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.
>>
>> On Mar 31, 8:07 pm, Sam Walters <mr.sam...@gmail.com> wrote:
>>
>>
>>
>> > 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
>>
>> > > 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
>>
>> > On Fri, Apr 1, 2011 at 11:48 AM, hank23 <hversem...@stchas.edu> wrote:
>> > > 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-users@googlegroups.com.
>> > > To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
>> > > 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-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> 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-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment