Skip to content

Commit

Permalink
Add report name to the playtime summary attachment filename. (#1474)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein authored Oct 24, 2023
1 parent 349f690 commit 13c4b59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions core/jobs/playtime_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,18 @@ def do_run(self):
Configuration.REPORTING_NAME_ENVIRONMENT_VARIABLE, ""
)

# format report name for use in csv attachment filename below
subject_prefix = reporting_name
if len(reporting_name) > 0:
reporting_name += ": "
subject_prefix += ": "

email_subject = f"{reporting_name}Playtime Summaries {formatted_start_date} - {formatted_until_date}"
email_subject = f"{subject_prefix}Playtime Summaries {formatted_start_date} - {formatted_until_date}"
reporting_name_with_no_spaces = reporting_name.replace(" ", "_") + "-"
attachment_extension = "csv"
attachment_name = f"playtime-summary-{formatted_start_date}-{formatted_until_date}.{attachment_extension}"
attachment_name = (
f"playtime-summary-{reporting_name_with_no_spaces}"
f"{formatted_start_date}-{formatted_until_date}.{attachment_extension}"
)

# Write to a temporary file so we don't overflow the memory
with TemporaryFile(
Expand Down
4 changes: 2 additions & 2 deletions tests/core/jobs/test_playtime_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_do_run(self, db: DatabaseTransactionFixture):
# collection2 library2
playtime(db.session, identifier, collection2, library2, date3m(3), 300)

reporting_name = "test-cm"
reporting_name = "test cm"

# Horrible unbracketted syntax for python 3.8
with patch("core.jobs.playtime_entries.csv.writer") as writer, patch(
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_do_run(self, db: DatabaseTransactionFixture):
receivers=["[email protected]"],
text="",
attachments={
f"playtime-summary-{cutoff}-{until}.csv": ""
f"playtime-summary-{reporting_name.replace(' ', '_')}-{cutoff}-{until}.csv": ""
}, # Mock objects do not write data
)

Expand Down

0 comments on commit 13c4b59

Please sign in to comment.