Fixed incompatibilities with Wagtail 1.4rc1 (thanks @hmartiniano) and updated the tests to support the new version - ref #67.

This commit is contained in:
Alexandre Silva 2016-03-15 10:04:06 +00:00
parent deaa90b6e5
commit 9baf8427d8
3 changed files with 34 additions and 10 deletions

View file

@ -37,6 +37,7 @@ def runtests():
'django.contrib.contenttypes',
'django.contrib.auth',
'taggit',
'rest_framework',
'wagtail.wagtailcore',
'wagtail.wagtailadmin',

View file

@ -13,8 +13,6 @@ from django.utils.translation import ugettext as _
from wagtail.wagtailadmin.edit_handlers import FieldPanel, \
MultiFieldPanel, FieldRowPanel
from wagtail.wagtailadmin.edit_handlers import StreamFieldPanel
from wagtail.wagtailadmin.views.pages import get_page_edit_handler, \
PAGE_EDIT_HANDLERS
from wagtail.wagtailcore.models import Page, Site
from wagtail.wagtailcore.url_routing import RouteResult
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
@ -23,6 +21,12 @@ from wagtail.wagtailsnippets.views.snippets import get_snippet_edit_handler, \
from wagtail_modeltranslation.translator import translator, NotRegistered
from .utils import build_localized_fieldname
try:
from wagtail.wagtailadmin.views.pages import get_page_edit_handler, \
PAGE_EDIT_HANDLERS
except ImportError:
pass
logger = logging.getLogger('wagtail.core')
@ -40,7 +44,10 @@ class WagtailTranslator(object):
# CONSTRUCT TEMPORARY EDIT HANDLER
if issubclass(model, Page):
edit_handler_class = get_page_edit_handler(model)
if hasattr(model, 'get_edit_handler'):
edit_handler_class = model.get_edit_handler()
else:
edit_handler_class = get_page_edit_handler(model)
else:
edit_handler_class = get_snippet_edit_handler(model)
WagtailTranslator._base_model_form = edit_handler_class.get_form_class(model)
@ -62,9 +69,13 @@ class WagtailTranslator(object):
# DELETE TEMPORARY EDIT HANDLER IN ORDER TO LET WAGTAIL RECONSTRUCT
# NEW EDIT HANDLER BASED ON NEW TRANSLATION PANELS
if issubclass(model, Page):
if model in PAGE_EDIT_HANDLERS:
del PAGE_EDIT_HANDLERS[model]
edit_handler_class = get_page_edit_handler(model)
if hasattr(model, 'get_edit_handler'):
model.get_edit_handler.cache_clear()
edit_handler_class = model.get_edit_handler()
else:
if model in PAGE_EDIT_HANDLERS:
del PAGE_EDIT_HANDLERS[model]
edit_handler_class = get_page_edit_handler(model)
else:
if model in SNIPPET_EDIT_HANDLERS:
del SNIPPET_EDIT_HANDLERS[model]

View file

@ -18,7 +18,7 @@ from django.db.models import Q, F, Count
from django.test import TestCase, TransactionTestCase
from django.test.utils import override_settings
from django.utils import six
from django.utils.translation import get_language, override, trans_real
from django.utils.translation import get_language, override, trans_real, ugettext
from wagtail_modeltranslation import settings as mt_settings, translator
from wagtail_modeltranslation.forms import TranslationModelForm
@ -291,7 +291,10 @@ class ModeltranslationTest(ModeltranslationTestBase):
def test_verbose_name(self):
verbose_name = models.TestModel._meta.get_field('title_de').verbose_name
self.assertEqual(six.text_type(verbose_name), 'title [de]')
# We use ugettext to get the title since as of Wagtail 1.4 there is a
# german translation for title so the test would fail if we asserted against
# a constant string
self.assertEqual(six.text_type(verbose_name), ugettext('title') + ' [de]')
def test_descriptor_introspection(self):
# See Django #8248
@ -498,6 +501,7 @@ class WagtailModeltranslationTest(ModeltranslationTestBase):
"""
Test of the modeltranslation features with Wagtail models (Page and Snippet)
"""
@classmethod
def setUpClass(cls):
super(WagtailModeltranslationTest, cls).setUpClass()
@ -654,8 +658,16 @@ class WagtailModeltranslationTest(ModeltranslationTestBase):
so if the created form has all fields the the form was correctly patched
"""
models.InlinePanelPage()
from wagtail.wagtailadmin.views.pages import get_page_edit_handler
page_edit_handler = get_page_edit_handler(models.InlinePanelPage)
try:
from wagtail.wagtailadmin.views.pages import get_page_edit_handler, \
PAGE_EDIT_HANDLERS
except ImportError:
pass
if hasattr(models.InlinePanelPage, 'get_edit_handler'):
page_edit_handler = models.InlinePanelPage.get_edit_handler()
else:
page_edit_handler = get_page_edit_handler(models.InlinePanelPage)
form = page_edit_handler.get_form_class(models.InlinePanelPage)
page_base_fields = ['slug_de', 'slug_en', 'seo_title_de', 'seo_title_en', 'search_description_de',