New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #28075 -- Prevented ChoiceWidget from localizing option values. #8385
Conversation
django/forms/widgets.py
Outdated
@@ -594,7 +594,7 @@ def create_option(self, name, value, label, selected, index, subindex=None, attr | |||
option_attrs['id'] = self.id_for_label(option_attrs['id'], index) | |||
return { | |||
'name': name, | |||
'value': value, | |||
'value': force_text(value), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On master, I'd rather see a simple str()
. Of course, the backport for 1.11 should keep force_text
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I chose force_text()
here to match the earlier use in ChoiceWidget
. Do you think it would be best to change this other usage in this PR or in a separate commit & PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a ticket for auditing existing force_text()
usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm uncertain about the need to test all subclasses of ChoiceWidget
but this might be considered later with a mixin so that these don't have to repeated several times.
docs/releases/1.11.1.txt
Outdated
@@ -45,3 +45,5 @@ Bugfixes | |||
|
|||
* Fixed exception reraising in ORM query execution when ``cursor.execute()`` | |||
fails and the subsequent ``cursor.close()`` also fails (:ticket:`28091`). | |||
|
|||
* Fixed ``ChoiceWidget`` to not localize option values (:ticket:`28075`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ChoiceWidget isn't a public API, so perhaps it would be better to say something like "Fixed a regression where A, B, C, and D localized option values" where the letters are the actual classes.
@@ -173,3 +176,29 @@ class TestForm(forms.Form): | |||
bound_field = TestForm()['f'] | |||
self.assertEqual(bound_field.field.widget.id_for_label('id'), '') | |||
self.assertEqual(bound_field.label_tag(), '<label>F:</label>') | |||
|
|||
@override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd order the test with the other check_html()
tests (above test_use_required_attribute
).
@@ -311,3 +313,29 @@ def test_renders_required_when_possible_to_select_empty_field_none(self): | |||
def test_doesnt_render_required_when_no_choices_are_available(self): | |||
widget = self.widget(choices=[]) | |||
self.assertIs(widget.use_required_attribute(initial=None), False) | |||
|
|||
@override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(order as suggested above)
Just to clarify, the reason I wrote the tests for all subclasses is that my first fix only fixed the |
Thanks for the reviews. I have made the suggested changes. |
https://code.djangoproject.com/ticket/28075