Code

Opened 3 years ago

Last modified 7 months ago

#16575 new New feature

SelectDateWidget should have possibility to have more custom configurations

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 3 years ago.
widgets.2.py (4.5 KB) - added by foobarrior 3 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 2 years ago.
date_format-select_date_widget.diff (8.2 KB) - added by calebs 2 years ago.

Download all attachments as: .zip

Change History (9)

Changed 3 years ago by anonymous

comment:1 Changed 3 years ago by foobarrior

  • Easy pickings set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Changed 3 years ago by foobarrior

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

comment:2 Changed 3 years ago by bpeschier

  • Needs documentation set
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 2 years ago by calebs

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?

Changed 2 years ago by calebs

Changed 2 years ago by calebs

comment:4 Changed 10 months ago by Kamu

  • Version 1.3 deleted

comment:5 Changed 7 months ago by timo

  • Easy pickings unset

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


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

 
Note: See TracTickets for help on using tickets.