Ensure thumb_col_header_text is used by ThumbnailMixin correctly

- fixes #8269
because you cannot dynamically set attributes on bound methods, we need to update the current classes version of admin_thumb so it can be accessed in sub classes
pull/8305/head
Kyle J. Roux 2022-04-02 16:23:49 -07:00 zatwierdzone przez LB (Ben Johnston)
rodzic 0b8a8c2024
commit 844efa696a
6 zmienionych plików z 15 dodań i 2 usunięć

Wyświetl plik

@ -58,6 +58,7 @@ Changelog
* Fix: Stop skipping heading levels in Wagtail welcome page (Jesse Menn)
* Fix: Add missing `lang` attributes to `<html>` elements (James Ray)
* Fix: Avoid 503 server error when entering tags over 100chars and instead show a user facing validation error (Vu Pham, Khanh Hoang)
* Fix: Ensure `thumb_col_header_text` is correctly used by `ThumbnailMixin` within `ModelAdmin` as the column header label (Kyle J. Roux)
2.16.2 (xx.xx.xxxx) - IN DEVELOPMENT

Wyświetl plik

@ -588,6 +588,7 @@ Contributors
* Caio Jhonny
* Heather White
* Onno Timmerman
* Kyle J. Roux
Translators
===========

Wyświetl plik

@ -93,6 +93,7 @@ class LandingPage(Page):
* Add missing `lang` attributes to `<html>` elements (James Ray)
* Add missing translation usage in Workflow templates (Anuja Verma, Saurabh Kumar)
* Avoid 503 server error when entering tags over 100chars and instead show a user facing validation error (Vu Pham, Khanh Hoang)
* Ensure `thumb_col_header_text` is correctly used by `ThumbnailMixin` within `ModelAdmin` as the column header label (Kyle J. Roux)
## Upgrade considerations

Wyświetl plik

@ -25,6 +25,7 @@ class ThumbnailMixin:
"The `wagtail.images` app must be installed in order "
"to use the `ThumbnailMixin` class."
)
self.__class__.admin_thumb.short_description = self.thumb_col_header_text
super().__init__(*args, **kwargs)
def admin_thumb(self, obj):
@ -53,5 +54,3 @@ class ThumbnailMixin:
rendition = get_rendition_or_not_found(image, spec)
img_attrs.update({"src": rendition.url})
return mark_safe("<img{}>".format(flatatt(img_attrs)))
admin_thumb.short_description = thumb_col_header_text

Wyświetl plik

@ -43,6 +43,16 @@ class TestBookIndexView(TestCase, WagtailTestUtils):
def get(self, **params):
return self.client.get("/admin/modeladmintest/book/", params)
def test_thumbnail_image_col_header_text(self):
response = self.get()
# check thumb_col_header_text is correctly used
self.assertContains(
response,
'<th scope="col" class="column-admin_thumb">The cover</th>',
html=True,
)
def test_simple(self):
response = self.get()

Wyświetl plik

@ -84,6 +84,7 @@ class BookModelAdmin(ThumbnailMixin, ModelAdmin):
inspect_view_enabled = True
inspect_view_fields_exclude = ("title",)
thumb_image_field_name = "cover_image"
thumb_col_header_text = "The cover"
search_handler_class = WagtailBackendSearchHandler
prepopulated_fields = {"title": ("author",)}