{{{
POST_DAYS_CHOICE = (
(7, '1 week'),
(14, '2 weeks'),
(30, '1 month'),
(60, '2 months'),
(90, '3 months'),
)
def days_to_till_date(val):
print val
try:
till_date = date.today() + timedelta(int(val))
except ValueError:
till_date = date.today() + timedelta(30)
return till_date
class PostForm(forms.ModelForm):
till_date = forms.TypedChoiceField(label='Period',
choices=POST_DAYS_CHOICE, coerce=days_to_till_date, required=True,
initial=30)
}}}
This is was removed from TypedChoiceField class:
{{{
def validate(self, value):
pass
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21397>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* severity: Normal => Release blocker
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
This was changed in [9883551d50e].
Interesting use case, which is currently not tested in Django. Having the
coerced value not in choices is a bit of a corner case (and not clearly
documented), but I admit this might be considered as a regression.
I'll see if I can come up with a fix which is not too invasive...
In any case, the documentation will have to be clarified on this point.
--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:1>
* has_patch: 0 => 1
Comment:
Attached a patch with a possible fix. Test suite passes with SQLite. I'll
let other core developers judge if this warrants to be added in a stable
release.
--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:2>
Comment (by claudep):
Thinking a bit more about this, I think that it's too risky to push my
patch in the 1.6 stable branch. We can document the regression in the 1.6
release notes, but you will probably have to create a custom field to
workaround the issue until the next release.
Please, next time try to test your project with beta or at least RC
releases, so we can catch those issues before the official release.
--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:3>
Comment (by Elec):
Hi, no problem. I just test my project with 1.6 release. I create custom
field.
--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:4>
* owner: nobody => claudep
* status: new => assigned
Comment:
Assigned to me, but would love to receive another core dev opinion.
--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:5>
* severity: Release blocker => Normal
* stage: Accepted => Ready for checkin
Comment:
While you did a great job at putting a non-invasive patch together I'm not
sure we should commit to backport it.
First because it doesn't meet any of the policy criterias and second
because it concerns an undocumented and corner use case.
IMHO the small risk of introducing another regression, there's a small one
given the original `to_python` override, is not worth the backport.
On the other hand -- apart the missing a release note -- the patch looks
RFC for master.
--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:6>
Comment (by claudep):
Proposal for a 1.6 release note addition (misc backwards
incompatibilities):
{{{
* Due to a change in the form validation workflow,
:class:`~django.forms.TypedChoiceField` ``coerce`` method should always
return a value present in the ``choices`` field attribute. That
limitation
should be lift again in Django 1.7.
}}}
Does it look sane?
--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:7>
Comment (by charettes):
LGTM
--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:8>
Comment (by Claude Paroz <claude@…>):
In [changeset:"4a00f132e0cc5246f7e7bd04b6d84a9d9ea4a0c1"]:
{{{
#!CommitTicketReference repository=""
revision="4a00f132e0cc5246f7e7bd04b6d84a9d9ea4a0c1"
Added release note for TypedChoiceField coerce limitation
Thanks Elec for the report and Simon Charette for the review.
Refs #21397.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:9>
Comment (by Claude Paroz <claude@…>):
In [changeset:"9f59149cfe97b3b0026bbc4ff1d2121e4cf04d0e"]:
{{{
#!CommitTicketReference repository=""
revision="9f59149cfe97b3b0026bbc4ff1d2121e4cf04d0e"
[1.6.x] Added release note for TypedChoiceField coerce limitation
Thanks Elec for the report and Simon Charette for the review.
Refs #21397.
Backport of 4a00f132e0 from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:10>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"a0f3eeccf3d5a90f9914bfe20b15df05673ea59d"]:
{{{
#!CommitTicketReference repository=""
revision="a0f3eeccf3d5a90f9914bfe20b15df05673ea59d"
Fixed #21397 -- Re-added flexibility to TypedChoiceField coercion
Thanks Elec for the report and Simon Charette for the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21397#comment:11>