Django

Code

Ticket #8962 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

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

Reported by: mrmachine Assigned to: kmtracey
Milestone: 1.1 beta Component: Forms
Version: SVN Keywords: datetime format widget i18n-rf
Cc: real.human@mrmachine.net, hv@tbz-pariv.de, david Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

datetime-formatting-r8983.diff (13.8 kB) - added by mrmachine on 09/08/08 03:40:47.
8962-datetime-format-r8983.diff (14.4 kB) - added by mrmachine on 09/09/08 20:45:30.
Removed redundant line from generic SplitDateTimeField and improved documentation.
8962-datetime-format-r8983.2.diff (14.6 kB) - added by mrmachine on 09/09/08 22:47:09.
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 on 02/16/09 17:56:56.
Updated to r9843.

Change History

09/08/08 03:40:47 changed by mrmachine

  • attachment datetime-formatting-r8983.diff added.

09/08/08 18:32:03 changed by mrmachine

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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.

09/08/08 19:20:42 changed by mrmachine

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

09/09/08 20:45:30 changed by mrmachine

  • attachment 8962-datetime-format-r8983.diff added.

Removed redundant line from generic SplitDateTimeField and improved documentation.

09/09/08 22:47:09 changed by mrmachine

  • attachment 8962-datetime-format-r8983.2.diff added.

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

10/28/08 06:33:54 changed by guettli

  • cc changed from real.human@mrmachine.net to real.human@mrmachine.net, hv@tbz-pariv.de.

02/07/09 05:34:14 changed by david

  • cc changed from real.human@mrmachine.net, hv@tbz-pariv.de to real.human@mrmachine.net, hv@tbz-pariv.de, david.

02/10/09 04:43:12 changed by garcia_marc

  • keywords changed from datetime format widget to datetime format widget i18n-rf.

02/16/09 17:56:56 changed by mrmachine

  • attachment 8962-datetime-format-r9843.diff added.

Updated to r9843.

02/16/09 18:13:54 changed by mrmachine

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

02/21/09 13:17:03 changed by claudep

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

02/25/09 13:51:44 changed by

  • milestone deleted.

Milestone post-1.0 deleted

02/25/09 16:52:17 changed by jacob

  • stage changed from Unreviewed to Accepted.
  • milestone set to 1.1 beta.

03/22/09 09:36:48 changed by kmtracey

  • owner changed from nobody to kmtracey.

03/22/09 11:13:07 changed by kmtracey

  • status changed from new to closed.
  • resolution set to fixed.

(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.


Add/Change #8962 (Make `input_formats` and `format` work consistently across `date`, `datetime`, and `time` fields and widgets.)




Change Properties
Action