Opened 3 years ago

Closed 3 years ago

#32917 closed Cleanup/optimization (fixed)

Add an internal _value_from_datadict() method to BaseForm

Reported by: Chris Jerdonek Owned by: Chris Jerdonek
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

I noticed that some call sites can be simplified if an internal method called something like _value_from_datadict() is added to BaseForm. Here is one of the call sites: https://github.com/django/django/blob/6f60fa97b0b501ef7cc77e16392654bf27ec8db3/django/forms/boundfield.py#L121

Its implementation can look something like this:

def _value_from_datadict(self, field, html_name):
    return field.widget.value_from_datadict(self.data, self.files, html_name)

One reason this is nicer is that callers don't have to know about the form's self.data and self.files dicts. They can just access a method on the form, which encapsulates the data dictionaries.

Change History (3)

comment:1 by Mariusz Felisiak, 3 years ago

Triage Stage: UnreviewedAccepted

comment:3 by GitHub <noreply@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 4be58fc:

Fixed #32917 -- Added BaseForm._widget_data_value()/_field_data_value().

Note: See TracTickets for help on using tickets.
Back to Top