Skip to content

Commit

Permalink
⚰️ [#1451] -- Remove Submission.get_printable_data
Browse files Browse the repository at this point in the history
Good riddance.
  • Loading branch information
sergei-maertens committed May 6, 2022
1 parent fc5d039 commit d7b63bd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 276 deletions.
2 changes: 1 addition & 1 deletion src/openforms/emails/confirmation_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_confirmation_email_context_data(submission: "Submission") -> Dict[str, A
"_form": submission.form, # should be the same as self.form
# TODO: this should use the :func:`openforms.formio.formatters.service.format_value`
# but be keyed by component.key instead of the label, which
# submission.get_printable_data does.
# submission.get_printable_data did.
**submission.data,
"public_reference": submission.public_registration_reference,
"form_name": submission.form.name,
Expand Down
17 changes: 15 additions & 2 deletions src/openforms/formio/formatters/tests/test_kitchensink.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,23 @@

from ...utils import iter_components
from ..printable import filter_printable
from ..service import format_value
from .mixins import BaseFormatterTestCase
from .utils import load_json


def _get_printable_data(submission):
printable_data = []
for key, (
component,
value,
) in submission.get_ordered_data_with_component_type().items():
printable_data.append(
(component["label"], format_value(component, value, as_html=False))
)
return printable_data


class KitchensinkFormatterTestCase(BaseFormatterTestCase):
def test_kitchensink_formio(self):
self.run_kitchensink_test("kitchensink_data", "kitchensink_printable_text")
Expand Down Expand Up @@ -81,7 +94,7 @@ def run_kitchensink_test(self, name_data, name_printable):
submission_step=submission_step,
)

printable_data = submission.get_printable_data()
printable_data = _get_printable_data(submission)

# check if we have something for all components
self.assertEqual(set(d[0] for d in printable_data), expected_labels)
Expand Down Expand Up @@ -115,7 +128,7 @@ def test_appointments_formio(self):
configuration["components"], submitted_data=data, completed=True
)

printable_data = submission.get_printable_data()
printable_data = _get_printable_data(submission)

text_values = dict()
for label, value in printable_data:
Expand Down
37 changes: 2 additions & 35 deletions src/openforms/submissions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import os.path
import uuid
import warnings
from collections import OrderedDict, defaultdict
from dataclasses import dataclass
from datetime import date, timedelta
Expand All @@ -14,7 +13,7 @@
from django.template import Context, Template
from django.urls import resolve
from django.utils import timezone
from django.utils.translation import gettext, gettext_lazy as _
from django.utils.translation import gettext_lazy as _

from celery.result import AsyncResult
from django_better_admin_arrayfield.models.fields import ArrayField
Expand All @@ -25,7 +24,7 @@
from openforms.authentication.constants import AuthAttribute
from openforms.config.models import GlobalConfiguration
from openforms.contrib.kvk.validators import validate_kvk
from openforms.formio.formatters.service import filter_printable, format_value
from openforms.formio.formatters.service import filter_printable
from openforms.forms.models import FormStep
from openforms.payments.constants import PaymentStatus
from openforms.utils.files import DeleteFileFieldFilesMixin, DeleteFilesQuerySetMixin
Expand Down Expand Up @@ -574,38 +573,6 @@ def get_merged_data(self) -> dict:

data = property(get_merged_data)

def get_printable_data(
self,
keys_to_include: Optional[List[str]] = None,
as_html=False,
) -> List[Tuple[str, str]]:
warnings.warn(
"Submission.get_printable_data() is deprecated - instead, use "
"'openforms.submissions.rendering.renderer.Renderer' with an appropriate "
"render mode.",
DeprecationWarning,
)
printable_data = []

for key, (
component,
value,
) in self.get_ordered_data_with_component_type().items():
if keys_to_include is not None and key not in keys_to_include:
continue

printable_data.append(
(component["label"], format_value(component, value, as_html=as_html))
)

# finally, check if we have co-sign information to append
if self.co_sign_data:
if not (co_signer := self.co_sign_data.get("representation", "")):
logger.warning("Incomplete co-sign data for submission %s", self.uuid)
printable_data.append((gettext("Co-signed by"), co_signer))

return printable_data

def get_co_signer(self) -> str:
if not self.co_sign_data:
return ""
Expand Down
37 changes: 1 addition & 36 deletions src/openforms/submissions/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_get_ordered_data_with_component_type_formio_formatters(self):
)
self.assertEqual(actual, expected)

def test_get_printable_data_with_selectboxes_formio_formatters(self):
def test_submission_data_with_selectboxes_formio_formatters(self):
form_definition = FormDefinitionFactory.create(
configuration={
"display": "form",
Expand Down Expand Up @@ -182,16 +182,6 @@ def test_get_printable_data_with_selectboxes_formio_formatters(self):
)
},
)
printable_data = submission.get_printable_data()

self.assertEqual(
"My Boxes",
printable_data[0][0],
)
self.assertEqual(
"test 1; test 2",
printable_data[0][1],
)

def test_submission_remove_sensitive_data(self):
form_definition = FormDefinitionFactory.create(
Expand Down Expand Up @@ -367,31 +357,6 @@ def test_submission_delete_file_uploads_cascade_file_already_gone(self):
)
self.assertFalse(attachment.content.storage.exists(attachment.content.path))

def test_printable_data_with_empty_keys_to_include(self):
form_definition = FormDefinitionFactory.create(
configuration={
"display": "form",
"components": [
{
"key": "testField",
"type": "textfield",
"label": "Label",
"showInEmail": False,
},
],
}
)
submission = SubmissionFactory.create()
SubmissionStepFactory.create(
submission=submission,
data={"testField": "this is text in a text area"},
form_step__form_definition=form_definition,
)

