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 #30758 -- Made RangeFields use multiple hidden inputs for initial data. #11755
Conversation
d22ea18
to
68d78a7
Compare
a6e94a5
to
9565b91
Compare
@nasirhjafri Thanks for this PR, however I don't think that it's a proper approach. IMO we should rather fix passing initial data for range fields. Currently we use <input type="hidden"
name="initial-range_field"
value="[datetime.datetime(2019, 9, 13, 9, 53, 31, 531040), None]"
... IMO we should change <input type="hidden" name="initial-range_field_0" value="2019-09-13 09:53:31" id="initial-id_range_field_0">
<input type="hidden" name="initial-range_field_1" id="initial-id_range_field_1"> e.g. diff --git a/django/contrib/postgres/forms/ranges.py b/django/contrib/postgres/forms/ranges.py
index 47a16a1bbd..2d55cbce57 100644
--- a/django/contrib/postgres/forms/ranges.py
+++ b/django/contrib/postgres/forms/ranges.py
@@ -2,7 +2,7 @@ from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
from django import forms
from django.core import exceptions
-from django.forms.widgets import MultiWidget
+from django.forms.widgets import MultiWidget, MultipleHiddenInput
from django.utils.translation import gettext_lazy as _
__all__ = [
@@ -16,6 +16,7 @@ class BaseRangeField(forms.MultiValueField):
'invalid': _('Enter two valid values.'),
'bound_ordering': _('The start of the range must not exceed the end of the range.'),
}
+ hidden_widget = MultipleHiddenInput
def __init__(self, **kwargs):
if 'widget' not in kwargs: |
@felixxm That's how it was being done in 1.11.x https://github.com/django/django/blob/stable/1.11.x/django/forms/fields.py#L398 I'll try the solution you provided, thanks. |
@nasirhjafri Yes but it's clunky, IMO. |
@felixxm Any ideas on how test cases should look like? This solution works but I can't think of a test case. |
9d34863
to
2a7b054
Compare
We should test the way how |
@felixxm I've pushed the tests, but they are not running on circle ci. Can you please retrigger the tests on PR? |
46a86f7
to
4a0bbb1
Compare
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.
@nasirhjafri Please move tests to the postgres_tests.test_ranges.TestWidget
. Moreover tests that are not related with this patch should be in a separate commit, i.e. first commit with extra tests and second (Fixed #30758 -- Made RangeFields use multiple hidden inputs for initial data.
) with fix and tests that falling without it.
tests/postgres_tests/test_widgets.py
Outdated
|
||
def test_date_range_has_changed_empty_initial(self): | ||
self.assertTrue(self.date_field.has_changed(['2010-01-01', ''], | ||
['2010-01-01', '2020-12-12'])) |
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.
Please use hanging indentation per our coding style (in all tests).
3b7febf
to
920afe9
Compare
@felixxm This one is failing without the fix and working with the fix. django/tests/postgres_tests/test_ranges.py Lines 802 to 813 in 3b7febf
I've created two separate commits. Please review. |
920afe9
to
b281519
Compare
@nasirhjafri Thanks! I simplified tests, moved them between test classes and added some extra tests. I also notice that with |
b281519
to
db8174e
Compare
@felixxm looks good to me, working fine with the new |
db8174e
to
24fff56
Compare
Great, I squashed commits and rebased from master. |
24fff56
to
094b8c8
Compare
Hi! Thanks a lot for fixing this! @felixxm do you know if this patch will be able to make it into 2.2.6? |
@yeppus No, it doesn't qualify for a backport to 2.2.x, but it's included in Django 3.0. |
@felixxm thanks for letting me know,,, we need the LTS so I guess we need to rework the code around this bug in that case. |
https://code.djangoproject.com/ticket/30758