diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index afc7cfc5bd..2c060a05ac 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -69,6 +69,7 @@ FORMFIELD_FOR_DBFIELD_DEFAULTS = { models.CharField: {'widget': widgets.AdminTextInputWidget}, models.ImageField: {'widget': widgets.AdminFileWidget}, models.FileField: {'widget': widgets.AdminFileWidget}, + models.EmailField: {'widget': widgets.AdminEmailInputWidget}, } csrf_protect_m = method_decorator(csrf_protect) diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 4b79401dbc..eeae846320 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -285,7 +285,14 @@ class AdminTextInputWidget(forms.TextInput): final_attrs.update(attrs) super(AdminTextInputWidget, self).__init__(attrs=final_attrs) -class AdminURLFieldWidget(forms.TextInput): +class AdminEmailInputWidget(forms.EmailInput): + def __init__(self, attrs=None): + final_attrs = {'class': 'vTextField'} + if attrs is not None: + final_attrs.update(attrs) + super(AdminEmailInputWidget, self).__init__(attrs=final_attrs) + +class AdminURLFieldWidget(forms.URLInput): def __init__(self, attrs=None): final_attrs = {'class': 'vURLField'} if attrs is not None: diff --git a/tests/admin_widgets/models.py b/tests/admin_widgets/models.py index ae19d58cc4..2c9bc5b32a 100644 --- a/tests/admin_widgets/models.py +++ b/tests/admin_widgets/models.py @@ -13,6 +13,7 @@ class Member(models.Model): name = models.CharField(max_length=100) birthdate = models.DateTimeField(blank=True, null=True) gender = models.CharField(max_length=1, blank=True, choices=[('M','Male'), ('F', 'Female')]) + email = models.EmailField(blank=True) def __str__(self): return self.name diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index 870aa6d455..e8d4e5276b 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -83,6 +83,9 @@ class AdminFormfieldForDBFieldTests(TestCase): def testCharField(self): self.assertFormfield(models.Member, 'name', widgets.AdminTextInputWidget) + def testEmailField(self): + self.assertFormfield(models.Member, 'email', widgets.AdminEmailInputWidget) + def testFileField(self): self.assertFormfield(models.Album, 'cover_art', widgets.AdminFileWidget) @@ -300,29 +303,29 @@ class AdminURLWidgetTest(DjangoTestCase): w = widgets.AdminURLFieldWidget() self.assertHTMLEqual( conditional_escape(w.render('test', '')), - '' + '' ) self.assertHTMLEqual( conditional_escape(w.render('test', 'http://example.com')), - '
Currently:http://example.com
Change:
Currently:http://example.com
Change:
Currently:http://example-äüö.com
Change:
Currently:http://example-äüö.com
Change:
Currently:http://example.com/<sometag>some text</sometag>
Change:
Currently:http://example.com/<sometag>some text</sometag>
Change:
Currently:http://example-äüö.com/<sometag>some text</sometag>
Change:
Currently:http://example-äüö.com/<sometag>some text</sometag>
Change: