mirror of https://github.com/django/django.git
Fixed #34283 -- Escaped title in admin's changelist filters.
Regression in 27aa7035f5
.
This commit is contained in:
parent
0265b1b49b
commit
20a0850099
|
@ -11,7 +11,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.entries(filters).forEach(([key, value]) => {
|
Object.entries(filters).forEach(([key, value]) => {
|
||||||
const detailElement = document.querySelector(`[data-filter-title='${key}']`);
|
const detailElement = document.querySelector(`[data-filter-title='${CSS.escape(key)}']`);
|
||||||
|
|
||||||
// Check if the filter is present, it could be from other view.
|
// Check if the filter is present, it could be from other view.
|
||||||
if (detailElement) {
|
if (detailElement) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django.contrib.auth.admin import UserAdmin
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
|
|
||||||
from .models import Band, Child, Event, Parent, Swallow
|
from .models import Band, Child, Event, Parent, ProxyUser, Swallow
|
||||||
|
|
||||||
site = admin.AdminSite(name="admin")
|
site = admin.AdminSite(name="admin")
|
||||||
|
|
||||||
|
@ -185,3 +185,24 @@ class EmptyValueChildAdmin(admin.ModelAdmin):
|
||||||
@admin.display(empty_value="†")
|
@admin.display(empty_value="†")
|
||||||
def age_display(self, obj):
|
def age_display(self, obj):
|
||||||
return obj.age
|
return obj.age
|
||||||
|
|
||||||
|
|
||||||
|
class UnescapedTitleFilter(admin.SimpleListFilter):
|
||||||
|
title = "It's OK"
|
||||||
|
parameter_name = "is_active"
|
||||||
|
|
||||||
|
def lookups(self, request, model_admin):
|
||||||
|
return [("yes", "yes"), ("no", "no")]
|
||||||
|
|
||||||
|
def queryset(self, request, queryset):
|
||||||
|
if self.value() == "yes":
|
||||||
|
return queryset.filter(is_active=True)
|
||||||
|
else:
|
||||||
|
return queryset.filter(is_active=False)
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUserAdmin(UserAdmin):
|
||||||
|
list_filter = [UnescapedTitleFilter]
|
||||||
|
|
||||||
|
|
||||||
|
site.register(ProxyUser, CustomUserAdmin)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,3 +122,8 @@ class CustomIdUser(models.Model):
|
||||||
|
|
||||||
class CharPK(models.Model):
|
class CharPK(models.Model):
|
||||||
char_pk = models.CharField(max_length=100, primary_key=True)
|
char_pk = models.CharField(max_length=100, primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
|
class ProxyUser(User):
|
||||||
|
class Meta:
|
||||||
|
proxy = True
|
||||||
|
|
|
@ -1910,3 +1910,23 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||||
"[data-filter-title='number of members']",
|
"[data-filter-title='number of members']",
|
||||||
).get_attribute("open")
|
).get_attribute("open")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_collapse_filter_with_unescaped_title(self):
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
|
||||||
|
self.admin_login(username="super", password="secret")
|
||||||
|
changelist_url = reverse("admin:admin_changelist_proxyuser_changelist")
|
||||||
|
self.selenium.get(self.live_server_url + changelist_url)
|
||||||
|
# Title is escaped.
|
||||||
|
filter_title = self.selenium.find_element(
|
||||||
|
By.CSS_SELECTOR, "[data-filter-title='It\\'s OK']"
|
||||||
|
)
|
||||||
|
filter_title.find_element(By.CSS_SELECTOR, "summary").click()
|
||||||
|
self.assertFalse(filter_title.get_attribute("open"))
|
||||||
|
# Filter is in the same state after refresh.
|
||||||
|
self.selenium.refresh()
|
||||||
|
self.assertFalse(
|
||||||
|
self.selenium.find_element(
|
||||||
|
By.CSS_SELECTOR, "[data-filter-title='It\\'s OK']"
|
||||||
|
).get_attribute("open")
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue