Opened 14 years ago
Closed 14 years ago
#17165 closed Bug (duplicate)
SelectDateWidget does not work correctly with has_changed()
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Forms | Version: | dev |
| Severity: | Normal | Keywords: | SelectDateWidget changed has_changed changed_data |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description
See http://groups.google.com/group/django-users/browse_thread/thread/45c2a4b6a2f0ba67
Attachments (2)
Change History (16)
comment:1 by , 14 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
by , 14 years ago
| Attachment: | 1.3.X.diff added |
|---|
comment:2 by , 14 years ago
| Has patch: | set |
|---|---|
| Owner: | removed |
| Status: | assigned → new |
| Version: | 1.3 → SVN |
comment:3 by , 14 years ago
The problem is that Widget._has_changed compares a localized string representation of the date to a datetime.date object. The patch addresses the issue by overriding _has_changed in SelectDateWidget and passing the data value as a datetime.date object to Widget._has_changed.
comment:4 by , 14 years ago
| Owner: | set to |
|---|
comment:5 by , 14 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
Thanks for the report. The patch looks good, I'm just about to push it. You'll note that I've just fleshed out the tests a bit to be sure it works if the field's show_hidden_initial is True. Cheers!
comment:7 by , 14 years ago
rene_f, my apologies for not mentioning you in the commit message. Thanks again for your contribution.
comment:8 by , 14 years ago
julien, no problem. Thanks for your quick reaction.
Will the fix also be applied to the 1.3.X branch? It might be nice to have it included in a possible 1.3.2 release. I attached a separate diff for 1.3.X (avoids datetime.strptime for Python 2.4 compatibility).
comment:9 by , 14 years ago
The policy is to only commit severe bug fixes to older branches; see: https://docs.djangoproject.com/en/dev/internals/release-process/#supported-versions
I don't think the severity of this bug qualifies, so you'll have to wait till the next release which should hopefully happen soon.
comment:10 by , 14 years ago
| Patch needs improvement: | set |
|---|
doesn't work for me
when SelectDateWidget is empty and i check "if 'fieldname' in self.changed_data" for some other field
django fires TypeError "must be string, not None" in django/forms/extras/widgets.py "data = datetime_safe.datetime.strptime(data, input_format).date()"
so, you should make something like
if data is not None:
data = datetime_safe.datetime.strptime(data, input_format).date()
else:
data = None
comment:11 by , 14 years ago
it would be better
try:
input_format = get_format('DATE_INPUT_FORMATS')[0]
data = datetime.datetime.strptime(data, input_format).date()
except (TypeError, ValueError):
pass
comment:12 by , 14 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
comment:14 by , 14 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | reopened → closed |
Patch against the 1.3.X branch.