From caf80cb41f13e84803a94928282cae75333bbdfc Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 9 Jun 2023 21:37:23 +0200 Subject: [PATCH] Fixed #34645 -- Restored alignment for admin date/time timezone warnings. Regression in 96a598356a9ea8c2c05b22cadc12e256a3b295fd. --- django/contrib/admin/static/admin/css/forms.css | 4 +++- django/contrib/admin/static/admin/css/rtl.css | 4 +++- .../admin/templates/admin/widgets/date.html | 3 +++ .../admin/templates/admin/widgets/time.html | 3 +++ django/contrib/admin/widgets.py | 14 +++++++++++--- docs/releases/4.2.3.txt | 3 ++- tests/admin_widgets/tests.py | 12 ++++++++---- 7 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 django/contrib/admin/templates/admin/widgets/date.html create mode 100644 django/contrib/admin/templates/admin/widgets/time.html diff --git a/django/contrib/admin/static/admin/css/forms.css b/django/contrib/admin/static/admin/css/forms.css index 52f956e2cf..e45abe1c07 100644 --- a/django/contrib/admin/static/admin/css/forms.css +++ b/django/contrib/admin/static/admin/css/forms.css @@ -130,7 +130,9 @@ form .aligned div.help { padding-left: 10px; } -form .aligned p.datetime div.help.timezonewarning { +form .aligned p.date div.help.timezonewarning, +form .aligned p.datetime div.help.timezonewarning, +form .aligned p.time div.help.timezonewarning { margin-left: 0; padding-left: 0; font-weight: normal; diff --git a/django/contrib/admin/static/admin/css/rtl.css b/django/contrib/admin/static/admin/css/rtl.css index dcc12d745b..ec5a2256ec 100644 --- a/django/contrib/admin/static/admin/css/rtl.css +++ b/django/contrib/admin/static/admin/css/rtl.css @@ -147,7 +147,9 @@ form .aligned div.help { form div.help ul, form .aligned .checkbox-row + .help, -form .aligned p.datetime div.help.timezonewarning { +form .aligned p.date div.help.timezonewarning, +form .aligned p.datetime div.help.timezonewarning, +form .aligned p.time div.help.timezonewarning { margin-right: 0; padding-right: 0; } diff --git a/django/contrib/admin/templates/admin/widgets/date.html b/django/contrib/admin/templates/admin/widgets/date.html new file mode 100644 index 0000000000..acd5d5fc57 --- /dev/null +++ b/django/contrib/admin/templates/admin/widgets/date.html @@ -0,0 +1,3 @@ +

+ {% include "django/forms/widgets/date.html" %} +

diff --git a/django/contrib/admin/templates/admin/widgets/time.html b/django/contrib/admin/templates/admin/widgets/time.html new file mode 100644 index 0000000000..e4eaca61f2 --- /dev/null +++ b/django/contrib/admin/templates/admin/widgets/time.html @@ -0,0 +1,3 @@ +

+ {% include "django/forms/widgets/time.html" %} +

diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index c7d5db209e..5e3416bc28 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -48,7 +48,7 @@ class FilteredSelectMultiple(forms.SelectMultiple): return context -class AdminDateWidget(forms.DateInput): +class BaseAdminDateWidget(forms.DateInput): class Media: js = [ "admin/js/calendar.js", @@ -60,7 +60,11 @@ class AdminDateWidget(forms.DateInput): super().__init__(attrs=attrs, format=format) -class AdminTimeWidget(forms.TimeInput): +class AdminDateWidget(BaseAdminDateWidget): + template_name = "admin/widgets/date.html" + + +class BaseAdminTimeWidget(forms.TimeInput): class Media: js = [ "admin/js/calendar.js", @@ -72,6 +76,10 @@ class AdminTimeWidget(forms.TimeInput): super().__init__(attrs=attrs, format=format) +class AdminTimeWidget(BaseAdminTimeWidget): + template_name = "admin/widgets/time.html" + + class AdminSplitDateTime(forms.SplitDateTimeWidget): """ A SplitDateTime Widget that has some admin-specific styling. @@ -80,7 +88,7 @@ class AdminSplitDateTime(forms.SplitDateTimeWidget): template_name = "admin/widgets/split_datetime.html" def __init__(self, attrs=None): - widgets = [AdminDateWidget, AdminTimeWidget] + widgets = [BaseAdminDateWidget, BaseAdminTimeWidget] # Note that we're calling MultiWidget, not SplitDateTimeWidget, because # we want to define widgets. forms.MultiWidget.__init__(self, widgets, attrs) diff --git a/docs/releases/4.2.3.txt b/docs/releases/4.2.3.txt index 4279175df9..66d6611b36 100644 --- a/docs/releases/4.2.3.txt +++ b/docs/releases/4.2.3.txt @@ -9,4 +9,5 @@ Django 4.2.3 fixes several bugs in 4.2.2. Bugfixes ======== -* ... +* Fixed a regression in Django 4.2 that caused incorrect alignment of timezone + warnings for ``DateField`` and ``TimeField`` in the admin (:ticket:`34645`). diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index 2977b64596..0a65ef06f0 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -398,15 +398,17 @@ class AdminDateWidgetTest(SimpleTestCase): w = widgets.AdminDateWidget() self.assertHTMLEqual( w.render("test", datetime(2007, 12, 1, 9, 30)), + '

' '', + 'size="10">

', ) # pass attrs to widget w = widgets.AdminDateWidget(attrs={"size": 20, "class": "myDateField"}) self.assertHTMLEqual( w.render("test", datetime(2007, 12, 1, 9, 30)), + '

' '', + 'size="20">

', ) @@ -415,15 +417,17 @@ class AdminTimeWidgetTest(SimpleTestCase): w = widgets.AdminTimeWidget() self.assertHTMLEqual( w.render("test", datetime(2007, 12, 1, 9, 30)), + '

' '', + 'size="8">

', ) # pass attrs to widget w = widgets.AdminTimeWidget(attrs={"size": 20, "class": "myTimeField"}) self.assertHTMLEqual( w.render("test", datetime(2007, 12, 1, 9, 30)), + '

' '', + 'size="20">

', )