#4271 closed (wontfix)
Form should use a copy of data passed to it
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Design decision needed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Usually, one passes POST data directly to the form like so:
if request.method == 'POST': form = MyForm(request.POST)
and request.POST is an immutable QueryDict. This means that you cannot fiddle with the data, for say if you wanted to remove keys so that the data doesn't get redisplayed when the form has errors.
I could make the copy in my own code:
form = MyForm(request.POST.copy())
but just thought this might be something useful to do more generally.
If anyone has a better alternative for not redisplaying submitted data, please mention it.
Attachments (1)
Change History (4)
by , 18 years ago
comment:1 by , 18 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Based on the the django-dev thread, this didn't get a lot of support from core developers. The logic was that
the copy operation is not free, so in the odd case when the developer wants to modify the data, they can make the copy manually (since it's not difficult).
comment:3 by , 17 years ago
For those needing this, here would be a way to put it in your form so that the developer using your form doesn't need to know to pass a copy of the post data in the view:
class MyForm(forms.Form): def __init__(self, data=None, *args, **kwargs): if data: data = data.copy() super(MyForm, self).__init__(data, *args, **kwargs)
use copy of passed data.