2
0
Эх сурвалжийг харах

Fixed #36055 -- Prevented overlap of object-tools buttons and page header in the admin.

antoliny0919 2 сар өмнө
parent
commit
b1324a680a

+ 4 - 1
django/contrib/admin/static/admin/css/base.css

@@ -773,7 +773,6 @@ a.deletelink:focus, a.deletelink:hover {
     padding-left: 0;
     float: right;
     position: relative;
-    margin-top: -48px;
 }
 
 .object-tools li {
@@ -821,6 +820,10 @@ a.deletelink:focus, a.deletelink:hover {
     background-image: url(../img/tooltag-add.svg);
 }
 
+.object-tools:has(a.addlink) {
+    margin-top: -48px;
+}
+
 /* OBJECT HISTORY */
 
 #change-history table {

+ 1 - 1
django/contrib/admin/templates/admin/base.html

@@ -98,9 +98,9 @@
         <div id="content" class="{% block coltype %}colM{% endblock %}">
           {% block pretitle %}{% endblock %}
           {% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}{% endblock %}
+          {% block object-tools %}{% endblock %}
           {% block content_subtitle %}{% if subtitle %}<h2>{{ subtitle }}</h2>{% endif %}{% endblock %}
           {% block content %}
-            {% block object-tools %}{% endblock %}
             {{ content }}
           {% endblock %}
           {% block sidebar %}{% endblock %}

+ 2 - 1
django/contrib/admin/templates/admin/change_form.html

@@ -24,7 +24,6 @@
 {% endblock %}
 {% endif %}
 
-{% block content %}<div id="content-main">
 {% block object-tools %}
 {% if change and not is_popup %}
   <ul class="object-tools">
@@ -34,6 +33,8 @@
   </ul>
 {% endif %}
 {% endblock %}
+
+{% block content %}<div id="content-main">
 <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}{% if form_url %}action="{{ form_url }}" {% endif %}method="post" id="{{ opts.model_name }}_form" novalidate>{% csrf_token %}{% block form_top %}{% endblock %}
 <div>
 {% if is_popup %}<input type="hidden" name="{{ is_popup_var }}" value="1">{% endif %}

+ 8 - 7
django/contrib/admin/templates/admin/change_list.html

@@ -39,15 +39,16 @@
 
 {% block coltype %}{% endblock %}
 
+{% block object-tools %}
+<ul class="object-tools">
+  {% block object-tools-items %}
+    {% change_list_object_tools %}
+  {% endblock %}
+</ul>
+{% endblock %}
+
 {% block content %}
   <div id="content-main">
-    {% block object-tools %}
-        <ul class="object-tools">
-          {% block object-tools-items %}
-            {% change_list_object_tools %}
-          {% endblock %}
-        </ul>
-    {% endblock %}
     {% if cl.formset and cl.formset.errors %}
         <p class="errornote">
         {% blocktranslate count counter=cl.formset.total_error_count %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktranslate %}

+ 19 - 0
tests/admin_views/tests.py

@@ -125,6 +125,7 @@ from .models import (
     Song,
     State,
     Story,
+    Subscriber,
     SuperSecretHideout,
     SuperVillain,
     Telegram,
@@ -6864,6 +6865,24 @@ class SeleniumTests(AdminSeleniumTestCase):
         name_input_value = name_input.get_attribute("value")
         self.assertEqual(name_input_value, "Test section 1")
 
+    @screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"])
+    def test_long_object_str_on_change_view(self):
+        from selenium.webdriver.common.by import By
+
+        self.admin_login(
+            username="super", password="secret", login_url=reverse("admin:index")
+        )
+        s = Subscriber.objects.create(name="a " * 40, email="b " * 80)
+        self.selenium.get(
+            self.live_server_url
+            + reverse("admin:admin_views_subscriber_change", args=(s.pk,))
+        )
+        object_tools = self.selenium.find_elements(
+            By.CSS_SELECTOR, "div#content ul.object-tools li"
+        )
+        self.assertGreater(len(object_tools), 0)
+        self.take_screenshot("not-overwrap")
+
 
 @override_settings(ROOT_URLCONF="admin_views.urls")
 class ReadonlyTest(AdminFieldExtractionMixin, TestCase):