当前位置: 首页>>代码示例>>Python>>正文


Python LanguageSelectorViewlet.available方法代码示例

本文整理汇总了Python中plone.app.multilingual.browser.selector.LanguageSelectorViewlet.available方法的典型用法代码示例。如果您正苦于以下问题:Python LanguageSelectorViewlet.available方法的具体用法?Python LanguageSelectorViewlet.available怎么用?Python LanguageSelectorViewlet.available使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plone.app.multilingual.browser.selector.LanguageSelectorViewlet的用法示例。


在下文中一共展示了LanguageSelectorViewlet.available方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_selector_viewlet_is_available_but_tool_is_not

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import available [as 别名]
 def test_selector_viewlet_is_available_but_tool_is_not(self):
     selector_viewlet = LanguageSelectorViewlet(
         self.portal, self.request, None, None
     )
     selector_viewlet.update()
     selector_viewlet.tool = None
     self.assertFalse(selector_viewlet.available())
开发者ID:plone,项目名称:plone.app.multilingual,代码行数:9,代码来源:test_selector.py

示例2: TestLanguageSelectorBasics

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import available [as 别名]
class TestLanguageSelectorBasics(unittest.TestCase):

    layer = PLONEAPPMULTILINGUAL_FUNCTIONAL_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        self.portal.error_log._ignored_exceptions = ()
        self.request = self.layer['request']
        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        self.portal_url = self.portal.absolute_url()
        self.language_tool = getToolByName(self.portal, 'portal_languages')
        self.language_tool.addSupportedLanguage('ca')
        self.language_tool.addSupportedLanguage('es')

        self.selector = LanguageSelectorViewlet(self.portal,
                            self.request, None, None)

    def test_available(self):
        self.selector.update()
        self.assertEquals(self.selector.available(), True)

    def test_available_no_tool(self):
        self.selector.update()
        self.selector.tool = None
        self.assertEquals(self.selector.available(), False)

    def test_original_selector_data_not_modified_by_viewlet(self):
        self.selector.update()
        multilingual_lang_info = self.selector.languages()
        original_selector = LanguageSelector(self.portal,
                            self.request, None, None)
        original_selector.update()
        original_lang_info = original_selector.languages()

        self.assertNotEquals(original_lang_info, multilingual_lang_info)

    def assertFullyTranslatedPages(self):
        doc1 = makeContent(self.portal, 'Document', id='doc1')
        doc1.setLanguage('en')
        doc1_tg = ITG(doc1)
        doc1_ca = makeTranslation(doc1, 'ca')
        doc1_ca.edit(title="Foo", language='ca')
        doc1_es = makeTranslation(doc1, 'es')
        doc1_es.edit(title="Foo", language='es')

        self.selector = LanguageSelectorViewlet(doc1,
                            self.request, None, None)

        self.selector.update()
        selector_languages = self.selector.languages()
        self.assertEqual(selector_languages, [
            {
                'code': u'en',
                u'name': u'English',
                'url': SELECTOR_VIEW_TEMPLATE % {
                    'url': self.portal_url,
                    'tg': doc1_tg,
                    'lang': 'en',
                    'query': '?set_language=en'
                },
                'selected': True,
                u'flag': u'/++resource++country-flags/gb.gif',
                'translated': True,
                u'native': u'English'
            },
            {
                'code': u'ca',
                u'name': u'Catalan',
                'url': SELECTOR_VIEW_TEMPLATE % {
                    'url': self.portal_url,
                    'tg': doc1_tg,
                    'lang': 'ca',
                    'query': '?set_language=ca'
                },
                'selected': False,
                u'flag': u'/++resource++language-flags/ca.gif',
                'translated': True,
                u'native': u'Catal\xe0'
            },
            {
                'code': u'es',
                u'name': u'Spanish',
                'url': SELECTOR_VIEW_TEMPLATE % {
                    'url': self.portal_url,
                    'tg': doc1_tg,
                    'lang': 'es',
                    'query': '?set_language=es'
                },
                'selected': False,
                u'flag': u'/++resource++country-flags/es.gif',
                'translated': True,
                u'native': u'Espa\xf1ol'
            }
        ])

        self.browser.open(selector_languages[0]['url'])
        self.assertEqual(
            self.browser.url,
            doc1.absolute_url() + '?set_language=en'
#.........这里部分代码省略.........
开发者ID:khink,项目名称:plone.app.multilingual,代码行数:103,代码来源:test_selector.py

示例3: test_selector_viewlet_is_available

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import available [as 别名]
 def test_selector_viewlet_is_available(self):
     selector_viewlet = \
         LanguageSelectorViewlet(self.portal, self.request, None, None)
     selector_viewlet.update()
     self.assertTrue(selector_viewlet.available())
开发者ID:PythonUnited,项目名称:plone.app.multilingual,代码行数:7,代码来源:test_selector.py

示例4: TestLanguageSelectorBasics

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import available [as 别名]
class TestLanguageSelectorBasics(unittest.TestCase):

    layer = PLONEAPPMULTILINGUAL_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        self.portal_url = self.portal.absolute_url()
        self.language_tool = getToolByName(self.portal, 'portal_languages')
        self.language_tool.addSupportedLanguage('ca')
        self.language_tool.addSupportedLanguage('es')

        self.selector = LanguageSelectorViewlet(self.portal,
                            self.request, None, None)

    def test_available(self):
        self.selector.update()
        self.assertEquals(self.selector.available(), True)

    def test_available_no_tool(self):
        self.selector.update()
        self.selector.tool = None
        self.assertEquals(self.selector.available(), False)

    def test_original_selector_data_not_modified_by_viewlet(self):
        self.selector.update()
        multilingual_lang_info = self.selector.languages()
        original_selector = LanguageSelector(self.portal,
                            self.request, None, None)
        original_selector.update()
        original_lang_info = original_selector.languages()

        self.assertNotEquals(original_lang_info, multilingual_lang_info)

    def test_languages_full_translated_by_closest(self):
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(IMultiLanguagePolicies)
        self.settings.selector_lookup_translations_policy = 'closest'

        doc1 = makeContent(self.portal, 'Document', id='doc1')
        doc1.setLanguage('en')
        doc1_ca = makeTranslation(doc1, 'ca')
        doc1_ca.edit(title="Foo", language='ca')
        doc1_es = makeTranslation(doc1, 'es')
        doc1_es.edit(title="Foo", language='es')

        self.selector = LanguageSelectorViewlet(doc1,
                            self.request, None, None)

        self.selector.update()

        self.assertEqual(self.selector.languages(), [
            {'code': u'en',
             u'name': u'English',
             'url': 'http://nohost/plone/doc1?set_language=en',
             'selected': True,
             u'flag': u'/++resource++country-flags/gb.gif',
             'translated': True,
             u'native': u'English'},
             {'code': u'ca',
              u'name': u'Catalan',
              'url': 'http://nohost/plone/doc1-ca?set_language=ca',
              'selected': False,
              u'flag': u'/++resource++language-flags/ca.gif',
              'translated': True,
              u'native': u'Catal\xe0'},
              {'code': u'es',
              u'name': u'Spanish',
              'url': 'http://nohost/plone/doc1-es?set_language=es',
              'selected': False,
              u'flag': u'/++resource++country-flags/es.gif',
              'translated': True,
              u'native': u'Espa\xf1ol'}
        ])

    def test_languages_partially_translated_by_dialog(self):
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(IMultiLanguagePolicies)
        self.settings.selector_lookup_translations_policy = 'dialog'

        p1 = makeContent(self.portal, 'Document', id='partial')
        p1.setLanguage('en')
        p1_ca = makeTranslation(p1, 'ca')
        p1_ca.edit(title="Foo ca", language='ca')

        self.selector = LanguageSelectorViewlet(p1,
                            self.request, None, None)

        self.selector.update()

        self.assertEqual(self.selector.languages(), [
            {'code': u'en',
             u'name': u'English',
             'url': 'http://nohost/plone/partial?set_language=en',
             'selected': True,
             u'flag': u'/++resource++country-flags/gb.gif',
             'translated': True,
             u'native': u'English'},
             {'code': u'ca',
             u'name': u'Catalan',
#.........这里部分代码省略.........
开发者ID:adam139,项目名称:devplone422,代码行数:103,代码来源:test_selector.py


注:本文中的plone.app.multilingual.browser.selector.LanguageSelectorViewlet.available方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。