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


Python models.Placeholder类代码示例

本文整理汇总了Python中cms.models.Placeholder的典型用法代码示例。如果您正苦于以下问题:Python Placeholder类的具体用法?Python Placeholder怎么用?Python Placeholder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_05_remove_plugin_not_associated_to_page

    def test_05_remove_plugin_not_associated_to_page(self):
        """
        Test case for PlaceholderField
        """
        page_data = self.get_new_page_data()
        response = self.client.post(URL_CMS_PAGE_ADD, page_data)
        page = Page.objects.all()[0]

        # add a plugin
        plugin_data = {
            'plugin_type':"TextPlugin",
            'language':settings.LANGUAGES[0][0],
            'placeholder':page.placeholders.get(slot="body").pk,
        }
        response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
        
        self.assertEquals(response.status_code, 200)
        self.assertEquals(int(response.content), CMSPlugin.objects.all()[0].pk)
        
        # there should be only 1 plugin
        self.assertEquals(CMSPlugin.objects.all().count(), 1)
        
        ph = Placeholder(slot="subplugin")
        ph.save()
        plugin_data = {
            'plugin_type':"TextPlugin",
            'language':settings.LANGUAGES[0][0],
            'placeholder': ph.pk,
            'parent': int(response.content)
        }
        response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
        # no longer allowed for security reasons
        self.assertEqual(response.status_code, 404)
开发者ID:42,项目名称:django-cms,代码行数:33,代码来源:plugins.py

示例2: test_05_remove_plugin_not_associated_to_page

    def test_05_remove_plugin_not_associated_to_page(self):
        """
        Test case for PlaceholderField
        """
        page_data = self.get_new_page_data()
        response = self.client.post(URL_CMS_PAGE_ADD, page_data)
        page = Page.objects.all()[0]

        # add a plugin
        plugin_data = {
            "plugin_type": "TextPlugin",
            "language": settings.LANGUAGES[0][0],
            "placeholder": page.placeholders.get(slot="body").pk,
        }
        response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)

        self.assertEquals(response.status_code, 200)
        self.assertEquals(int(response.content), CMSPlugin.objects.all()[0].pk)

        # there should be only 1 plugin
        self.assertEquals(CMSPlugin.objects.all().count(), 1)

        ph = Placeholder(slot="subplugin")
        ph.save()
        plugin_data = {
            "plugin_type": "TextPlugin",
            "language": settings.LANGUAGES[0][0],
            "placeholder": ph.pk,
            "parent": int(response.content),
        }
        response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)

        plugin_data = {"plugin_id": int(response.content)}
        response = response.client.post(URL_CMS_PLUGIN_REMOVE, plugin_data)
        self.assertEquals(response.status_code, 200)
开发者ID:kowtowme,项目名称:django-cms,代码行数:35,代码来源:plugins.py

示例3: __init__

    def __init__(self, request):
        super(CMSToolbar, self).__init__()
        self.left_items = None
        self.right_items = None
        self.menus = {}
        self.request = request
        self.login_form = CMSToolbarLoginForm(request=request)
        self.is_staff = self.request.user.is_staff
        self.edit_mode = self.is_staff and self.request.session.get('cms_edit', False)
        self.build_mode = self.is_staff and self.request.session.get('cms_build', False)
        self.use_draft = self.is_staff and self.edit_mode or self.build_mode
        self.show_toolbar = self.is_staff or self.request.session.get('cms_edit', False)
        if settings.USE_I18N:
            self.language = get_language_from_request(request)
        else:
            self.language = settings.LANGUAGE_CODE

        # We need to store the current language in case the user's preferred language is different.
        self.toolbar_language = self.language

        if self.is_staff:
            try:
                user_settings = UserSettings.objects.get(user=self.request.user)
            except UserSettings.DoesNotExist:
                user_settings = UserSettings(language=self.language, user=self.request.user)
                placeholder = Placeholder(slot="clipboard")
                placeholder.save()
                user_settings.clipboard = placeholder
                user_settings.save()
            self.toolbar_language = user_settings.language
            self.clipboard = user_settings.clipboard
