On 9 oct, 20:53, Taylor <[EMAIL PROTECTED]> wrote:
> Dave, that is the problem. I need to be able to call perform
> elsewhere in the code (not necessarily from a view), and it would be
> difficult to build the datadict to do that
Why so ???
Using keywords, your call would like this:
ab.perform(arg1=x, arg2=y, yadda=yadda)
Using a datadict, this would be:
ab.perform(dict(arg1=x, arg2=y, yadda=yadda))
That is a four letters and 2 parens overhead. Not optimal indeed, but
hardly "difficult"...
> I like your solution, though.
>
> For now I'm using this loop:
> data = {}
> for key in request.POST.keys():
> data[str(key)] = str(request.POST[key])
POST is a QueryDict, not a dict. This means that when multiple values
are submitted for the same key (which is allowed by HTTP), using
POST[key] will only retrieve the last one[1]. And while we're at it,
you don't have to (and should not) make *values* strings too.
Also, you may want to use a more pythonic and concise syntax for such
a simple operation:
data = dict((str(k), v) for k, v in request.POST.items())
But you'll still have a potential problem with multiple values...
[1] http://docs.djangoproject.com/en/dev/ref/request-response/#querydict-objects
> ab.perform(**data)
>
> which works, but it bugs me a little. I don't think I'll have that
> many POST items that it will be a big deal,
I don't think you should worry about performances issues here.
> and I suppose any method
> built into request.POST would have to do the same thing.
Indeed.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---