From 6c80d2e8398efe663ef6ee314405081eeff992af Mon Sep 17 00:00:00 2001 From: Kara Engelhardt Date: Mon, 22 Jan 2024 10:54:56 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20csv=20export=20for=20donation?= =?UTF-8?q?=20gifts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fragdenstaat_de/fds_donation/admin.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/fragdenstaat_de/fds_donation/admin.py b/fragdenstaat_de/fds_donation/admin.py index f03795690..53fa0b9fd 100644 --- a/fragdenstaat_de/fds_donation/admin.py +++ b/fragdenstaat_de/fds_donation/admin.py @@ -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 ( @@ -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"]