コード例 #1
0
 def setup(self):
     # use a context manager to ensure these settings are
     # only used here
     with override_settings(WAGTAILTRANS_SYNC_TREE=True, WAGTAILTRANS_LANGUAGES_PER_SITE=True):
         register_site_languages()(SiteLanguages)
         self.site = sites.SiteFactory()
         SiteLanguages.for_site(self.site)
         self.default_language = Language.objects.get(code='en')
         self.site.sitelanguages.default_language = self.default_language
コード例 #2
0
ファイル: test_signals.py プロジェクト: yvess/wagtailtrans
    def test_site_languages(self):
        site = sites.SiteFactory()
        SiteLanguages.for_site(site)  # Initialize sitelanguages

        default_language = Language.objects.default()
        lang = language.LanguageFactory(code='nl', is_default=False)
        site.sitelanguages.default_language = lang
        site.sitelanguages.save()

        pages = sites.create_site_tree(language=default_language, site=site)
        homepage = HomePageFactory.build(language=default_language)
        pages[0].add_child(instance=homepage)

        signals.force_parent_language(page=homepage, parent=site.root_page)

        assert homepage.language == lang
コード例 #3
0
ファイル: signals.py プロジェクト: yvess/wagtailtrans
def force_parent_language(**kwargs):
    """Force the initial language of the first page, before creating..

    When adding a homepage to a site, the initial language should be set.
    By default we set the default language from the Languages model, however
    when the languages are defined per site, it's possible that the default
    language differs from the database default.

    """
    page = kwargs.get('page')
    parent = kwargs.get('parent')

    #: Force the page language according to the parent, when the parent
    #: has no language set and is a site root page, force the default language
    #: For now we assume there isn't more than 1 site rooted at the parent.
    if hasattr(parent, 'language'):
        page.language = parent.language
    elif get_wagtailtrans_setting('LANGUAGES_PER_SITE'):
        site = parent.sites_rooted_here.first()
        if site:
            lang_settings = SiteLanguages.for_site(site)
            page.language = lang_settings.default_language or Language.objects.default()