开发者ID:conrado,项目名称:django-cms,代码行数:31,代码来源:toolbar.py

示例4: __init__

    def __init__(self, request):
        super(CMSToolbar, self).__init__()
        self.right_items = []
        self.left_items = []
        self.populated = False
        self.post_template_populated = False
        self.menus = {}
        self.request = request
        self.login_form = CMSToolbarLoginForm(request=request)
        self.is_staff = self.request.user.is_staff
        self.edit_mode = self.is_staff and self.request.session.get("cms_edit", False)
        self.edit_mode_url_on = get_cms_setting("CMS_TOOLBAR_URL__EDIT_ON")
        self.edit_mode_url_off = get_cms_setting("CMS_TOOLBAR_URL__EDIT_OFF")
        self.build_mode = self.is_staff and self.request.session.get("cms_build", False)
        self.use_draft = self.is_staff and self.edit_mode or self.build_mode
        self.show_toolbar = self.is_staff or self.request.session.get("cms_edit", False)
        self.obj = None
        self.redirect_url = None
        if settings.USE_I18N:
            self.language = get_language_from_request(request)
        else:
            self.language = settings.LANGUAGE_CODE

        # We need to store the current language in case the user's preferred language is different.
        self.toolbar_language = self.language

        if self.is_staff:
            try:
                user_settings = UserSettings.objects.select_related("clipboard").get(user=self.request.user)
            except UserSettings.DoesNotExist:
                user_settings = UserSettings(language=self.language, user=self.request.user)
                placeholder = Placeholder(slot="clipboard")
                placeholder.save()
                user_settings.clipboard = placeholder
                user_settings.save()
            if (settings.USE_I18N and user_settings.language in dict(settings.LANGUAGES)) or (
                not settings.USE_I18N and user_settings.language == settings.LANGUAGE_CODE
            ):
                self.toolbar_language = user_settings.language
            else:
                user_settings.language = self.language
                user_settings.save()
            self.clipboard = user_settings.clipboard
        with force_language(self.language):
            try:
                self.app_name = resolve(self.request.path).app_name
            except Resolver404:
                self.app_name = ""
        toolbars = toolbar_pool.get_toolbars()

        self.toolbars = SortedDict()
        app_key = ""
        for key in toolbars:
            app_name = ".".join(key.split(".")[:-2])
            if app_name == self.app_name and len(key) > len(app_key):
                app_key = key
        for key in toolbars:
            toolbar = toolbars[key](self.request, self, key == app_key, app_key)
            self.toolbars[key] = toolbar
开发者ID:BertrandBordage,项目名称:django-cms,代码行数:59,代码来源:toolbar.py

示例5: get_user_settings

 def get_user_settings(self):
     user_settings = None
     if self.is_staff:
         try:
             user_settings = UserSettings.objects.select_related("clipboard").get(user=self.request.user)
         except UserSettings.DoesNotExist:
             user_settings = UserSettings(language=self.language, user=self.request.user)
             placeholder = Placeholder(slot="clipboard")
             placeholder.save()
             user_settings.clipboard = placeholder
             user_settings.save()
     return user_settings
开发者ID:skirsdeda,项目名称:django-cms,代码行数:12,代码来源:toolbar.py

