Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosign improvements (batch 2) #4838

Merged
merged 16 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
8bd1ac3
:technologist: [#4320] Add debug view links to submission admin in de…
sergei-maertens Nov 19, 2024
4621aa5
:test_tube: [#4320] Add regression test for unexpected summary heading
sergei-maertens Nov 19, 2024
68ed6df
:bug: [#4320] Ensure that the summary tag is not emitted if there's n…
sergei-maertens Nov 19, 2024
d56ee8a
:white_check_mark: [#4320] Add test for cosign-specific confirmation …
sergei-maertens Nov 19, 2024
f7a0717
:card_file_box: [#4320] Define model fields for cosign confirmation t…
sergei-maertens Nov 19, 2024
28dc3a3
:sparkles: [#4320] Select the correct templates for confirm email
sergei-maertens Nov 19, 2024
02600c9
:recycle: [#4320] Put default translation fix in re-usable helper
sergei-maertens Nov 21, 2024
f3748de
:adhesive_bandage: [#4320] Ensure new translatable fields have proper…
sergei-maertens Nov 21, 2024
100e720
:globe_with_meridians: [#4320] Initial pass at translating the new fi…
sergei-maertens Nov 21, 2024
d68e08c
:sparkles: [#4320] Add new template fields to the frontend
sergei-maertens Nov 21, 2024
5eac22f
:speech_balloon: [#4320] Tweak the (default) templates for cosign con…
sergei-maertens Nov 21, 2024
3b4daae
:boom: [#4320] Remove header from cosign_information tag
sergei-maertens Nov 21, 2024
ea34ad7
:bento: [#4320] Re-generate API spec
sergei-maertens Nov 21, 2024
bb9c1fb
:sparkles: [#4320] Treat PDF confirmation page content different depe…
sergei-maertens Nov 21, 2024
8cf1dca
:globe_with_meridians: [#4320] Extract new translations
sergei-maertens Nov 21, 2024
d9c6e9d
:children_crossing: [#4320] Use more accessible language
sergei-maertens Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,16 @@

import functools

from django.conf import settings
from django.db import migrations, models
from django.db.migrations.state import StateApps
from django.utils import translation
from django.utils.translation import gettext

import tinymce.models

import openforms.config.models.config
import openforms.template.validators
import openforms.utils.translations


def update_translated_defaults(apps: StateApps, _):
"""
Set the properly translated default config field values.

Workaround for https://github.com/open-formulieren/open-forms/issues/4826
"""
GlobalConfiguration = apps.get_model("config", "GlobalConfiguration")
config = GlobalConfiguration.objects.first()
if config is None:
return

for field in (
"cosign_submission_confirmation_template",
"cosign_submission_confirmation_title",
"submission_confirmation_title",
):
for lang, _ in settings.LANGUAGES:
with translation.override(lang):
default_callback = config._meta.get_field(field).default
assert isinstance(default_callback, functools.partial)
if default_callback.func is openforms.utils.translations.get_default:
default_callback = functools.partial(
gettext, *default_callback.args
)
setattr(config, f"{field}_{lang}", default_callback())
config.save()
from openforms.utils.migrations_utils.fix_default_translation import (
FixDefaultTranslations,
)


class Migration(migrations.Migration):
Expand Down Expand Up @@ -188,5 +159,16 @@ class Migration(migrations.Migration):
verbose_name="submission confirmation title",
),
),
migrations.RunPython(update_translated_defaults, migrations.RunPython.noop),
migrations.RunPython(
FixDefaultTranslations(
app_label="config",
model="GlobalConfiguration",
fields=(
"cosign_submission_confirmation_template",
"cosign_submission_confirmation_title",
"submission_confirmation_title",
),
),
migrations.RunPython.noop,
),
]
42 changes: 42 additions & 0 deletions src/openforms/utils/migrations_utils/fix_default_translation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import functools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to keep this solution?I thought it was not the what we wanted.(asking since this is now a reusable thing..)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not what we want, but it is what we need for the time being 😬

from collections.abc import Sequence

from django.conf import settings
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.utils import translation
from django.utils.translation import gettext

import openforms.utils.translations


class FixDefaultTranslations:
"""
Set the properly translated default translatable field values.

Workaround for https://github.com/open-formulieren/open-forms/issues/4826
"""

def __init__(self, app_label: str, model: str, fields: Sequence[str]):
self.app_label = app_label
self.model = model
self.fields = fields

def __call__(self, apps: StateApps, schema_editor: BaseDatabaseSchemaEditor):
Model = apps.get_model(self.app_label, self.model)
for obj in Model.objects.all():
for field in self.fields:
for lang, _ in settings.LANGUAGES:
with translation.override(lang):
default_callback = Model._meta.get_field(field).default
assert isinstance(default_callback, functools.partial)
if (
default_callback.func
is openforms.utils.translations.get_default
):
default_callback = functools.partial(
gettext,
*default_callback.args,
)
setattr(obj, f"{field}_{lang}", default_callback())
obj.save()