Skip to content

Commit

Permalink
Merge pull request #4048 from GeotrekCE/fix_menu_item_migration_trans…
Browse files Browse the repository at this point in the history
…lator_error

Ensure migration steps for menu items can be run separately
  • Loading branch information
marcantoinedupre committed Apr 4, 2024
2 parents fb42f7e + 4128737 commit 2398d44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CHANGELOG
**Bug fix**

- New menu items targeting static page now open it in the same tab
- Ensure migration steps for menu items can be run separately


2.104.1 (2024-04-03)
Expand Down
8 changes: 6 additions & 2 deletions geotrek/flatpages/migrations/0011_migrate_flatpage_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.conf import settings
from django.db import migrations
from django.utils import translation
from modeltranslation.translator import translator, TranslationOptions
from modeltranslation.translator import translator, TranslationOptions, AlreadyRegistered
from modeltranslation.utils import build_localized_fieldname

from treebeard.mp_tree import MP_Node
Expand Down Expand Up @@ -94,8 +94,12 @@ class FlatPageTO(TranslationOptions):
# modeltranslation registration is not run on historical models available during migrations.
# We register FlatPage for translations now so `title_fr`, `title_es`, etc are defined.
translator.register(FlatPage, FlatPageTO)
# MenuItem is already translation-registered from the previous migration
# MenuItem is already translation-registered from the previous migration so we cautiously try
# (it will be needed to copy values in translation fields)
try:
translator.register(MenuItem, MenuItemTO)
except AlreadyRegistered:
pass

# Those fields are copied from FlatPage to MenuItem.
# Dict keys are FlatPage's fieldnames, dict values are MenuItem's fieldnames.
Expand Down

0 comments on commit 2398d44

Please sign in to comment.