From f3d3aa624d3717286e29c28e5b2d69c2415c4e4d Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Tue, 19 Sep 2023 19:57:38 +0200 Subject: [PATCH] Fix formatting --- alumni/admin/actions.py | 6 ++++-- donations/admin.py | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/alumni/admin/actions.py b/alumni/admin/actions.py index 3e97e85..5f69f40 100644 --- a/alumni/admin/actions.py +++ b/alumni/admin/actions.py @@ -133,6 +133,7 @@ def export_as_xslx( # Write the header (if desired) if header: + def makeHeaderCell(field): c = cell.Cell(ws, value=field) c.font = styles.Font(bold=True) @@ -143,19 +144,20 @@ def makeHeaderCell(field): # Write each of the rows copy = queryset.all() for (raw, row) in zip(copy, queryset.values_list(*field_names)): + def makeCell(prop): try: return to_excel(prop) except: return str(prop) - + cells = [makeCell(c) for c in row] if extra_fields: extra_cells = [makeCell(f(raw)) for (_, f) in extra_fields] else: extra_cells = [] - ws.append(cells+extra_cells) + ws.append(cells + extra_cells) # adjust column widths # adapted from https://stackoverflow.com/a/39530676 diff --git a/donations/admin.py b/donations/admin.py index 3d93c90..bafa49a 100644 --- a/donations/admin.py +++ b/donations/admin.py @@ -2,6 +2,7 @@ from donations.models import DonationTarget, Donation from alumni.admin.actions import export_as_xslx_action + def deactivate(modeladmin, request, queryset): queryset.update(active=False) @@ -16,7 +17,11 @@ class DonationAdmin(admin.ModelAdmin): date_hierarchy = "completed" actions = [ - export_as_xslx_action("Export as XSLX", fields=["completed", "target"], extra_fields=[("amount", lambda x:x.amount)]), + export_as_xslx_action( + "Export as XSLX", + fields=["completed", "target"], + extra_fields=[("amount", lambda x: x.amount)], + ), ]