Skip to content

Commit

Permalink
CRON endpoint for NGO export
Browse files Browse the repository at this point in the history
  • Loading branch information
danniel committed Jan 31, 2024
1 parent 830210d commit 3599c2b
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions backend/donations/views/cron.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import csv
import logging
import operator
from datetime import datetime

from django.utils import timezone
from django.http import HttpResponse
from django.utils import timezone

from donations.models.main import Donor, Ngo
from .base import Handler
Expand Down Expand Up @@ -49,7 +50,30 @@ class CustomExport(Handler):


class NgoExport(Handler):
pass
def get(self, request):
fields = (
"id",
"name",
"registration_number",
"county",
"active_region",
"email",
"website",
"address",
)

response = HttpResponse(
content_type="text/csv",
headers={"Content-Disposition": 'attachment; filename="ngo_export.csv"'},
)

writer = csv.writer(response, quoting=csv.QUOTE_ALL)
writer.writerow(fields)

for ngo in Ngo.objects.all().values(*fields):
writer.writerow([ngo[field_name] for field_name in fields])

return response


class NgoRemoveForms(Handler):
Expand Down

0 comments on commit 3599c2b

Please sign in to comment.