Opened 17 years ago

Closed 16 years ago

#3852 closed (duplicate)

[patch] newforms SelectDateWidget fails to display saved values correctly, lacks 'blank' choices

Reported by: Jeff Hilyard <jhilyard@…> Owned by: nobody
Component: Forms Version: dev
Severity: Keywords: SelectDateWidget
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

SelectDateWidget in newforms.extras.widgets displays January 1, 2007 regardless of value entered.
render() assumes the value parameter is a string but it is being passed a datetime.date.
It sets the year, month, day to None before rendering the individual select tags.

This minimally invasive patch works for me but should be rewritten by someone with knowledge of how things are supposed to be - if value is supposed to be a datetime.date then that case should probably be handled in the "try" not the "except" as I've done.

Attachments (3)

newforms_extras_widgets.diff (688 bytes ) - added by Jeff Hilyard <jhilyard@…> 17 years ago.
patch to fix newforms.extras.widgets.SelectDateWidget render() bug
selectdatewidget_dashes.diff (949 bytes ) - added by Jeff Forcier <reg@…> 17 years ago.
Adds initial 'dashes' choices at the top of the dropdowns, as with regular select fields
django-selectdatewidget-datetime.patch (966 bytes ) - added by Simon Law <simon@…> 16 years ago.
Patch that only does coersion when value is a basestring.

Download all attachments as: .zip

Change History (9)

by Jeff Hilyard <jhilyard@…>, 17 years ago

patch to fix newforms.extras.widgets.SelectDateWidget render() bug

comment:1 by Simon G. <dev@…>, 17 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

by Jeff Forcier <reg@…>, 17 years ago

Adds initial 'dashes' choices at the top of the dropdowns, as with regular select fields

comment:2 by Jeff Forcier <reg@…>, 17 years ago

Sigh. Keep thinking the text field on the attachment page is going to be a file description instead of the comment body. This is what I really want to say:

I seem to be having this issue too. I don't have time right now to extensively investigate the issue, but I do want to be a parasite and attach my own diff to this ticket, for a very similar/related issue: if one wanted the fields to be blank, that's not possible at this point in time, as there are no dashes in the choice lists. My diff remedies this.

comment:3 by Jeff Forcier <reg@…>, 17 years ago

Summary: [patch] newforms.extras.widgets SelectDateWidget shows January 1, (first year)[patch] newforms SelectDateWidget fails to display saved values, has no blank options

comment:4 by Jeff Forcier <reg@…>, 17 years ago

Summary: [patch] newforms SelectDateWidget fails to display saved values, has no blank options[patch] newforms SelectDateWidget fails to display saved values correctly, lacks 'blank' choices

Apologies for ticket spam.

comment:5 by Simon Law <simon@…>, 16 years ago

Here is a patch that does the coersion only when value is a basestring.

Otherwise, we just assume it's either a datetime.date or datetime.datetime object. If it isn't, it makes sense to throw an exception.

by Simon Law <simon@…>, 16 years ago

Patch that only does coersion when value is a basestring.

comment:6 by Matt Grayson, 16 years ago

Resolution: duplicate
Status: newclosed

The issue of displaying saved values correctly was fixed by #5917

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