Form enhancement: `Form.set_data` to set data and files
|Reported by:||Byron Ruth||Owned by:||nobody|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||yes|
This simply moves the logic for setting
files into a method which enables setting the data after form initialization. This is a backwards compatible. This makes it easier to not have to initialize a form twice in view. It changes from this idiom:
def view(request): if request.method == 'POST': form = Form(request.POST, request.FILES) ... else: form = Form() ...
to simply this:
def view(request): form = Form() if request.method == 'POST': form.set_data(request.POST, request.FILES) ...
This reduces clutter and redundancy when there are a lot of form arguments passed.
Change History (6)
comment:2 Changed 4 years ago by
|Summary:||Form enhancement: `Form.set_data` to set data an files → Form enhancement: `Form.set_data` to set data and files|
comment:3 Changed 4 years ago by
|Patch needs improvement:||set|
|Triage Stage:||Unreviewed → Design decision needed|