Skip to content

Commit

Permalink
[#3470] Slugify form name in pdf submission reports
Browse files Browse the repository at this point in the history
Backport-of: #3480
  • Loading branch information
vaszig authored and sergei-maertens committed Sep 18, 2023
1 parent 9d5b35f commit 1872770
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/openforms/forms/tests/admin/test_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from django.apps import apps
from django.contrib import admin
from django.test import RequestFactory, TestCase, override_settings
from django.test import RequestFactory, TestCase, override_settings, tag
from django.urls import reverse
from django.utils.module_loading import import_string
from django.utils.translation import ugettext as _
Expand Down
2 changes: 1 addition & 1 deletion src/openforms/submissions/models/submission_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def generate_submission_report_pdf(self) -> str:
)
self.content = ContentFile(
content=pdf_report,
name=f"{form.name}.pdf", # Takes care of replacing spaces with underscores
name=f"{form.slug}.pdf",
)
self.save()
return html_report
Expand Down
6 changes: 4 additions & 2 deletions src/openforms/submissions/tests/test_submission_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ def test_invalid_token_timestamp(self):

@patch("celery.app.task.Task.request")
def test_report_generation(self, mock_request):
submission = SubmissionFactory.create(completed=True, form__name="Test Form")
submission = SubmissionFactory.create(
completed=True, form__name="Test Form", form__slug="test-form"
)
mock_request.id = "some-id"

generate_submission_report(submission.id)

report = submission.report
self.assertEqual("some-id", report.task_id)
# report.content.name contains the path too
self.assertTrue(report.content.name.endswith("Test_Form.pdf"))
self.assertTrue(report.content.name.endswith("test-form.pdf"))

@patch(
"celery.result.AsyncResult._get_task_meta", return_value={"status": "SUCCESS"}
Expand Down
6 changes: 4 additions & 2 deletions src/openforms/submissions/tests/test_tasks_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
@temp_private_root()
class SubmissionReportGenerationTests(TestCase):
def test_submission_report_metadata(self):
submission = SubmissionFactory.create(completed=True, form__name="Test Form")
submission = SubmissionFactory.create(
completed=True, form__name="Test Form", form__slug="test-form"
)

generate_submission_report.request.id = "some-id"
generate_submission_report.run(submission.id)
Expand All @@ -25,7 +27,7 @@ def test_submission_report_metadata(self):
_("%(title)s: Submission report") % {"title": "Test Form"}, report.title
)
self.assertEqual(submission, report.submission)
self.assertTrue(report.content.name.endswith("Test_Form.pdf"))
self.assertTrue(report.content.name.endswith("test-form.pdf"))
self.assertEqual("some-id", report.task_id)

def test_multiple_value_report_rendering_issue_990(self):
Expand Down

0 comments on commit 1872770

Please sign in to comment.