From e742a93f4c0a15dc48b17ed5ceae090652603fa0 Mon Sep 17 00:00:00 2001 From: Eric Sherman Date: Fri, 25 Oct 2019 13:06:15 -0500 Subject: [PATCH 1/3] different bindto model function depending on wagtail version --- wagtail_modeltranslation/patch_wagtailadmin.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wagtail_modeltranslation/patch_wagtailadmin.py b/wagtail_modeltranslation/patch_wagtailadmin.py index cf58f6f..077c5ff 100644 --- a/wagtail_modeltranslation/patch_wagtailadmin.py +++ b/wagtail_modeltranslation/patch_wagtailadmin.py @@ -45,6 +45,7 @@ from wagtail.wagtailsnippets.views.snippets import SNIPPET_EDIT_HANDLERS from wagtail_modeltranslation.settings import CUSTOM_SIMPLE_PANELS, CUSTOM_COMPOSED_PANELS, TRANSLATE_SLUGS from wagtail_modeltranslation.utils import compare_class_tree_depth +from wagtail import version logger = logging.getLogger('wagtail.core') @@ -141,7 +142,11 @@ def _patch_other_models(self, model): panels = filter(lambda field: field.field_name not in translation_registered_fields, panels) edit_handler = ObjectList(panels) + if VERSION < (2, 5): SNIPPET_EDIT_HANDLERS[model] = edit_handler.bind_to_model(model) + else: + SNIPPET_EDIT_HANDLERS[model] = edit_handler.bind_to(model=model) + def _patch_panels(self, panels_list, related_model=None): """ From 187e524ed2781ad2b5878372f026cf3a71eb0cc6 Mon Sep 17 00:00:00 2001 From: Eric Sherman Date: Fri, 25 Oct 2019 13:14:29 -0500 Subject: [PATCH 2/3] import verision constant --- wagtail_modeltranslation/patch_wagtailadmin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wagtail_modeltranslation/patch_wagtailadmin.py b/wagtail_modeltranslation/patch_wagtailadmin.py index 077c5ff..b3fc842 100644 --- a/wagtail_modeltranslation/patch_wagtailadmin.py +++ b/wagtail_modeltranslation/patch_wagtailadmin.py @@ -45,7 +45,7 @@ from wagtail.wagtailsnippets.views.snippets import SNIPPET_EDIT_HANDLERS from wagtail_modeltranslation.settings import CUSTOM_SIMPLE_PANELS, CUSTOM_COMPOSED_PANELS, TRANSLATE_SLUGS from wagtail_modeltranslation.utils import compare_class_tree_depth -from wagtail import version +from wagtail import VERSION logger = logging.getLogger('wagtail.core') From a92d287a6e14805b4240daa76fa2880333994307 Mon Sep 17 00:00:00 2001 From: Eric Sherman Date: Fri, 25 Oct 2019 13:17:44 -0500 Subject: [PATCH 3/3] nested if --- wagtail_modeltranslation/patch_wagtailadmin.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/wagtail_modeltranslation/patch_wagtailadmin.py b/wagtail_modeltranslation/patch_wagtailadmin.py index b3fc842..e2939cc 100644 --- a/wagtail_modeltranslation/patch_wagtailadmin.py +++ b/wagtail_modeltranslation/patch_wagtailadmin.py @@ -141,11 +141,10 @@ def _patch_other_models(self, model): translation_registered_fields = translator.get_options_for_model(model).fields panels = filter(lambda field: field.field_name not in translation_registered_fields, panels) edit_handler = ObjectList(panels) - - if VERSION < (2, 5): - SNIPPET_EDIT_HANDLERS[model] = edit_handler.bind_to_model(model) - else: - SNIPPET_EDIT_HANDLERS[model] = edit_handler.bind_to(model=model) + if VERSION < (2, 5): + SNIPPET_EDIT_HANDLERS[model] = edit_handler.bind_to_model(model) + else: + SNIPPET_EDIT_HANDLERS[model] = edit_handler.bind_to(model=model) def _patch_panels(self, panels_list, related_model=None):