1
0
mirror of https://github.com/django/django.git synced 2025-03-06 15:32:33 +00:00

[5.2.x] Fixed #36069 -- Fixed the delete button position in TabularInlines.

Backport of 1330cb570519170bb4397b4fb02c7e3e0657855a from main.
This commit is contained in:
antoliny0919 2025-01-07 20:22:30 +09:00 committed by Sarah Boyce
parent d03102a5a8
commit 209d0f6143
2 changed files with 34 additions and 4 deletions

View File

@ -23,7 +23,7 @@
{% if field.help_text %}<img src="{% static "admin/img/icon-unknown.svg" %}" class="help help-tooltip" width="10" height="10" alt="({{ field.help_text|striptags }})" title="{{ field.help_text|striptags }}">{% endif %} {% if field.help_text %}<img src="{% static "admin/img/icon-unknown.svg" %}" class="help help-tooltip" width="10" height="10" alt="({{ field.help_text|striptags }})" title="{{ field.help_text|striptags }}">{% endif %}
</th> </th>
{% endfor %} {% endfor %}
{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}<th>{% translate "Delete?" %}</th>{% endif %} <th>{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}{% translate "Delete?" %}{% endif %}</th>
</tr></thead> </tr></thead>
<tbody> <tbody>
@ -58,9 +58,7 @@
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %} <td class="delete">{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission and inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
<td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
{% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -19,6 +19,7 @@ from .models import (
Child, Child,
ChildModel1, ChildModel1,
ChildModel2, ChildModel2,
ExtraTerrestrial,
Fashionista, Fashionista,
FootNote, FootNote,
Holder, Holder,
@ -2493,3 +2494,34 @@ class SeleniumTests(AdminSeleniumTestCase):
tabular_inline.find_elements(By.CSS_SELECTOR, ".collapse"), tabular_inline.find_elements(By.CSS_SELECTOR, ".collapse"),
[], [],
) )
@screenshot_cases(["desktop_size", "mobile_size", "rtl", "dark", "high_contrast"])
def test_tabular_inline_delete_layout(self):
from selenium.webdriver.common.by import By
user = User.objects.create_user("testing", password="password", is_staff=True)
et_permission = Permission.objects.filter(
content_type=ContentType.objects.get_for_model(ExtraTerrestrial),
)
s_permission = Permission.objects.filter(
codename__in=["view_sighting", "add_sighting"],
content_type=ContentType.objects.get_for_model(Sighting),
)
user.user_permissions.add(*et_permission, *s_permission)
self.admin_login(username="testing", password="password")
cf = ExtraTerrestrial.objects.create(name="test")
url = reverse("admin:admin_inlines_extraterrestrial_change", args=(cf.pk,))
self.selenium.get(self.live_server_url + url)
headers = self.selenium.find_elements(
By.CSS_SELECTOR, "fieldset.module thead tr th"
)
self.assertHTMLEqual(headers[-1].get_attribute("outerHTML"), "<th></th>")
delete = self.selenium.find_element(
By.CSS_SELECTOR,
"fieldset.module tbody tr.dynamic-sighting_set:not(.original) td.delete",
)
self.assertIn(
'<a role="button" class="inline-deletelink" href="#">',
delete.get_attribute("innerHTML"),
)
self.take_screenshot("loaded")