[Django] #28090: TimeField rendering in admin forms

4 views
Skip to first unread message

Django

unread,
Apr 17, 2017, 9:15:12 PM4/17/17
to django-...@googlegroups.com
#28090: TimeField rendering in admin forms
-----------------------------------------+------------------------
Reporter: Tomek Rej | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
When passing a datetime.Time instance to the choices parameter in a
TimeField, the admin template converts it to a human readable form. Eg
Time(0, 0) gets converted to "midnight", Time(1, 30) gets converted to
1:30 a.m. In Django 1.10 it gets formatted as 00:00:00 and 01:30:00
respectively.

An example of the choices I pass in to the constructor is:

{{{
[
(datetime.Time(0, 0), '00:00'),
(datetime.Time(0, 30), '00:30'),
(datetime.Time(1, 0), '01:00'),
....,
(datetime.Time(23, 30), '23:30')
]
}}}

This causes the admin form validation to fail with errors like the
following:
''Select a valid choice. midnight is not one of the available choices.''

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

Django

unread,
Apr 19, 2017, 2:55:53 AM4/19/17
to django-...@googlegroups.com
#28090: TimeField rendering in admin forms
-------------------------------+--------------------------------------

Reporter: Tomek Rej | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Musen):

* cc: ygan@… (added)


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

Django

unread,
Apr 20, 2017, 8:15:32 AM4/20/17
to django-...@googlegroups.com
#28090: TimeField's value incorrectly localized in forms
---------------------------+-------------------------------------

Reporter: Tomek Rej | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.11
Severity: Normal | Resolution: duplicate
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 Tim Graham):

* status: new => closed
* component: Uncategorized => Forms
* resolution: => duplicate
* stage: Unreviewed => Accepted


Old description:

> When passing a datetime.Time instance to the choices parameter in a
> TimeField, the admin template converts it to a human readable form. Eg
> Time(0, 0) gets converted to "midnight", Time(1, 30) gets converted to
> 1:30 a.m. In Django 1.10 it gets formatted as 00:00:00 and 01:30:00
> respectively.
>
> An example of the choices I pass in to the constructor is:
>
> {{{
> [
> (datetime.Time(0, 0), '00:00'),
> (datetime.Time(0, 30), '00:30'),
> (datetime.Time(1, 0), '01:00'),
> ....,
> (datetime.Time(23, 30), '23:30')
> ]
> }}}
>
> This causes the admin form validation to fail with errors like the
> following:
> ''Select a valid choice. midnight is not one of the available choices.''

New description:

When passing a `datetime.time` instance to the choices parameter in a
`TimeField`, the admin template converts it to a human readable form. For
example, `time(0, 0)` is converted to "midnight", `time(1, 30)` is
converted to 1:30 a.m. In Django 1.10, it gets formatted as 00:00:00 and
01:30:00 respectively.

An example of the choices I pass in to the constructor is:

{{{
[
(datetime.time(0, 0), '00:00'),
(datetime.time(0, 30), '00:30'),
(datetime.time(1, 0), '01:00'),
....,
(datetime.time(23, 30), '23:30')
]
}}}

This causes the admin form validation to fail with errors like the
following:
''Select a valid choice. midnight is not one of the available choices.''

--

Comment:

Bisected to 6d8979f4c2fbfb9fd5db92acd72489cbbcbdd5d1. It happens in forms
outside the admin also. I think it's a duplicate of #28075 -- the
`<select>` `value` is inadvertently localized just like in that ticket.

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

Reply all
Reply to author
Forward
0 new messages