From 304554f4051ab632b6851f948add5d273c09e7a4 Mon Sep 17 00:00:00 2001 From: Pomax Date: Mon, 18 Mar 2019 15:38:58 -0700 Subject: [PATCH 1/3] Update apps.py From https://github.com/infoportugal/wagtail-modeltranslation/issues/234#issuecomment-474096604, the timing between django-modeltranslation and wagtail-modeltranslation leads to wmt updating the settings variable for dmt too late (namely, after dmt already read it out). This PR ensures that the `CUSTOM_FIELDS` value is set directly on dmt's settings. This fixes the (original) issue reported in https://github.com/infoportugal/wagtail-modeltranslation/issues/234 --- wagtail_modeltranslation/apps.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/wagtail_modeltranslation/apps.py b/wagtail_modeltranslation/apps.py index f77efc0..eff9d97 100644 --- a/wagtail_modeltranslation/apps.py +++ b/wagtail_modeltranslation/apps.py @@ -10,9 +10,22 @@ class ModeltranslationConfig(AppConfig): def ready(self): from django.conf import settings + from modeltranslation import settings as mt_settings + # Add Wagtail defined fields as modeltranslation custom fields - setattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', getattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', ()) + ( - 'StreamField', 'RichTextField')) + wagtail_fields = ( + 'StreamField', + 'RichTextField', + ) + + # update both the standard settings and the modeltranslation settings, + # as we cannot guarantee the load order, and so django_modeltranslation + # may bootstrap itself either before, or after, our ready() gets called. + custom_fields = getattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', ()) + setattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', list(set(custom_fields + wagtail_fields))) + + mt_custom_fields = getattr(mt_settings, 'CUSTOM_FIELDS', ()) + setattr(mt_settings, 'CUSTOM_FIELDS', list(set(mt_custom_fields + wagtail_fields))) from modeltranslation.models import handle_translation_registrations handle_translation_registrations() From 372a2f31df1515bc5d8e97a2b54d667a261946a0 Mon Sep 17 00:00:00 2001 From: Pomax Date: Tue, 19 Mar 2019 11:36:42 -0700 Subject: [PATCH 2/3] Update apps.py --- wagtail_modeltranslation/apps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wagtail_modeltranslation/apps.py b/wagtail_modeltranslation/apps.py index eff9d97..fe2275a 100644 --- a/wagtail_modeltranslation/apps.py +++ b/wagtail_modeltranslation/apps.py @@ -21,10 +21,10 @@ class ModeltranslationConfig(AppConfig): # update both the standard settings and the modeltranslation settings, # as we cannot guarantee the load order, and so django_modeltranslation # may bootstrap itself either before, or after, our ready() gets called. - custom_fields = getattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', ()) + custom_fields = getattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', list()) setattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', list(set(custom_fields + wagtail_fields))) - mt_custom_fields = getattr(mt_settings, 'CUSTOM_FIELDS', ()) + mt_custom_fields = getattr(mt_settings, 'CUSTOM_FIELDS', list()) setattr(mt_settings, 'CUSTOM_FIELDS', list(set(mt_custom_fields + wagtail_fields))) from modeltranslation.models import handle_translation_registrations From 4f0b07789c7e88d1356b57472f068d2c992fafd1 Mon Sep 17 00:00:00 2001 From: Diogo Marques Date: Thu, 21 Mar 2019 10:47:32 +0000 Subject: [PATCH 3/3] Fixes error on apps.py: TypeError: can only concatenate list (not "tuple") to list --- wagtail_modeltranslation/apps.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wagtail_modeltranslation/apps.py b/wagtail_modeltranslation/apps.py index fe2275a..a21d273 100644 --- a/wagtail_modeltranslation/apps.py +++ b/wagtail_modeltranslation/apps.py @@ -21,11 +21,11 @@ class ModeltranslationConfig(AppConfig): # update both the standard settings and the modeltranslation settings, # as we cannot guarantee the load order, and so django_modeltranslation # may bootstrap itself either before, or after, our ready() gets called. - custom_fields = getattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', list()) - setattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', list(set(custom_fields + wagtail_fields))) + custom_fields = getattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', tuple()) + setattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', tuple(set(custom_fields + wagtail_fields))) - mt_custom_fields = getattr(mt_settings, 'CUSTOM_FIELDS', list()) - setattr(mt_settings, 'CUSTOM_FIELDS', list(set(mt_custom_fields + wagtail_fields))) + mt_custom_fields = getattr(mt_settings, 'CUSTOM_FIELDS', tuple()) + setattr(mt_settings, 'CUSTOM_FIELDS', tuple(set(mt_custom_fields + wagtail_fields))) from modeltranslation.models import handle_translation_registrations handle_translation_registrations()