[Django] #32924: Move special-case logic in BoundField.initial() to BaseForm.get_initial_for_field()

24 views
Skip to first unread message

Django

unread,
Jul 13, 2021, 11:41:27 AM7/13/21
to django-...@googlegroups.com
#32924: Move special-case logic in BoundField.initial() to
BaseForm.get_initial_for_field()
-------------------------------------+-------------------------------------
Reporter: Chris | Owner: Chris Jerdonek
Jerdonek |
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: dev
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
This is another follow-up to ticket #32920.

Currently, `BoundField.initial()` has logic to special-case `time` and
`datetime` objects:
https://github.com/django/django/blob/f5669fd7b568cf8a3eda1e65c1c6fb583c7b177d/django/forms/boundfield.py#L217-L219
I noticed that this logic can be moved to
`BaseForm.get_initial_for_field()`, and in particular under the `if
callable(value)` block:
https://github.com/django/django/blob/f5669fd7b568cf8a3eda1e65c1c6fb583c7b177d/django/forms/forms.py#L496-L497

Eventually, I think it could make sense to go further and move some of
this logic to a new method of the `Field` class, which could permit the
special-casing to be handled by overriding in sub-classes that use times
and datetimes.

--
Ticket URL: <https://code.djangoproject.com/ticket/32924>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 13, 2021, 5:21:02 PM7/13/21
to django-...@googlegroups.com
#32924: Move special-case logic in BoundField.initial() to
BaseForm.get_initial_for_field()
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Chris
Type: | Jerdonek
Cleanup/optimization | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:1>

Django

unread,
Jul 15, 2021, 11:15:15 AM7/15/21
to django-...@googlegroups.com
#32924: Move special-case logic in BoundField.initial() to
BaseForm.get_initial_for_field()
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Chris
Type: | Jerdonek
Cleanup/optimization | Status: assigned
Component: Forms | Version: dev

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chris Jerdonek):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/14641

--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:2>

Django

unread,
Jul 16, 2021, 9:35:40 AM7/16/21
to django-...@googlegroups.com
#32924: Move special-case logic in BoundField.initial() to
BaseForm.get_initial_for_field()
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Chris
Type: | Jerdonek
Cleanup/optimization | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:3>

Django

unread,
Jul 16, 2021, 10:39:07 AM7/16/21
to django-...@googlegroups.com
#32924: Move special-case logic in BoundField.initial() to
BaseForm.get_initial_for_field()
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Chris
Type: | Jerdonek
Cleanup/optimization | Status: assigned
Component: Forms | Version: dev

Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton.gibson@…>):

In [changeset:"469e76929976a7070b0bf6899a314d19e6e8e485" 469e769]:
{{{
#!CommitTicketReference repository=""
revision="469e76929976a7070b0bf6899a314d19e6e8e485"
Refs #32924 -- Changed test_get_initial_for_field() to use subTests.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:4>

Django

unread,
Jul 16, 2021, 10:39:08 AM7/16/21
to django-...@googlegroups.com
#32924: Move special-case logic in BoundField.initial() to
BaseForm.get_initial_for_field()
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Chris
Type: | Jerdonek
Cleanup/optimization | Status: closed
Component: Forms | Version: dev
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton.gibson@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"0dc25526d8daaaa59968d4b1b597968e197f040c" 0dc25526]:
{{{
#!CommitTicketReference repository=""
revision="0dc25526d8daaaa59968d4b1b597968e197f040c"
Fixed #32924 -- Changed BaseForm.get_initial_for_field() to remove
microseconds when needed.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:6>

Django

unread,
Jul 16, 2021, 10:39:08 AM7/16/21
to django-...@googlegroups.com
#32924: Move special-case logic in BoundField.initial() to
BaseForm.get_initial_for_field()
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Chris
Type: | Jerdonek
Cleanup/optimization | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton.gibson@…>):

In [changeset:"788441c6ab4e0167aadc155a4362a87694e38aa5" 788441c]:
{{{
#!CommitTicketReference repository=""
revision="788441c6ab4e0167aadc155a4362a87694e38aa5"
Refs #32924 -- Changed test_initial_datetime_values() to use subTests.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32924#comment:5>

Reply all
Reply to author
Forward
0 new messages