diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ddc97fb..1a1a7c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ exclude: ".yarn/|yarn.lock|\\.min\\.(css|js)$" repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-added-large-files - id: check-builtin-literals @@ -14,35 +14,27 @@ repos: - id: mixed-line-ending - id: trailing-whitespace - repo: https://github.com/adamchainz/django-upgrade - rev: 1.20.0 + rev: 1.22.1 hooks: - id: django-upgrade args: [--target-version, "3.2"] - - repo: https://github.com/MarcoGorelli/absolufy-imports - rev: v0.3.1 - hooks: - - id: absolufy-imports - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.6.2" + rev: "v0.7.0" hooks: - id: ruff + args: [--unsafe-fixes] - id: ruff-format - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.1.0 - hooks: - - id: prettier - args: [--list-different, --no-semi] - exclude: "^conf/|.*\\.html$" - repo: https://github.com/biomejs/pre-commit - rev: "v0.4.0" + rev: "v0.5.0" hooks: - id: biome-check - additional_dependencies: ["@biomejs/biome@1.8.3"] + additional_dependencies: ["@biomejs/biome@1.9.4"] + args: [--unsafe] - repo: https://github.com/tox-dev/pyproject-fmt - rev: 2.2.1 + rev: 2.4.3 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.19 + rev: v0.21 hooks: - id: validate-pyproject diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fd9f4dd..fbbffea 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,8 @@ Next version * Limited the email field choices to email fields only when using the send emails to authors option. +* Stopped slugifying choice values so that we properly support non-latin + characters. 0.26 ---- diff --git a/form_designer/models.py b/form_designer/models.py index 202a7d8..16e76c5 100644 --- a/form_designer/models.py +++ b/form_designer/models.py @@ -204,10 +204,17 @@ def loader(submission, field, choice_dict): def old_name_loader(submission, old_name): return submission.data.get(old_name) + def include_slugified_choices(choices): + return dict(choices) | {slugify(value): label for value, label in choices} + fields_and_loaders = [ ( {"name": field.name, "title": field.title}, - partial(loader, field=field, choice_dict=dict(field.get_choices())), + partial( + loader, + field=field, + choice_dict=include_slugified_choices(field.get_choices()), + ), ) for field in self.fields.all() ] @@ -360,7 +367,7 @@ def clean(self): def get_choices(self): def get_tuple(value): - return (slugify(value.strip()), value.strip()) + return (value.strip(), value.strip()) choices = [get_tuple(value) for value in self.choices.split(",")] if not self.is_required and self.type == "select": @@ -383,8 +390,7 @@ def formfield(self): } if self.choices: kwargs["choices"] = self.get_choices() - # The value of individual choices is slugified too. - kwargs["initial"] = slugify(self.default_value) + kwargs["initial"] = self.default_value return self.get_type(**kwargs) diff --git a/tests/testapp/test_forms.py b/tests/testapp/test_forms.py index 4c53bf9..a3ac932 100644 --- a/tests/testapp/test_forms.py +++ b/tests/testapp/test_forms.py @@ -94,7 +94,7 @@ def test_forms(self): ) self.assertContains(response, "