Code

Opened 6 years ago

Closed 5 years ago

Last modified 3 years ago

#8962 closed Uncategorized (fixed)

Make `input_formats` and `format` work consistently across `date`, `datetime`, and `time` fields and widgets.

Reported by: mrmachine Owned by: kmtracey
Component: Forms Version: master
Severity: Normal Keywords: datetime format widget i18n-rf
Cc: real.human@…, david Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, there are some inconsistencies in what form fields and widgets we have available for date, datetime, and time data. There are also inconsistencies in how the format argument applies to the widgets, and the input_formats applies to the fields.

  1. DateTimeInput and TimeInput exist, DateInput doesn't.
  2. DateTimeInput accepts format, but TimeInput doesn't.
  3. SplitDateTimeField doesn't use SplitDateTimeWidget by default.
  4. SplitDateTimeField doesn't allow the user to specify input_formats.
  5. SplitDateTimeWidget uses two TextInput widgets, instead of TimeInput and the missing DateInput (and thus doesn't allow the user to specify formats).
  6. django.contrib.localflavor.generic.forms is missing SplitDateTimeField.
  7. The documentation is sparse on detail for SplitDateTimeField, DateTimeInput and TimeInput.

This patch:

  1. Adds DateInput, which accepts format, and is used for DateField by default.
  2. Adds format as an argument to TimeInput.
  3. Uses SplitDateTimeWidget for SplitDateTimeField by default.
  4. Adds input_date_formats and input_time_formats as arguments to SplitDateTimeField.
  5. Uses DateInput and TimeInput for SplitDateTimeWidget, and passes through date_format and time_format through to DateInput and TimeInput as format, respectively.
  6. Adds SplitDateTimeField to django.contrib.localflavor.generic.forms.
  7. Adds documentation for all of these changes.
  8. Adds tests for all of these changes.

Attachments (4)

datetime-formatting-r8983.diff (13.8 KB) - added by mrmachine 6 years ago.
8962-datetime-format-r8983.diff (14.4 KB) - added by mrmachine 6 years ago.
Removed redundant line from generic SplitDateTimeField and improved documentation.
8962-datetime-format-r8983.2.diff (14.6 KB) - added by mrmachine 6 years ago.
Set default date/time format for SplitDateTimeWidget as class attribute, so it can be overridden in a subclass.
8962-datetime-format-r9843.diff (14.4 KB) - added by mrmachine 5 years ago.
Updated to r9843.

Download all attachments as: .zip

Change History (17)

Changed 6 years ago by mrmachine

comment:1 Changed 6 years ago by mrmachine

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Another option would be to use settings.*_FORMAT as the default if no format is provided. This would make it easy to configure a consistent date format across a whole site, including forms.

comment:2 Changed 6 years ago by mrmachine

On second thoughts, it looks like settings.*_FORMAT uses a slightly different format and supports some options not compatible with strftime, etc.

Changed 6 years ago by mrmachine

Removed redundant line from generic SplitDateTimeField and improved documentation.

Changed 6 years ago by mrmachine

Set default date/time format for SplitDateTimeWidget as class attribute, so it can be overridden in a subclass.

comment:3 Changed 6 years ago by guettli

  • Cc hv@… added

comment:4 Changed 5 years ago by david

  • Cc david added

comment:5 Changed 5 years ago by garcia_marc

  • Keywords i18n-rf added

Changed 5 years ago by mrmachine

Updated to r9843.

comment:6 Changed 5 years ago by mrmachine

Looks like SplitDateTimeField does use SplitDateTimeWidget by default in r9843, so I've updated the patch to work on trunk again.

comment:7 Changed 5 years ago by claudep

+1 for this patch. Was bitten today with the missing format of the TimeInput widget...

comment:8 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:9 Changed 5 years ago by jacob

  • milestone set to 1.1 beta
  • Triage Stage changed from Unreviewed to Accepted

comment:10 Changed 5 years ago by kmtracey

  • Owner changed from nobody to kmtracey

comment:11 Changed 5 years ago by kmtracey

  • Resolution set to fixed
  • Status changed from new to closed

(In [10115]) Fixed #8962 -- Consistently support format and input_format in the various (individual, combined, split) date and time form fields and widgets.

Many thanks to Tai Lee for doing all the work here.

comment:12 Changed 3 years ago by jacob

  • milestone 1.1 beta deleted

Milestone 1.1 beta deleted

comment:13 Changed 3 years ago by guettli

  • Cc hv@… removed
  • Easy pickings unset
  • Severity set to Normal
  • Type set to Uncategorized
  • UI/UX unset

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.