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


Python api.add_plugin方法代码示例

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


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

示例1: test_copy_filled_placeholder

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_copy_filled_placeholder(self):
        """
        If an existing title in the target language has plugins in a placeholder
        that placeholder is skipped
        """
        site = 1
        number_start_plugins = CMSPlugin.objects.all().count()

        # create an empty title language
        root_page = Page.objects.on_site(site).get_home()
        create_title("de", "root page de", root_page)
        ph = root_page.placeholders.get(slot="body")
        add_plugin(ph, "TextPlugin", "de", body="Hello World")

        out = StringIO()
        management.call_command(
            'cms', 'copy', 'lang', '--from-lang=en', '--to-lang=de', interactive=False, stdout=out
        )

        self.assertEqual(CMSPlugin.objects.filter(language='en').count(), number_start_plugins)
        # one placeholder (with 7 plugins) is skipped, so the difference must be 6
        self.assertEqual(CMSPlugin.objects.filter(language='de').count(), number_start_plugins-6) 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:24,代码来源:test_management.py

示例2: add_text

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def add_text(page, language, content, n=1):
    """
    Adds n text plugins to each placeholder in the page
    :param content:
    :param page:
    :param language:
    :param n:
    :return: the created plugin instances
    """
    plugins = []
    # put three text plugins in each placeholder
    for i, ph in enumerate(page.placeholders.all()):
        for language in page.get_languages():
            for j in range(n):
                plugin = add_plugin(ph, TextPlugin, language, body=content)
                plugins.append(plugin)
    make_page_version_dirty(page, language)
    return plugins 
开发者ID:Blueshoe,项目名称:djangocms-reversion2,代码行数:20,代码来源:testutils.py

示例3: test_plugin_loading_queries

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_plugin_loading_queries(self):
        with self.settings(CMS_TEMPLATES=(('placeholder_tests/base.html', 'tpl'),)):
            page = create_page('home', 'placeholder_tests/base.html', 'en', published=True, slug='home')
            placeholders = list(page.placeholders.all())
            for i, placeholder in enumerate(placeholders):
                for j in range(5):
                    add_plugin(placeholder, TextPlugin, 'en', body='text-%d-%d' % (i, j))
                    add_plugin(placeholder, LinkPlugin, 'en', name='link-%d-%d' % (i, j))

            # trigger the apphook query so that it doesn't get in our way
            reverse('pages-root')
            # trigger the get_languages query so it doesn't get in our way
            context = self.get_context(page=page)
            context['request'].current_page.get_languages()
            with self.assertNumQueries(4):
                for i, placeholder in enumerate(placeholders):
                    content = get_placeholder_content(context, context['request'], page, placeholder.slot, False, None)
                    for j in range(5):
                        self.assertIn('text-%d-%d' % (i, j), content)
                        self.assertIn('link-%d-%d' % (i, j), content) 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:22,代码来源:test_page.py

示例4: test_type_limit_on_plugin_move

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_type_limit_on_plugin_move(self):
        admin = self.get_admin()
        superuser = self.get_superuser()
        cms_page = self.get_page()
        source_placeholder = cms_page.placeholders.get(slot='right-column')
        target_placeholder = cms_page.placeholders.get(slot='body')
        data = {
            'placeholder': source_placeholder,
            'plugin_type': 'TextPlugin',
            'language': 'en',
        }
        plugin_1 = add_plugin(**data)
        plugin_2 = add_plugin(**data)
        with UserLoginContext(self, superuser):
            with self.settings(CMS_PLACEHOLDER_CONF=self.placeholderconf):
                request = self.get_post_request(
                    {'placeholder_id': target_placeholder.pk, 'plugin_id': plugin_1.pk, 'plugin_parent': ''})
                response = admin.move_plugin(request) # first
                self.assertEqual(response.status_code, 200)
                request = self.get_post_request(
                    {'placeholder_id': target_placeholder.pk, 'plugin_id': plugin_2.pk, 'plugin_parent': ''})
                response = admin.move_plugin(request) # second
                self.assertEqual(response.status_code, 400)
                self.assertEqual(response.content,
                                 b"This placeholder already has the maximum number (1) of allowed Text plugins.") 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:27,代码来源:test_page.py

