Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add csv export for donation gifts #452

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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