Skip to content

Commit

Permalink
Repair the donations' download
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Jan 13, 2025
1 parent a44d768 commit cff9a3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backend/donations/management/commands/download_donations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

import time

from django.core.management import BaseCommand
from django_q.models import Schedule
from django_q.tasks import async_task
Expand Down Expand Up @@ -43,7 +43,7 @@ def handle(self, *args, **options):

logger.info(f"Download took {result} seconds.")
else:
self.stdout.write(self.style.SUCCESS("Setting up download task for job with ID #{job_id}."))
self.stdout.write(self.style.SUCCESS(f"Setting up download task for job with ID #{job_id}."))

success_message: str = f"set up download task for job with ID #{job_id}."
self._run_async(job_id)
Expand Down
15 changes: 10 additions & 5 deletions backend/donations/views/donations_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def _package_donations(tmp_dir_name: str, donations: QuerySet[Donor], ngo: Ngo,
)

csv_output = io.StringIO()
csv_output.write(codecs.BOM_UTF8)
csv_writer = csv.writer(csv_output, dialect=csv.excel)
csv_writer.writerow(
[
Expand Down Expand Up @@ -211,10 +210,16 @@ def _package_donations(tmp_dir_name: str, donations: QuerySet[Donor], ngo: Ngo,
]
)

# Attach a CSV file with all donor data
logger.info("Attaching the CSV to the ZIP")
with zip_archive.open("index.csv", mode="w", force_zip64=zip_64_flag) as handler:
handler.write(csv_output.getvalue().encode())
# Create the CSV file as a temporary file
with tempfile.TemporaryFile() as fp:
fp.write(codecs.BOM_UTF8)
fp.write(csv_output.getvalue().encode())

# Attach a CSV file with all donor data
logger.info("Attaching the CSV to the ZIP")
with zip_archive.open("index.csv", mode="w", force_zip64=zip_64_flag) as handler:
fp.seek(0)
handler.write(fp.read())

_generate_xml_files(ngo, zip_archive, zip_64_flag, zip_timestamp, cnp_idx)

Expand Down

0 comments on commit cff9a3e

Please sign in to comment.