示例5: test_plugin_order

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_plugin_order(self):
        """
        Test that plugin position is saved after creation
        """
        page_en = api.create_page("PluginOrderPage", "col_two.html", "en",
                                  slug="page1", published=True, in_navigation=True)
        ph_en = page_en.placeholders.get(slot="col_left")

        # We check created objects and objects from the DB to be sure the position value
        # has been saved correctly
        text_plugin_1 = api.add_plugin(ph_en, "TextPlugin", "en", body="I'm the first")
        text_plugin_2 = api.add_plugin(ph_en, "TextPlugin", "en", body="I'm the second")
        db_plugin_1 = CMSPlugin.objects.get(pk=text_plugin_1.pk)
        db_plugin_2 = CMSPlugin.objects.get(pk=text_plugin_2.pk)

        with self.settings(CMS_PERMISSION=False):
            self.assertEqual(text_plugin_1.position, 0)
            self.assertEqual(db_plugin_1.position, 0)
            self.assertEqual(text_plugin_2.position, 1)
            self.assertEqual(db_plugin_2.position, 1)
            ## Finally we render the placeholder to test the actual content
            rendered_placeholder = ph_en.render(self.get_context(page_en.get_absolute_url(), page=page_en), None)
            self.assertEqual(rendered_placeholder, "I'm the firstI'm the second") 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:25,代码来源:test_plugins.py

示例6: test_plugin_breadcrumbs

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_plugin_breadcrumbs(self):
        """
        Test the plugin breadcrumbs order
        """
        draft_page = api.create_page("home", "col_two.html", "en",
                                     slug="page1", published=False, in_navigation=True)
        placeholder = draft_page.placeholders.get(slot="col_left")

        columns = api.add_plugin(placeholder, "MultiColumnPlugin", "en")
        column = api.add_plugin(placeholder, "ColumnPlugin", "en", target=columns, width='10%')
        text_plugin = api.add_plugin(placeholder, "TextPlugin", "en", target=column, body="I'm the second")
        text_breadcrumbs = text_plugin.get_breadcrumb()
        self.assertEqual(len(columns.get_breadcrumb()), 1)
        self.assertEqual(len(column.get_breadcrumb()), 2)
        self.assertEqual(len(text_breadcrumbs), 3)
        self.assertTrue(text_breadcrumbs[0]['title'], columns.get_plugin_class().name)
        self.assertTrue(text_breadcrumbs[1]['title'], column.get_plugin_class().name)
        self.assertTrue(text_breadcrumbs[2]['title'], text_plugin.get_plugin_class().name)
        self.assertTrue('/edit-plugin/%s/'% columns.pk in text_breadcrumbs[0]['url'])
        self.assertTrue('/edit-plugin/%s/'% column.pk, text_breadcrumbs[1]['url'])
        self.assertTrue('/edit-plugin/%s/'% text_plugin.pk, text_breadcrumbs[2]['url']) 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:23,代码来源:test_plugins.py

示例7: test_inherit_plugin_with_empty_plugin

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_inherit_plugin_with_empty_plugin(self):
        inheritfrompage = api.create_page('page to inherit from',
                                          'nav_playground.html',
                                          'en', published=True)

        body = inheritfrompage.placeholders.get(slot="body")
        empty_plugin = CMSPlugin(
            plugin_type='TextPlugin', # create an empty plugin
            placeholder=body,
            position=1,
            language='en',
        )
        empty_plugin.add_root(instance=empty_plugin)
        other_page = api.create_page('other page', 'nav_playground.html', 'en', published=True)
        inherited_body = other_page.placeholders.get(slot="body")

        api.add_plugin(inherited_body, InheritPagePlaceholderPlugin, 'en', position='last-child',
                       from_page=inheritfrompage, from_language='en')

        api.add_plugin(inherited_body, "TextPlugin", "en", body="foobar")
        # this should not fail, even if there in an empty plugin
        rendered = inherited_body.render(context=self.get_context(other_page.get_absolute_url(), page=other_page), width=200)
        self.assertIn("foobar", rendered) 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:25,代码来源:test_plugins.py

示例8: test_plugin_child_classes_from_settings

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_plugin_child_classes_from_settings(self):
        page = api.create_page("page", "nav_playground.html", "en", published=True)
        placeholder = page.placeholders.get(slot='body')
        ChildClassesPlugin = type('ChildClassesPlugin', (CMSPluginBase,),
                                  dict(child_classes=['TextPlugin'], render_template='allow_children_plugin.html'))
        plugin_pool.register_plugin(ChildClassesPlugin)
        plugin = api.add_plugin(placeholder, ChildClassesPlugin, settings.LANGUAGES[0][0])
        plugin = plugin.get_plugin_class_instance()
        ## assert baseline
        self.assertEqual(['TextPlugin'], plugin.get_child_classes(placeholder.slot, page))

        CMS_PLACEHOLDER_CONF = {
            'body': {
                'child_classes': {
                    'ChildClassesPlugin': ['LinkPlugin', 'PicturePlugin'],
                }
            }
        }
        with self.settings(CMS_PLACEHOLDER_CONF=CMS_PLACEHOLDER_CONF):
            self.assertEqual(['LinkPlugin', 'PicturePlugin'],
                             plugin.get_child_classes(placeholder.slot, page))
        plugin_pool.unregister_plugin(ChildClassesPlugin) 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:24,代码来源:test_plugins.py

