Пример #1
0
def create_new_resources_index_page(apps, schema_editor):
    '''
    Transfer data from the resource page (an instance of RTEIPage) to a new
    instance of ResourceIndexPage. This deletes the old resources (RTEIPage) page.
    '''
    from rtei.translation import RTEIPageTR, ResourceIndexPageTR
    from wagtail_modeltranslation.translator import translator
    from django.contrib.contenttypes.models import ContentType

    RTEIPage = apps.get_model("rtei", "RTEIPage")
    translator.register(RTEIPage, RTEIPageTR)
    ResourceIndexPage = apps.get_model('rtei', 'ResourceIndexPage')
    translator.register(ResourceIndexPage, ResourceIndexPageTR)

    resource_index_page_content_type = ContentType.objects.get_for_model(
        ResourceIndexPage)

    old_resources_page = RTEIPage.objects.get(slug='resources')
    old_resources_page.delete()

    d = {
        'slug': old_resources_page.slug,
        'slug_en': old_resources_page.slug_en,
        'slug_fr': old_resources_page.slug_fr,
        'slug_es': old_resources_page.slug_es,
        'slug_ar': old_resources_page.slug_ar,
        'numchild': old_resources_page.numchild,
        'title': old_resources_page.title,
        'title_en': old_resources_page.title_en,
        'title_fr': old_resources_page.title_fr,
        'title_es': old_resources_page.title_es,
        'title_ar': old_resources_page.title_ar,
        'url_path': old_resources_page.url_path,
        'url_path_en': old_resources_page.url_path_en,
        'url_path_fr': old_resources_page.url_path_fr,
        'url_path_es': old_resources_page.url_path_es,
        'url_path_ar': old_resources_page.url_path_ar,
        'show_in_menus': old_resources_page.show_in_menus,
        'path': old_resources_page.path,
        'depth': old_resources_page.depth,
        'content_type_id': resource_index_page_content_type.id
    }

    new_resources_page = ResourceIndexPage(**d)
    new_resources_page.save()
Пример #2
0
def create_new_resources_index_page(apps, schema_editor):
    '''
    Transfer data from the resource page (an instance of RTEIPage) to a new
    instance of ResourceIndexPage. This deletes the old resources (RTEIPage) page.
    '''
    from rtei.translation import RTEIPageTR, ResourceIndexPageTR
    from wagtail_modeltranslation.translator import translator
    from django.contrib.contenttypes.models import ContentType

    RTEIPage = apps.get_model("rtei", "RTEIPage")
    translator.register(RTEIPage, RTEIPageTR)
    ResourceIndexPage = apps.get_model('rtei', 'ResourceIndexPage')
    translator.register(ResourceIndexPage, ResourceIndexPageTR)

    resource_index_page_content_type = ContentType.objects.get_for_model(ResourceIndexPage)

    old_resources_page = RTEIPage.objects.get(slug='resources')
    old_resources_page.delete()

    d = {
        'slug': old_resources_page.slug,
        'slug_en': old_resources_page.slug_en,
        'slug_fr': old_resources_page.slug_fr,
        'slug_es': old_resources_page.slug_es,
        'slug_ar': old_resources_page.slug_ar,
        'numchild': old_resources_page.numchild,
        'title': old_resources_page.title,
        'title_en': old_resources_page.title_en,
        'title_fr': old_resources_page.title_fr,
        'title_es': old_resources_page.title_es,
        'title_ar': old_resources_page.title_ar,
        'url_path': old_resources_page.url_path,
        'url_path_en': old_resources_page.url_path_en,
        'url_path_fr': old_resources_page.url_path_fr,
        'url_path_es': old_resources_page.url_path_es,
        'url_path_ar': old_resources_page.url_path_ar,
        'show_in_menus': old_resources_page.show_in_menus,
        'path': old_resources_page.path,
        'depth': old_resources_page.depth,
        'content_type_id': resource_index_page_content_type.id
    }

    new_resources_page = ResourceIndexPage(**d)
    new_resources_page.save()
    RichText, RichTextPage, MultitableModelA, MultitableModelB, MultitableModelC, ManagerTestModel,
    CustomManagerTestModel, CustomManager2TestModel, GroupFieldsetsModel, NameModel,
    ThirdPartyRegisteredModel, ProxyTestModel, UniqueNullableModel, OneToOneFieldModel,
    RequiredModel, DecoratedModel, TestRootPage, TestSlugPage1, TestSlugPage2, PatchTestPage, PatchTestSnippet,
    FieldPanelPage, ImageChooserPanelPage, FieldRowPanelPage, MultiFieldPanelPage, InlinePanelPage,
    FieldPanelSnippet, ImageChooserPanelSnippet, FieldRowPanelSnippet, MultiFieldPanelSnippet, PageInlineModel,
    BaseInlineModel, StreamFieldPanelPage, StreamFieldPanelSnippet, SnippetInlineModel, InlinePanelSnippet)
from wagtail_modeltranslation.translator import translator, register, TranslationOptions


class TestTranslationOptions(TranslationOptions):
    fields = ('title', 'text', 'url', 'email',)
    empty_values = ''


translator.register(TestModel, TestTranslationOptions)


class UniqueNullableTranslationOptions(TranslationOptions):
    fields = ('title',)


translator.register(UniqueNullableModel, UniqueNullableTranslationOptions)


# ######### Proxy model testing

class ProxyTestTranslationOptions(TranslationOptions):
    fields = ('title', 'text', 'url', 'email',)

from wagtail_modeltranslation.translator import translator, TranslationOptions
from .test_app.models import Other


class OtherTranslationOptions(TranslationOptions):
    fields = ('name', )


translator.register(Other, OtherTranslationOptions)
from wagtail_modeltranslation.translator import translator, TranslationOptions
from .models import News


class NewsTranslationOptions(TranslationOptions):
    fields = ('title',)


translator.register(News, NewsTranslationOptions)
from wagtail_modeltranslation.translator import translator, TranslationOptions
from .test_app.models import Other


class OtherTranslationOptions(TranslationOptions):
    fields = ("name",)


translator.register(Other, OtherTranslationOptions)
    PageInlineModel, BaseInlineModel, StreamFieldPanelPage,
    StreamFieldPanelSnippet, SnippetInlineModel, InlinePanelSnippet)
from wagtail_modeltranslation.translator import translator, register, TranslationOptions


class TestTranslationOptions(TranslationOptions):
    fields = (
        'title',
        'text',
        'url',
        'email',
    )
    empty_values = ''


translator.register(TestModel, TestTranslationOptions)


class UniqueNullableTranslationOptions(TranslationOptions):
    fields = ('title', )


translator.register(UniqueNullableModel, UniqueNullableTranslationOptions)

# ######### Proxy model testing


class ProxyTestTranslationOptions(TranslationOptions):
    fields = (
        'title',
        'text',
Пример #8
0
 def wrapper(opts_class):
     if not issubclass(opts_class, TranslationOptions):
         raise ValueError('Wrapped class must subclass TranslationOptions.')
     translator.register(model_or_iterable, opts_class, **options)