printable_data = submission.get_printable_data(keys_to_include=[])

self.assertEqual(0, len(printable_data))

def test_get_merged_appointment_data(self):
form = FormFactory.create()
form_definition_1 = FormDefinitionFactory.create(
Expand Down
202 changes: 0 additions & 202 deletions src/openforms/submissions/tests/test_submission_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,208 +103,6 @@ def test_report_generation(self, mock_request):
# report.content.name contains the path too
self.assertTrue(report.content.name.endswith("Test_Form.pdf"))

@override_settings(LANGUAGE_CODE="nl")
def test_submission_printable_data(self):
# TODO: move this test to a separate test module/case?
form = FormFactory.create()
form_def = FormDefinitionFactory.create(
configuration={
"components": [
{
"key": "radio1",
"type": "radio",
"label": "Test Radio",
"values": [
{"label": "Test Option 1", "value": "testOption1"},
{"label": "Test Option 2", "value": "testOption2"},
],
},
{
"key": "select1",
"type": "select",
"label": "Test Select",
"data": {
"values": [
{"label": "Test Option 1", "value": "testOption1"},
{"label": "Test Option 2", "value": "testOption2"},
]
},
},
{
"key": "select2",
"type": "select",
"label": "Test Select 2",
"multiple": True,
"data": {
"values": [
{"label": "Test Option 1", "value": "testOption1"},
{"label": "Test Option 2", "value": "testOption2"},
]
},
},
{
"key": "date0",
"type": "date",
"label": "Test date 0",
},
{
"key": "date1",
"type": "date",
"label": "Test date 1",
},
{
"key": "date2",
"type": "date",
"label": "Test date 2",
"multiple": True,
},
# appointment fields are special...
{
"key": "date3",
"type": "select",
"label": "Afspraakdatum",
"appointments": {
"showDates": True,
},
},
{
"key": "time0",
"type": "time",
"label": "Test time 0",
},
{
"key": "time1",
"type": "select",
"label": "Afspraaktijdstip",
"appointments": {
"showTimes": True,
},
},
{
"key": "number1",
"type": "number",
"label": "Test number 1",
"decimalLimit": 0,
},
{
"key": "number2",
"type": "number",
"label": "Test number 2",
"decimalLimit": 2,
},
{
"key": "number3",
"type": "number",
"label": "Test number 3",
"decimalLimit": 2,
"multiple": True,
},
{
"key": "currency",
"type": "currency",
"label": "Test currency",
},
{"key": "checkbox", "type": "checkbox", "label": "Test checkbox"},
]
}
)
form_step = FormStepFactory.create(form_definition=form_def, form=form)
submission = SubmissionFactory.create(completed=True, form=form)
SubmissionStepFactory.create(
data={
"radio1": "testOption1",
"select1": "testOption2",
"select2": ["testOption2", "testOption1"],
"date0": "",
"date1": "2022-01-02",
"date2": ["2022-01-02", "2022-02-03"],
"time0": "17:30:00",
"date3": "2021-12-24",
"time1": "2021-12-24T08:10:00+01:00",
"number1": 1,
"number2": 1.23,
"number3": [4.20, 2.71],
"currency": 1.23,
"checkbox": True,
},
submission=submission,
form_step=form_step,
)

printable_data = submission.get_printable_data()

values = [
("Test Radio", "Test Option 1"),
("Test Select", "Test Option 2"),
("Test Select 2", "Test Option 2; Test Option 1"),
("Test date 0", ""),
("Test date 1", "2 januari 2022"),
("Test date 2", "2 januari 2022; 3 februari 2022"),
("Afspraakdatum", "24 december 2021"),
("Test time 0", "17:30"),
("Afspraaktijdstip", "08:10"),
("Test number 1", "1"),
("Test number 2", "1,23"),
("Test number 3", "4,20; 2,71"),
("Test currency", "1,23"),
("Test checkbox", "ja"),
]

for i, (expected, actual) in enumerate(zip(values, printable_data)):
with self.subTest(i=i, e=expected[0]):
self.assertEqual(expected[0], actual[0]) # Labels
self.assertEqual(expected[1], actual[1]) # Values

@override_settings(LANGUAGE_CODE="nl")
def test_submission_printable_data_with_repeating_labels(self):
form = FormFactory.create()
form_def = FormDefinitionFactory.create(
configuration={
"components": [
{
"key": "radio1",
"type": "radio",
"label": "Test Equal label",
"values": [
{"label": "Test Option 1", "value": "testOption1"},
{"label": "Test Option 2", "value": "testOption2"},
],
},
{
"key": "radio2",
"type": "radio",
"label": "Test Equal label",
"values": [
{"label": "Test Option 1", "value": "testOption1"},
{"label": "Test Option 2", "value": "testOption2"},
],
},
]
}
)
form_step = FormStepFactory.create(form_definition=form_def, form=form)
submission = SubmissionFactory.create(completed=True, form=form)
SubmissionStepFactory.create(
data={
"radio1": "testOption1",
"radio2": "testOption2",
},
submission=submission,
form_step=form_step,
)

printable_data = submission.get_printable_data()

values = [
("Test Equal label", "Test Option 1"),
("Test Equal label", "Test Option 2"),
]

for expected, actual in zip(values, printable_data):
with self.subTest(expected[0]):
self.assertEqual(expected[0], actual[0]) # Labels
self.assertEqual(expected[1], actual[1]) # Values

@patch(
"celery.result.AsyncResult._get_task_meta", return_value={"status": "SUCCESS"}
)
Expand Down

0 comments on commit d7b63bd

Please sign in to comment.