mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-04-12 19:01:04 +00:00
Don't copy input_type attribute from original widget when the floppyform widget has a much more appropriate HTML5 type.
This commit is contained in:
parent
494b999922
commit
d10838c2ed
3 changed files with 29 additions and 9 deletions
|
|
@ -109,17 +109,14 @@ _django_to_floppyforms_widget = {
|
|||
django.forms.widgets.DateInput:
|
||||
_create_widget(
|
||||
floppyforms.widgets.DateInput,
|
||||
('input_type',),
|
||||
init_arguments=('format',)),
|
||||
django.forms.widgets.DateTimeInput:
|
||||
_create_widget(
|
||||
floppyforms.widgets.DateTimeInput,
|
||||
('input_type',),
|
||||
init_arguments=('format',)),
|
||||
django.forms.widgets.TimeInput:
|
||||
_create_widget(
|
||||
floppyforms.widgets.TimeInput,
|
||||
('input_type',),
|
||||
init_arguments=('format',)),
|
||||
django.forms.widgets.CheckboxInput:
|
||||
_create_widget(floppyforms.widgets.CheckboxInput, ('check_test',)),
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ class UserAdminTest(TestCase):
|
|||
self.assertTrue(
|
||||
isinstance(form.fields['username'].widget,
|
||||
floppyforms.TextInput))
|
||||
self.assertTrue(
|
||||
isinstance(form.fields['date_joined'].widget,
|
||||
floppyforms.DateTimeInput))
|
||||
|
||||
request = self.factory.get(
|
||||
reverse('admin2:auth_user_update', args=(self.user.pk,)))
|
||||
|
|
@ -51,3 +54,6 @@ class UserAdminTest(TestCase):
|
|||
self.assertTrue(
|
||||
isinstance(form.fields['username'].widget,
|
||||
floppyforms.TextInput))
|
||||
self.assertTrue(
|
||||
isinstance(form.fields['date_joined'].widget,
|
||||
floppyforms.DateTimeInput))
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class ModelFormFactoryTest(TestCase):
|
|||
|
||||
class GetFloppyformWidgetTest(TestCase):
|
||||
def assertExpectWidget(self, instance, new_class_,
|
||||
equal_attributes=None):
|
||||
equal_attributes=None, new_attributes=None):
|
||||
new_instance = floppify_widget(instance)
|
||||
self.assertEqual(new_instance.__class__, new_class_)
|
||||
if equal_attributes:
|
||||
|
|
@ -33,6 +33,16 @@ class GetFloppyformWidgetTest(TestCase):
|
|||
self.assertEqual(old_attr, new_attr,
|
||||
'Original widget\'s attribute was not copied: %r != %r' %
|
||||
(old_attr, new_attr))
|
||||
if new_attributes:
|
||||
for attribute, value in new_attributes.items():
|
||||
self.assertTrue(
|
||||
hasattr(new_instance, attribute),
|
||||
'Cannot check new attribute %r, not available on '
|
||||
'generated widget %r' % (attribute, new_instance))
|
||||
new_attr = getattr(new_instance, attribute)
|
||||
self.assertEqual(new_attr, value,
|
||||
'Generated widget\'s attribute is not as expected: '
|
||||
'%r != %r' % (new_attr, value))
|
||||
|
||||
def test_created_widget_doesnt_leak_attributes_into_original_widget(self):
|
||||
widget = forms.TextInput()
|
||||
|
|
@ -70,12 +80,16 @@ class GetFloppyformWidgetTest(TestCase):
|
|||
def test_textinput_widget(self):
|
||||
self.assertExpectWidget(
|
||||
forms.widgets.TextInput(),
|
||||
floppyforms.widgets.TextInput)
|
||||
floppyforms.widgets.TextInput,
|
||||
['input_type'],
|
||||
{'input_type': 'text'})
|
||||
|
||||
def test_passwordinput_widget(self):
|
||||
self.assertExpectWidget(
|
||||
forms.widgets.PasswordInput(),
|
||||
floppyforms.widgets.PasswordInput)
|
||||
floppyforms.widgets.PasswordInput,
|
||||
['input_type'],
|
||||
{'input_type': 'password'})
|
||||
|
||||
def test_hiddeninput_widget(self):
|
||||
self.assertExpectWidget(
|
||||
|
|
@ -146,7 +160,8 @@ class GetFloppyformWidgetTest(TestCase):
|
|||
self.assertExpectWidget(
|
||||
widget,
|
||||
floppyforms.widgets.DateInput,
|
||||
['format'])
|
||||
['format'],
|
||||
{'input_type': 'date'})
|
||||
|
||||
def test_datetimeinput_widget(self):
|
||||
self.assertExpectWidget(
|
||||
|
|
@ -157,7 +172,8 @@ class GetFloppyformWidgetTest(TestCase):
|
|||
self.assertExpectWidget(
|
||||
widget,
|
||||
floppyforms.widgets.DateTimeInput,
|
||||
['format'])
|
||||
['format'],
|
||||
{'input_type': 'datetime'})
|
||||
|
||||
def test_timeinput_widget(self):
|
||||
self.assertExpectWidget(
|
||||
|
|
@ -168,7 +184,8 @@ class GetFloppyformWidgetTest(TestCase):
|
|||
self.assertExpectWidget(
|
||||
widget,
|
||||
floppyforms.widgets.TimeInput,
|
||||
['format'])
|
||||
['format'],
|
||||
{'input_type': 'time'})
|
||||
|
||||
def test_checkboxinput_widget(self):
|
||||
self.assertExpectWidget(
|
||||
|
|
|
|||
Loading…
Reference in a new issue