示例9: test_plugin_parent_classes_from_settings

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_plugin_parent_classes_from_settings(self):
        page = api.create_page("page", "nav_playground.html", "en", published=True)
        placeholder = page.placeholders.get(slot='body')
        ParentClassesPlugin = type('ParentClassesPlugin', (CMSPluginBase,),
                                   dict(parent_classes=['TextPlugin'], render_plugin=False))
        plugin_pool.register_plugin(ParentClassesPlugin)
        plugin = api.add_plugin(placeholder, ParentClassesPlugin, settings.LANGUAGES[0][0])
        plugin = plugin.get_plugin_class_instance()
        ## assert baseline
        self.assertEqual(['TextPlugin'], plugin.get_parent_classes(placeholder.slot, page))

        CMS_PLACEHOLDER_CONF = {
            'body': {
                'parent_classes': {
                    'ParentClassesPlugin': ['TestPlugin'],
                }
            }
        }
        with self.settings(CMS_PLACEHOLDER_CONF=CMS_PLACEHOLDER_CONF):
            self.assertEqual(['TestPlugin'],
                             plugin.get_parent_classes(placeholder.slot, page))
        plugin_pool.unregister_plugin(ParentClassesPlugin) 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:24,代码来源:test_plugins.py

示例10: test_copy_fk_from_model

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_copy_fk_from_model(self):
        plugin = api.add_plugin(
            placeholder=self.placeholder1,
            plugin_type="PluginWithFKFromModel",
            language=self.FIRST_LANG,
        )
        FKModel.objects.create(fk_field=plugin)
        old_public_count = FKModel.objects.filter(
            fk_field__placeholder__page__publisher_is_draft=False
        ).count()
        api.publish_page(
            self.page1,
            self.super_user,
            self.FIRST_LANG
        )
        new_public_count = FKModel.objects.filter(
            fk_field__placeholder__page__publisher_is_draft=False
        ).count()
        self.assertEqual(
            new_public_count,
            old_public_count + 1
        ) 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:24,代码来源:test_plugins.py

示例11: test_add_child_plugin

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_add_child_plugin(self):
        page_one = create_page(u"Three Placeholder", u"col_three.html", u"en",
                                   position=u"last-child", published=True, in_navigation=True)
        page_one_ph_one = page_one.placeholders.get(slot=u"col_sidebar")
        # add the text plugin to placeholder one
        text_plugin_en = add_plugin(page_one_ph_one, u"TextPlugin", u"en", body=u"Hello World")
        superuser = self.get_superuser()
        with self.login_user_context(superuser):
            # now move the parent text plugin to another placeholder
            post_data = {
                'placeholder_id': page_one_ph_one.id,
                'plugin_type': 'LinkPlugin',
                'plugin_language': 'en',
                'plugin_parent': text_plugin_en.pk,

            }
            add_url = URL_CMS_PLUGIN_PAGE_ADD % page_one.pk
            response = self.client.post(add_url, post_data)
            self.assertEqual(response.status_code, 200)
        link_plugin = CMSPlugin.objects.get(parent_id=text_plugin_en.pk)
        self.assertEqual(link_plugin.parent_id, text_plugin_en.pk)
        self.assertEqual(link_plugin.path, '00010001') 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:24,代码来源:test_nested_plugins.py

示例12: fill_placeholder

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def fill_placeholder(self, placeholder=None):
        if placeholder is None:
            placeholder = Placeholder(slot=u"some_slot")
            placeholder.save()  # a good idea, if not strictly necessary


        # plugin in placeholder
        plugin_1 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"01",
        )
        plugin_1.save()

        # IMPORTANT: plugins must be reloaded, before they can be assigned
        # as a parent. Otherwise, the MPTT structure doesn't seem to rebuild
        # properly.

        # child of plugin_1
        plugin_2 = add_plugin(placeholder, u"TextPlugin", u"en",
                              body=u"02",
        )
        plugin_1 = self.reload(plugin_1)
        plugin_2.parent = plugin_1
        plugin_2.save()
        return placeholder 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:26,代码来源:test_static_placeholder.py

