Skip to content

Commit

Permalink
✨ Add csv export for donation gifts
Browse files Browse the repository at this point in the history
  • Loading branch information
pajowu committed Jan 22, 2024
1 parent 274fe10 commit 6c80d2e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion fragdenstaat_de/fds_donation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ class DonationGiftOrderAdmin(admin.ModelAdmin):
"donation_gift",
)
search_fields = ("email", "donation__donor__email", "donation_gift__name")
actions = ["notify_shipped"]
actions = ["notify_shipped", "export_csv"]

def get_queryset(self, request):
return (
Expand Down Expand Up @@ -904,6 +904,27 @@ def notify_shipped(self, request, queryset):

notify_shipped.short_description = _("notify shipped and set date")

def export_csv(self, request, queryset):
def get_rows(queryset):
for object in queryset:
yield {
"id": object.id,
"email": object.email,
"first_name": object.first_name,
"last_name": object.last_name,
"company_name": object.company_name,
"address": object.address,
"postcode": object.postcode,
"city": object.city,
"country": object.country.name,
"full_address": object.formatted_address(),
}

donor_data = list(get_rows(queryset))
return export_csv_response(dict_to_csv_stream(donor_data))

export_csv.short_description = _("export as csv")


class DefaultDonationAdmin(DonationAdmin):
list_display = [x for x in DonationAdmin.list_display if x != "project"]
Expand Down

0 comments on commit 6c80d2e

Please sign in to comment.