Django

Code

Ticket #8962 (new)

Opened 2 months ago

Last modified 3 weeks ago

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

Reported by: mrmachine Assigned to: nobody
Milestone: post-1.0 Component: Forms
Version: SVN Keywords: datetime format widget
Cc: real.human@mrmachine.net, hv@tbz-pariv.de Triage Stage: Unreviewed
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.

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.

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




Change Properties
Action