Opened 9 years ago

Closed 5 years ago

#5714 closed Cleanup/optimization (fixed)

Date/Time fields' clean methods need strip()

Reported by: Simon Litchfield <simon@…> Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Minor, but trailing/leading spaces throw date/time fields.

Believe it or not this has come up on two separate occasions now, so I thought I'd submit the patch.

Attachments (3)

newforms-datetime-strip.diff (1.2 KB) - added by Simon Litchfield 9 years ago.
fix5714.patch (4.3 KB) - added by Matthias Kestenholz 6 years ago.
5714.diff (9.2 KB) - added by Chris Beaven 6 years ago.

Download all attachments as: .zip

Change History (11)

Changed 9 years ago by Simon Litchfield

comment:1 Changed 9 years ago by Chris Beaven

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedDesign decision needed

I'll push to a design decision, in the past these issues have been brushed off with a "create your own subclass" but I like the idea.

In fact, I'd be tempted to put a clean_strip attribute on Field (defaulting to False for most, overridden to True default for date/time fields) since this is a common request. But that's just me dreaming :)

comment:2 Changed 6 years ago by Malcolm Tredinnick

Resolution: duplicate
Status: newclosed
Triage Stage: Design decision neededAccepted

Marking as a dupe of #6362.

comment:3 Changed 6 years ago by Malcolm Tredinnick

Resolution: duplicate
Status: closedreopened

comment:4 Changed 6 years ago by Malcolm Tredinnick

The other ticket isn't a real-dupe. This particular data type is a no-brainer. We should strip the spaces before strptime'ing. Accepted.

comment:5 Changed 6 years ago by Chris Beaven

Needs tests: set

comment:6 Changed 6 years ago by Matthias Kestenholz

Needs tests: unset

Changed 6 years ago by Matthias Kestenholz

Attachment: fix5714.patch added

Changed 6 years ago by Chris Beaven

Attachment: 5714.diff added

comment:7 Changed 6 years ago by Gabriel Hurley

Severity: Normal
Type: Cleanup/optimization

comment:8 Changed 5 years ago by Jannis Leidel

Resolution: fixed
Status: reopenedclosed

In [16137]:

Fixed #5714 -- Strip whitespaces around date and time form field values before converting it to a native type. Thanks to SmileyChris for the initial patch.

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