Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#8962 closed Uncategorized (fixed)

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

Reported by: Tai Lee Owned by: Karen Tracey
Component: Forms Version: master
Severity: Normal Keywords: datetime format widget i18n-rf
Cc: real.human@…, David Larlet 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 Tai Lee 8 years ago.
8962-datetime-format-r8983.diff (14.4 KB) - added by Tai Lee 8 years ago.
Removed redundant line from generic SplitDateTimeField and improved documentation.
8962-datetime-format-r8983.2.diff (14.6 KB) - added by Tai Lee 8 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 Tai Lee 8 years ago.
Updated to r9843.

Download all attachments as: .zip

Change History (17)

Changed 8 years ago by Tai Lee

comment:1 Changed 8 years ago by Tai Lee

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 8 years ago by Tai Lee

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

Changed 8 years ago by Tai Lee

Removed redundant line from generic SplitDateTimeField and improved documentation.

Changed 8 years ago by Tai Lee

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

comment:3 Changed 8 years ago by Thomas Güttler

Cc: hv@… added

comment:4 Changed 8 years ago by David Larlet

Cc: David Larlet added

comment:5 Changed 8 years ago by Marc Garcia

Keywords: i18n-rf added

Changed 8 years ago by Tai Lee

Updated to r9843.

comment:6 Changed 8 years ago by Tai Lee

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

comment:7 Changed 8 years ago by Claude Paroz

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

comment:8 Changed 8 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:9 Changed 8 years ago by Jacob

milestone: 1.1 beta
Triage Stage: UnreviewedAccepted

comment:10 Changed 8 years ago by Karen Tracey

Owner: changed from nobody to Karen Tracey

comment:11 Changed 8 years ago by Karen Tracey

Resolution: fixed
Status: newclosed

(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 5 years ago by Jacob

milestone: 1.1 beta

Milestone 1.1 beta deleted

comment:13 Changed 5 years ago by Thomas Güttler

Cc: hv@… removed
Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset
Note: See TracTickets for help on using tickets.
Back to Top