-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🗃️ [#1451] -- add data migration to add the new display/presentation …
…options with default values
- Loading branch information
1 parent
055274d
commit 941584a
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/openforms/forms/migrations/0023_add_show_in_FOO_defaults.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Generated by Django 3.2.13 on 2022-05-09 10:21 | ||
|
||
from django.db import migrations | ||
|
||
from openforms.formio.rendering.constants import RenderConfigurationOptions | ||
from openforms.formio.utils import iter_components | ||
|
||
defaults = { | ||
RenderConfigurationOptions.show_in_summary: True, | ||
RenderConfigurationOptions.show_in_pdf: True, | ||
} | ||
|
||
|
||
def update_configuration(component: dict) -> bool: | ||
key = RenderConfigurationOptions.show_in_confirmation_email | ||
if key not in component: | ||
return False | ||
|
||
modified = False | ||
for option, default_value in defaults.items(): | ||
# skip if it's defined already | ||
if option in component: | ||
continue | ||
|
||
component[option] = default_value | ||
modified = True | ||
|
||
return modified | ||
|
||
|
||
def add_missing_show_in_FOO_options(apps, _): | ||
FormDefinition = apps.get_model("forms", "FormDefinition") | ||
for form_def in FormDefinition.objects.all(): | ||
if not form_def.configuration: | ||
continue | ||
|
||
is_modified = False | ||
for component in iter_components(form_def.configuration, recursive=True): | ||
is_modified = update_configuration(component) | ||
|
||
if is_modified: | ||
form_def.save(update_fields=["configuration"]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("forms", "0022_formsexport"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
add_missing_show_in_FOO_options, migrations.RunPython.noop | ||
), | ||
] |