示例13: test_empty

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_empty(self):
        self.assertObjectDoesNotExist(StaticPlaceholder.objects.all(), code='foobar')
        self.assertObjectDoesNotExist(Placeholder.objects.all(), slot='foobar')
        t = Template('{% load cms_tags %}{% static_placeholder "foobar" or %}No Content{% endstatic_placeholder %}')
        rendered = t.render(self.get_context('/'))
        self.assertIn("No Content", rendered)

        t = Template('{% load cms_tags %}{% static_placeholder "" %}')
        rendered = t.render(self.get_context('/'))
        self.assertEqual("", rendered)

        t = Template('{% load cms_tags %}{% static_placeholder code or %}No Content{% endstatic_placeholder %}')
        rendered = t.render(Context({'code': StaticPlaceholder.objects.all()[0]}))
        self.assertIn("No Content", rendered)

        for p in Placeholder.objects.all():
            add_plugin(p, 'TextPlugin', 'en', body='test')
        t = Template('{% load cms_tags %}{% static_placeholder "foobar" or %}No Content{% endstatic_placeholder %}')
        rendered = t.render(self.get_context('/'))
        self.assertNotIn("No Content", rendered)
        self.assertEqual(StaticPlaceholder.objects.filter(site_id__isnull=True, code='foobar').count(), 1) 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:23,代码来源:test_static_placeholder.py

示例14: test_add_plugin_alias

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_add_plugin_alias(self):
        page_en = api.create_page("PluginOrderPage", "col_two.html", "en",
                                  slug="page1", published=True, in_navigation=True)
        ph_en = page_en.placeholders.get(slot="col_left")
        text_plugin_1 = api.add_plugin(ph_en, "TextPlugin", "en", body="I'm the first")
        with self.login_user_context(self.get_superuser()):
            response = self.client.post(admin_reverse('cms_create_alias'), data={'plugin_id': text_plugin_1.pk})
            self.assertEqual(response.status_code, 200)
            response = self.client.post(admin_reverse('cms_create_alias'), data={'placeholder_id': ph_en.pk})
            self.assertEqual(response.status_code, 200)
            response = self.client.post(admin_reverse('cms_create_alias'))
            self.assertEqual(response.status_code, 400)
            response = self.client.post(admin_reverse('cms_create_alias'), data={'plugin_id': 20000})
            self.assertEqual(response.status_code, 400)
            response = self.client.post(admin_reverse('cms_create_alias'), data={'placeholder_id': 20000})
            self.assertEqual(response.status_code, 400)
        response = self.client.post(admin_reverse('cms_create_alias'), data={'plugin_id': text_plugin_1.pk})
        self.assertEqual(response.status_code, 403)
        instance = AliasPluginModel.objects.all()[0]
        admin = AliasPlugin()
        request = self.get_request("/")
        context = Context({'request': request})
        admin.render(context, instance, ph_en)
        self.assertEqual(context['content'], "I'm the first") 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:26,代码来源:test_alias.py

示例15: test_inter_placeholder_plugin_move

# 需要导入模块: from cms import api [as 别名]
# 或者: from cms.api import add_plugin [as 别名]
def test_inter_placeholder_plugin_move(self):
        ex = TwoPlaceholderExample(
            char_1='one',
            char_2='two',
            char_3='tree',
            char_4='four'
        )
        ex.save()
        ph1 = ex.placeholder_1
        ph2 = ex.placeholder_2
        ph1_pl1 = add_plugin(ph1, TextPlugin, 'en', body='ph1 plugin1').cmsplugin_ptr
        ph1_pl2 = add_plugin(ph1, TextPlugin, 'en', body='ph1 plugin2').cmsplugin_ptr
        ph1_pl3 = add_plugin(ph1, TextPlugin, 'en', body='ph1 plugin3').cmsplugin_ptr
        ph2_pl1 = add_plugin(ph2, TextPlugin, 'en', body='ph2 plugin1').cmsplugin_ptr
        ph2_pl2 = add_plugin(ph2, TextPlugin, 'en', body='ph2 plugin2').cmsplugin_ptr
        ph2_pl3 = add_plugin(ph2, TextPlugin, 'en', body='ph2 plugin3').cmsplugin_ptr
        response = self.client.post(admin_reverse('placeholderapp_twoplaceholderexample_move_plugin'), {
            'placeholder_id': str(ph2.pk),
            'plugin_id': str(ph1_pl2.pk),
            'plugin_order[]': [str(p.pk) for p in [ph2_pl3, ph2_pl1, ph2_pl2, ph1_pl2]]
        })
        self.assertEqual(response.status_code, 200)
        self.assertEqual([ph1_pl1, ph1_pl3], list(ph1.cmsplugin_set.order_by('position')))
        self.assertEqual([ph2_pl3, ph2_pl1, ph2_pl2, ph1_pl2, ], list(ph2.cmsplugin_set.order_by('position'))) 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:26,代码来源:test_placeholder.py


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