Opened 13 years ago

Closed 7 years ago

#16575 closed New feature (duplicate)

Allow specifying custom "empty" values for SelectDateWidget

Reported by: foobarrior Owned by: nobody
Component: Forms Version:
Severity: Normal Keywords: SelectDateWidget
Cc: nikitamalyavin@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

It is possible to add some extra configurations to SelectDateWidget constructor.
There was a need for me to use custom "empty" value for each field and custom <select> order, not assigned with settings.
And that's what was done. I'm attouching my own version of forms.extras.widgets module.
It just differs in described above functionality and completely backward-compatible.
Also current v1.3 code was looking dirty for me, so most such places were rewritten. Hope this version will get into repository

Attachments (4)

widgets.py (3.9 KB ) - added by anonymous 13 years ago.
widgets.2.py (4.5 KB ) - added by foobarrior 13 years ago.
the same, only removed pep8 utility's errors and warnings
date_format-select_date_widget.2.diff (8.2 KB ) - added by calebs 12 years ago.
date_format-select_date_widget.diff (8.2 KB ) - added by calebs 12 years ago.

Download all attachments as: .zip

Change History (8)

by anonymous, 13 years ago

Attachment: widgets.py added

by foobarrior, 13 years ago

Attachment: widgets.2.py added

the same, only removed pep8 utility's errors and warnings

comment:2 by Bas Peschier, 13 years ago

Needs documentation: set
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Hi, thanks for the contribution! A bit of cleanup and simple extra features are always welcome.

There are however a couple of issues with the patch:

  • Actually, it's not a patch; could you create a diff from the current trunk?
  • Make sure there are no leftover prints or other debug-statements.
  • Other date widgets fall back to default date formats (see DateInput for example) and it is nice to do the same here.
  • The cleanup makes the code crisper, but it also makes the helper functions on top a bit harder to read, could you document them?
  • The new features should be documented and check whether there are tests for the widget, if they still work and whether or not they need updating.

comment:3 by calebs, 12 years ago

I made foobarrior's changes into a git diff off of the 1.3.1 trunc with a few other changes including:

  • Removal of stray prints and other debug statements.
  • Adding _has_changed back in. (Not certain about what to do with this method)
  • Consolidated the two helper functions into one and added a docstring.
  • Fallback to defaults based on locale

If L10N is False, the changes in this diff make the select widgets order by year, month, day. I'm not sure if this should fall back to US order (d/m/Y) as before, or UTC (Y/m/d).

Tests are still needed and this diff causes a failure in line 92 of FormsExtraTestCase. However, should the test be amended to use UTC or en-US in the event of no L10N?

comment:4 by Kamu, 11 years ago

Version: 1.3

comment:5 by Tim Graham, 7 years ago

Resolution: duplicate
Status: newclosed
Summary: SelectDateWidget should have possibility to have more custom configurationsAllow specifying custom "empty" values for SelectDateWidget

Duplicate of #22684. Use SelectDateWidget.empty_label in Django 1.8+.

Note: See TracTickets for help on using tickets.
Back to Top