示例6: test_toolbar_switch_urls

    def test_toolbar_switch_urls(self):
        user = self.get_superuser()
        user_settings = UserSettings(language="en", user=user)
        placeholder = Placeholder(slot="clipboard")
        placeholder.save()
        user_settings.clipboard = placeholder
        user_settings.save()

        page = create_page("page", "nav_playground.html", "en", published=True)
        create_title("fr", "french home", page)
        publish_page(page, user, "fr")

        with self.login_user_context(user):
            response = self.client.get("/fr/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
            self.assertContains(response, "/fr/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF'), 1, 200)
            response = self.client.get("/fr/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF'))
            self.assertContains(response, "/fr/?%s" % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'), 1, 200)
开发者ID:intexal,项目名称:my-first-blog,代码行数:17,代码来源:test_views.py

示例7: test_render_placeholder_toolbar

 def test_render_placeholder_toolbar(self):
     placeholder = Placeholder()
     placeholder.slot = "test"
     placeholder.pk = placeholder.id = 99
     context = SekizaiContext()
     context["request"] = AttributeObject(
         REQUEST={"language": "en"},
         GET=[],
         session={},
         path="/",
         user=self.test_user,
         current_page=None,
         method="GET",
     )
     classes = ["cms_placeholder-%s" % placeholder.pk, "cms_placeholder"]
     output = render_placeholder_toolbar(placeholder, context, "test", "en")
     for cls in classes:
         self.assertTrue(cls in output, "%r is not in %r" % (cls, output))
开发者ID:RicardoAndreSantos,项目名称:django-cms,代码行数:18,代码来源:rendering.py

示例8: fill_placeholder

    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:alegrm,项目名称:django-cms,代码行数:19,代码来源:test_static_placeholder.py

示例9: test_render_placeholder_toolbar

    def test_render_placeholder_toolbar(self):
        placeholder = Placeholder()
        placeholder.slot = 'test'
        placeholder.pk = placeholder.id = 99
        request = self.get_request(page=None)
        request.toolbar = CMSToolbar(request)

        content_renderer = self.get_content_renderer(request)

        context = SekizaiContext()
        context['request'] = request
        context['cms_content_renderer'] = content_renderer

        classes = [
            "cms-placeholder-%s" % placeholder.pk,
            'cms-placeholder',
        ]

        output = content_renderer.render_editable_placeholder(placeholder, context, 'en')
        for cls in classes:
            self.assertTrue(cls in output, '%r is not in %r' % (cls, output))
开发者ID:evildmp,项目名称:django-cms,代码行数:21,代码来源:test_rendering.py

示例10: test_render_placeholder_toolbar

 def test_render_placeholder_toolbar(self):
     placeholder = Placeholder()
     placeholder.slot = 'test'
     placeholder.pk = placeholder.id = 99
     context = SekizaiContext()
     context['request'] = AttributeObject(
         REQUEST={'language': 'en'},
         GET=[],
         session={},
         path='/',
         user=self.test_user,
         current_page=None,
         method='GET',
     )
     classes = [
         "cms_placeholder-%s" % placeholder.pk,
         'cms_placeholder',
     ]
     output = render_placeholder_toolbar(placeholder, context, 'test', 'en')
     for cls in classes:
         self.assertTrue(cls in output, '%r is not in %r' % (cls, output))
开发者ID:alekGbuz,项目名称:django-cms,代码行数:21,代码来源:rendering.py

示例11: convert


#.........这里部分代码省略.........
                models_dictionary["messages"][mmodel][old_field]={}

                try:
                    getattr(actual_model, new_field)
                except AttributeError:
                    message = "field " + new_field + " is missing - check the model and try agin"
                    models_dictionary["messages"][mmodel][old_field]["Error"]=message
                    continue
                    
                junk_content = []   # a record of those items with nothing but <br /> in them
                moved_items =[]     # a record of the items we migrated to placeholders

                # loop over each item in the class
                for item in actual_model.objects.all():

                    old_field_content = getattr(item, old_field)  # the old field we want to convert

                    # first get rid of junk content (change "<br />" to "")
                    if old_field_content == "<br />":
                        old_field_content = ""
                        setattr(item, old_field, "") # item.content = ""
                        if execute == "convert":
                            item.save()
                    
                    # now the serious business of converting the fields
            
                    # if the item lacks a placeholder, create the placeholder and the reference to it
                    if old_field_content and not getattr(item, new_field, None):

                        # check to see if it's worth converting
                        if len(old_field_content) > 60:

                            # create the placeholder
                            placeholder=Placeholder(slot=slot)
                            if execute == "convert":
                                placeholder.save()
        
                            # refer to the placeholder from the item
                            setattr(item, new_field, placeholder)
        
                            # I copied this from one of the test files
                            plugin_base = CMSPlugin(
                                plugin_type='TextPlugin',
                                placeholder=placeholder, 
                                position=1, 
                                language=settings.LANGUAGES[0][0]) # we assume the original field was in the first language
                            plugin_base.insert_at(None, position='last-child', commit=False)
        
                            # create a text plugin
                            plugin = Text(body='')
                            plugin_base.set_base_attr(plugin)
                            plugin.body = getattr(item, old_field)
                            if execute == "convert":
                                plugin.save()
        
                            # set the old field to ""
                            setattr(item, old_field, "")
                            if execute == "convert":
                                item.save()
                                item.status = "Converted to placeholder"
                            else:
                                item.status = "Unconverted"
                                        
                        else:
                            print "too short", old_field_content
                            # this item is so short it must be junk
开发者ID:airtonix,项目名称:Arkestra,代码行数:67,代码来源:convert_to_placeholders.py

示例12: __init__

    def __init__(self, request):
        super(CMSToolbar, self).__init__()
        self.right_items = []
        self.left_items = []
        self.populated = False
        self.post_template_populated = False
        self.menus = {}
        self.request = request
        self.login_form = CMSToolbarLoginForm(request=request)
        self.is_staff = self.request.user.is_staff
        self.edit_mode = self.is_staff and self.request.session.get('cms_edit', False)
        self.edit_mode_url_on = get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')
        self.edit_mode_url_off = get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF')
        self.build_mode = self.is_staff and self.request.session.get('cms_build', False)
        self.use_draft = self.is_staff and self.edit_mode or self.build_mode
        self.show_toolbar = self.is_staff or self.request.session.get('cms_edit', False)
        self.obj = None
        self.redirect_url = None
        if settings.USE_I18N:
            self.language = get_language_from_request(request)
        else:
            self.language = settings.LANGUAGE_CODE

        # We need to store the current language in case the user's preferred language is different.
        self.toolbar_language = self.language

        if self.is_staff:
            try:
                user_settings = UserSettings.objects.select_related('clipboard').get(user=self.request.user)
            except UserSettings.DoesNotExist:
                user_settings = UserSettings(language=self.language, user=self.request.user)
                placeholder = Placeholder(slot="clipboard")
                placeholder.save()
                user_settings.clipboard = placeholder
                user_settings.save()
            if (settings.USE_I18N and user_settings.language in dict(settings.LANGUAGES)) or (
                    not settings.USE_I18N and user_settings.language == settings.LANGUAGE_CODE):
                self.toolbar_language = user_settings.language
            else:
                user_settings.language = self.language
                user_settings.save()
            self.clipboard = user_settings.clipboard
        with force_language(self.language):
            try:
                decorator = resolve(self.request.path_info).func
                try:
                    # If the original view is decorated we try to extract the real function
                    # module instead of the decorator's one
                    if decorator and getattr(decorator, 'func_closure', False):
                        # python 2
                        self.app_name = decorator.func_closure[0].cell_contents.__module__
                    elif decorator and getattr(decorator, '__closure__', False):
                        # python 3
                        self.app_name = decorator.__closure__[0].cell_contents.__module__
                    else:
                        raise AttributeError()
                except (TypeError, AttributeError):
                    # no decorator
                    self.app_name = decorator.__module__
            except Resolver404:
                self.app_name = ""
        toolbars = toolbar_pool.get_toolbars()
        parts = self.app_name.split('.')
        while parts:
            path = '.'.join(parts)
            if path in installed_apps():
                self.app_name = path
                break
            parts.pop()

        self.toolbars = SortedDict()
        for key in toolbars:
            toolbar = toolbars[key](self.request, self, toolbars[key].check_current_app(key, self.app_name), self.app_name)
            self.toolbars[key] = toolbar
开发者ID:MackJay,项目名称:django-cms,代码行数:74,代码来源:toolbar.py


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