Fix issue aging pages report export if last_published_by is blank

Fixes #10821
pull/11601/head
Chiemezuo 2023-10-19 16:44:11 +01:00 zatwierdzone przez Sage Abdullah
rodzic caf68095b1
commit 0571c5e346
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: EB1A33CC51CC0217
3 zmienionych plików z 45 dodań i 0 usunięć

Wyświetl plik

@ -11,6 +11,7 @@ Changelog
* Fix: Avoid error when attempting to moderate a page drafted by a now deleted user (Dan Braghis)
* Fix: Ensure workflow dashboard panels work when the page/snippet is missing (Sage Abdullah)
* Fix: Prevent custom controls from stacking on top of the comment button in Draftail toolbar (Ben Morse)
* Fix: Avoid error when exporting Aging Pages report where a page has an empty `last_published_by_user` (Chiemezuo Akujobi)
5.2.1 (16.11.2023)

Wyświetl plik

@ -620,6 +620,48 @@ class TestAgingPagesView(WagtailTestUtils, TestCase):
self.assertEqual(worksheet["C2"].number_format, ExcelDateFormatter().get())
def test_xlsx_export_without_published_by(self):
"""
Test that the xlsx export works when a page has no 'published_by' set.
See https://github.com/wagtail/wagtail/issues/10821
"""
self.home.save_revision().publish()
if settings.USE_TZ:
self.home.last_published_at = "2013-01-01T12:00:00.000Z"
else:
self.home.last_published_at = "2013-01-01T12:00:00"
# mimic a page that does not have a 'published_by' on creation
self.home.last_published_by = None
self.home.save()
response = self.get(params={"export": "xlsx"})
self.assertEqual(response.status_code, 200)
workbook_data = response.getvalue()
worksheet = load_workbook(filename=BytesIO(workbook_data))["Sheet1"]
cell_array = [[cell.value for cell in row] for row in worksheet.rows]
self.assertEqual(
cell_array[0],
["Title", "Status", "Last published at", "Last published by", "Type"],
)
self.assertEqual(
cell_array[1],
[
"Welcome to your new Wagtail site!",
"live + draft",
datetime.datetime(2013, 1, 1, 12, 0),
None,
"Page",
],
)
self.assertEqual(len(cell_array), 2)
self.assertEqual(worksheet["C2"].number_format, ExcelDateFormatter().get())
def test_report_renders_when_page_publisher_deleted(self):
temp_user = self.create_superuser(
"temp", email="temp@user.com", password="tempuser"

Wyświetl plik

@ -82,6 +82,8 @@ class AgingPagesView(PageReportView):
user_id_value, get_deleted_user_display_name(user_id=user_id_value)
)
page.last_published_by_user = last_published_by_user
else:
page.last_published_by_user = ""
def decorate_paginated_queryset(self, queryset):
user_ids = set(queryset.values_list("last_published_by", flat=True))