def ready(self): from django.conf import settings from modeltranslation import settings as mt_settings # Add Wagtail defined fields as modeltranslation custom fields 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', tuple()) setattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', tuple(set(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() from .patch_wagtailadmin import patch_wagtail_models patch_wagtail_models()
def ready(self): from django.conf import settings # Add Wagtail defined fields as modeltranslation custom fields setattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', getattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', ()) + ( 'StreamField', 'RichTextField')) from modeltranslation.models import handle_translation_registrations handle_translation_registrations() from .patch_wagtailadmin import patch_wagtail_models patch_wagtail_models()
def ready(self): from django.conf import settings # Add Wagtail defined fields as modeltranslation custom fields setattr( settings, 'MODELTRANSLATION_CUSTOM_FIELDS', getattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', ()) + ('StreamField', 'RichTextField')) from modeltranslation.models import handle_translation_registrations handle_translation_registrations() from .patch_wagtailadmin import patch_wagtail_models patch_wagtail_models()
def ready(self): from django.conf import settings from modeltranslation import settings as mt_settings # Add Wagtail defined fields as modeltranslation custom fields 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', tuple()) setattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', tuple(set(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() from .patch_wagtailadmin import patch_wagtail_models patch_wagtail_models()
def setUpClass(cls): """ Prepare database: * Call syncdb to create tables for tests.models (since during default testrunner's db creation wagtail_modeltranslation.tests was not in INSTALLED_APPS """ super(WagtailModeltranslationTransactionTestBase, cls).setUpClass() if not WagtailModeltranslationTransactionTestBase.synced: # In order to perform only one syncdb WagtailModeltranslationTransactionTestBase.synced = True mgr = dummy_context_mgr() with mgr: # 1. Reload translation in case USE_I18N was False from django.utils import translation as dj_trans imp.reload(dj_trans) # 2. Reload MT because LANGUAGES likely changed. imp.reload(mt_settings) imp.reload(translator) # reload the translation module to register the Page model # and also edit_handlers so any patches made to Page are reapplied import sys del cls.cache.all_models['wagtailcore'] sys.modules.pop('wagtail_modeltranslation.translation.pagetr', None) from wagtail_modeltranslation import translation as wag_translation try: from wagtail.admin import edit_handlers sys.modules.pop('wagtail.core.models', None) except ImportError: from wagtail.wagtailadmin import edit_handlers sys.modules.pop('wagtail.wagtailcore.models', None) imp.reload(wag_translation) imp.reload(edit_handlers) # so Page can be repatched by edit_handlers wagtailcore_args = [] if django.VERSION < (1, 11): wagtailcore_args = [cls.cache.all_models['wagtailcore']] cls.cache.get_app_config('wagtailcore').import_models(*wagtailcore_args) # Reload the patching class to update the imported translator # in order to include the newly registered models from wagtail_modeltranslation import patch_wagtailadmin imp.reload(patch_wagtailadmin) # 3. Reset test models (because autodiscover have already run, those models # have translation fields, but for languages previously defined. We want # to be sure that 'de' and 'en' are available) del cls.cache.all_models['tests'] sys.modules.pop('wagtail_modeltranslation.tests.models', None) sys.modules.pop('wagtail_modeltranslation.tests.translation', None) tests_args = [] if django.VERSION < (1, 11): tests_args = [cls.cache.all_models['tests']] cls.cache.get_app_config('tests').import_models(*tests_args) # 4. Autodiscover from modeltranslation.models import handle_translation_registrations handle_translation_registrations() # 5. makemigrations from django.db import connections, DEFAULT_DB_ALIAS call_command('makemigrations', verbosity=2, interactive=False) # 6. Syncdb call_command('migrate', verbosity=0, interactive=False, run_syncdb=True, database=connections[DEFAULT_DB_ALIAS].alias) # 7. Make sure Page translation fields are created call_command('sync_page_translation_fields', interactive=False, verbosity=0) # 8. patch wagtail models from wagtail_modeltranslation.patch_wagtailadmin import patch_wagtail_models patch_wagtail_models() # A rather dirty trick to import models into module namespace, but not before # tests app has been added into INSTALLED_APPS and loaded # (that's why this is not imported in normal import section) global models, translation from wagtail_modeltranslation.tests import models, translation # NOQA
def setUpClass(cls): """ Prepare database: * Call syncdb to create tables for tests.models (since during default testrunner's db creation wagtail_modeltranslation.tests was not in INSTALLED_APPS """ super(WagtailModeltranslationTransactionTestBase, cls).setUpClass() if not WagtailModeltranslationTransactionTestBase.synced: # In order to perform only one syncdb WagtailModeltranslationTransactionTestBase.synced = True mgr = (override_settings(**TEST_SETTINGS) if django.VERSION < (1, 8) else dummy_context_mgr()) with mgr: # 1. Reload translation in case USE_I18N was False from django.utils import translation as dj_trans imp.reload(dj_trans) # 2. Reload MT because LANGUAGES likely changed. imp.reload(mt_settings) imp.reload(translator) # reload the translation module to register the Page model from wagtail_modeltranslation import translation as wag_translation, translator as wag_translator imp.reload(wag_translation) imp.reload(wag_translator) # Reload the patching class to update the imported translator # in order to include the newly registered models from wagtail_modeltranslation import patch_wagtailadmin imp.reload(patch_wagtailadmin) # 3. Reset test models (because autodiscover have already run, those models # have translation fields, but for languages previously defined. We want # to be sure that 'de' and 'en' are available) del cls.cache.all_models['tests'] import sys sys.modules.pop('wagtail_modeltranslation.tests.models', None) sys.modules.pop('wagtail_modeltranslation.tests.translation', None) cls.cache.get_app_config('tests').import_models(cls.cache.all_models['tests']) # 4. Autodiscover from modeltranslation.models import handle_translation_registrations handle_translation_registrations() # 5. makemigrations from django.db import connections, DEFAULT_DB_ALIAS call_command('makemigrations', verbosity=2, interactive=False, database=connections[DEFAULT_DB_ALIAS].alias) # 6. Syncdb call_command('migrate', verbosity=0, migrate=False, interactive=False, run_syncdb=True, database=connections[DEFAULT_DB_ALIAS].alias, load_initial_data=False) # 7. patch wagtail models from wagtail_modeltranslation.patch_wagtailadmin import patch_wagtail_models patch_wagtail_models() # A rather dirty trick to import models into module namespace, but not before # tests app has been added into INSTALLED_APPS and loaded # (that's why this is not imported in normal import section) global models, translation from wagtail_modeltranslation.tests import models, translation
def ready(self): from modeltranslation.models import handle_translation_registrations handle_translation_registrations()
def setUpClass(cls): """ Prepare database: * Call syncdb to create tables for tests.models (since during default testrunner's db creation wagtail_modeltranslation.tests was not in INSTALLED_APPS """ super(WagtailModeltranslationTransactionTestBase, cls).setUpClass() if not WagtailModeltranslationTransactionTestBase.synced: # In order to perform only one syncdb WagtailModeltranslationTransactionTestBase.synced = True mgr = (override_settings(**TEST_SETTINGS) if django.VERSION < (1, 8) else dummy_context_mgr()) with mgr: # 1. Reload translation in case USE_I18N was False from django.utils import translation as dj_trans imp.reload(dj_trans) # 2. Reload MT because LANGUAGES likely changed. imp.reload(mt_settings) imp.reload(translator) # reload the translation module to register the Page model from wagtail_modeltranslation import translation as wag_translation, translator as wag_translator imp.reload(wag_translation) imp.reload(wag_translator) # Reload the patching class to update the imported translator # in order to include the newly registered models from wagtail_modeltranslation import patch_wagtailadmin imp.reload(patch_wagtailadmin) # 3. Reset test models (because autodiscover have already run, those models # have translation fields, but for languages previously defined. We want # to be sure that 'de' and 'en' are available) del cls.cache.all_models['tests'] import sys sys.modules.pop('wagtail_modeltranslation.tests.models', None) sys.modules.pop('wagtail_modeltranslation.tests.translation', None) cls.cache.get_app_config('tests').import_models(cls.cache.all_models['tests']) # 4. Autodiscover from modeltranslation.models import handle_translation_registrations handle_translation_registrations() # 5. makemigrations from django.db import connections, DEFAULT_DB_ALIAS call_command('makemigrations', verbosity=2, interactive=False, database=connections[DEFAULT_DB_ALIAS].alias) # 6. Syncdb call_command('migrate', verbosity=0, migrate=False, interactive=False, run_syncdb=True, database=connections[DEFAULT_DB_ALIAS].alias, load_initial_data=False) # 7. patch wagtail models from wagtail_modeltranslation.patch_wagtailadmin import patch_wagtail_models patch_wagtail_models() # A rather dirty trick to import models into module namespace, but not before # tests app has been added into INSTALLED_APPS and loaded # (that's why this is not imported in normal import section) global models, translation from wagtail_modeltranslation.tests import models, translation
def setUpClass(cls): """ Prepare database: * Call syncdb to create tables for tests.models (since during default testrunner's db creation wagtail_modeltranslation.tests was not in INSTALLED_APPS """ super(WagtailModeltranslationTransactionTestBase, cls).setUpClass() if not WagtailModeltranslationTransactionTestBase.synced: # In order to perform only one syncdb WagtailModeltranslationTransactionTestBase.synced = True mgr = dummy_context_mgr() with mgr: # 1. Reload translation in case USE_I18N was False from django.utils import translation as dj_trans imp.reload(dj_trans) # 2. Reload MT because LANGUAGES likely changed. imp.reload(mt_settings) imp.reload(translator) # reload the translation module to register the Page model # and also edit_handlers so any patches made to Page are reapplied import sys del cls.cache.all_models['wagtailcore'] sys.modules.pop('wagtail_modeltranslation.translation.pagetr', None) from wagtail_modeltranslation import translation as wag_translation try: from wagtail.admin import edit_handlers sys.modules.pop('wagtail.core.models', None) except ImportError: from wagtail.wagtailadmin import edit_handlers sys.modules.pop('wagtail.wagtailcore.models', None) imp.reload(wag_translation) imp.reload( edit_handlers) # so Page can be repatched by edit_handlers wagtailcore_args = [] if django.VERSION < (1, 11): wagtailcore_args = [cls.cache.all_models['wagtailcore']] cls.cache.get_app_config('wagtailcore').import_models( *wagtailcore_args) # Reload the patching class to update the imported translator # in order to include the newly registered models from wagtail_modeltranslation import patch_wagtailadmin imp.reload(patch_wagtailadmin) # 3. Reset test models (because autodiscover have already run, those models # have translation fields, but for languages previously defined. We want # to be sure that 'de' and 'en' are available) del cls.cache.all_models['tests'] sys.modules.pop('wagtail_modeltranslation.tests.models', None) sys.modules.pop('wagtail_modeltranslation.tests.translation', None) tests_args = [] if django.VERSION < (1, 11): tests_args = [cls.cache.all_models['tests']] cls.cache.get_app_config('tests').import_models(*tests_args) # 4. Autodiscover from modeltranslation.models import handle_translation_registrations handle_translation_registrations() # 5. makemigrations from django.db import connections, DEFAULT_DB_ALIAS call_command('makemigrations', verbosity=2, interactive=False) # 6. Syncdb call_command('migrate', verbosity=0, interactive=False, run_syncdb=True, database=connections[DEFAULT_DB_ALIAS].alias) # 7. Make sure Page translation fields are created call_command('sync_page_translation_fields', interactive=False, verbosity=0) # 8. patch wagtail models from wagtail_modeltranslation.patch_wagtailadmin import patch_wagtail_models patch_wagtail_models() # A rather dirty trick to import models into module namespace, but not before # tests app has been added into INSTALLED_APPS and loaded # (that's why this is not imported in normal import section) global models, translation from wagtail_modeltranslation.tests import models, translation # NOQA