Form enhancement: `Form.set_data` to set data and files
|Reported by:||bruth||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 is_bound, data and 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:1 Changed 3 years ago by bruth
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 3 years ago by bruth
- Summary changed from Form enhancement: `Form.set_data` to set data an files to Form enhancement: `Form.set_data` to set data and files
comment:3 Changed 3 years ago by anonymous
- Needs tests set
- Patch needs improvement set
- Triage Stage changed from Unreviewed to Design decision needed