Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tkw1536 committed Sep 19, 2023
1 parent 8e6e371 commit f3d3aa6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions alumni/admin/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion donations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)],
),
]


Expand Down

0 comments on commit f3d3aa6

Please sign in to comment.