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


Python CMSPlugin.save方法代码示例

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


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

示例1: save_body

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
    def save_body(self, placeholder, desc):
        language = settings.LANGUAGE_CODE
        try:
            plugin = CMSPlugin.objects.get(placeholder=placeholder, position=0, language=language)
            plugin.body = desc
        except CMSPlugin.DoesNotExist:
            plugin = CMSPlugin(language=language, plugin_type="TextPlugin", position=0, placeholder=placeholder)
            plugin.save()

        if plugin:
            text = Text()
            # text.set_base_attr(plugin)
            text.pk = plugin.pk
            text.id = plugin.pk
            text.placeholder = placeholder
            text.position = plugin.position
            text.plugin_type = plugin.plugin_type
            text.tree_id = plugin.tree_id
            text.lft = plugin.lft
            text.rght = plugin.rght
            text.level = plugin.level
            text.cmsplugin_ptr = plugin
            text.publisher_public_id = None
            text.public_id = None
            text.published = False
            text.language = language
            text.body = desc
            text.save()
开发者ID:elprox97,项目名称:django-simple-shop,代码行数:30,代码来源:loadproducts.py

示例2: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
    def add_plugin(self, request):
        """
        POST request should have the following data:

        - placeholder_id
        - plugin_type
        - plugin_language
        - plugin_parent (optional)
        """
        parent = None
        plugin_type = request.POST['plugin_type']
        placeholder_id = request.POST.get('placeholder_id', None)
        placeholder = get_object_or_404(Placeholder, pk=placeholder_id)
        parent_id = request.POST.get('plugin_parent', None)
        language = request.POST.get('plugin_language') or get_language_from_request(request)
        if not self.has_add_plugin_permission(request, placeholder, plugin_type):
            return HttpResponseForbidden(force_unicode(_('You do not have permission to add a plugin')))
        try:
            has_reached_plugin_limit(placeholder, plugin_type, language,
                                     template=self.get_placeholder_template(request, placeholder))
        except PluginLimitReached as er:
            return HttpResponseBadRequest(er)
            # page add-plugin
        if not parent_id:
            position = request.POST.get('plugin_order',
                                        CMSPlugin.objects.filter(language=language, placeholder=placeholder).count())
        # in-plugin add-plugin
        else:
            parent = get_object_or_404(CMSPlugin, pk=parent_id)
            placeholder = parent.placeholder
            position = request.POST.get('plugin_order',
                                        CMSPlugin.objects.filter(language=language, parent=parent).count())
            # placeholder (non-page) add-plugin

        # Sanity check to make sure we're not getting bogus values from JavaScript:
        if settings.USE_I18N:
            if not language or not language in [lang[0] for lang in settings.LANGUAGES]:
                return HttpResponseBadRequest(force_unicode(_("Language must be set to a supported language!")))
            if parent and parent.language != language:
                return HttpResponseBadRequest(force_unicode(_("Parent plugin language must be same as language!")))
        else:
            language = settings.LANGUAGE_CODE
        plugin = CMSPlugin(language=language, plugin_type=plugin_type, position=position, placeholder=placeholder)

        if parent:
            plugin.position = CMSPlugin.objects.filter(parent=parent).count()
            plugin.parent_id = parent.pk
        plugin.save()
        self.post_add_plugin(request, placeholder, plugin)
        response = {
            'url': force_unicode(
                admin_reverse("%s_%s_edit_plugin" % (self.model._meta.app_label, self.model._meta.model_name),
                        args=[plugin.pk])),
            'delete': force_unicode(
                admin_reverse("%s_%s_delete_plugin" % (self.model._meta.app_label, self.model._meta.model_name),
                        args=[plugin.pk])),
            'breadcrumb': plugin.get_breadcrumb(),
        }
        return HttpResponse(json.dumps(response), content_type='application/json')
开发者ID:amaozhao,项目名称:basecms,代码行数:61,代码来源:placeholderadmin.py

示例3: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
    def add_plugin(self, request):
        # only allow POST
        if request.method != "POST":
            raise Http404
        plugin_type = request.POST['plugin_type']
        if not has_plugin_permission(request.user, plugin_type, "add"):
            return HttpResponseForbidden("You don't have permission to add plugins")

        placeholder_id = request.POST.get('placeholder', None)
        position = None
        language = get_language_from_request(request)
        parent = None
        # check if we got a placeholder (id)
        if placeholder_id:
            placeholder = get_object_or_404(Placeholder, pk=placeholder_id)
        else: # else get the parent_id
            parent_id = request.POST.get('parent_id', None)
            if not parent_id: # if we get neither a placeholder nor a parent, bail out
                raise Http404
            parent = get_object_or_404(CMSPlugin, pk=parent_id)
            placeholder = parent.placeholder
        
        # check add permissions on placeholder
        if not placeholder.has_add_permission(request):
            return HttpResponseForbidden(_("You don't have permission to add content here."))
        
        # check the limits defined in CMS_PLACEHOLDER_CONF for this placeholder
        limits = settings.CMS_PLACEHOLDER_CONF.get(placeholder.slot, {}).get('limits', None)
        if limits:
            count = placeholder.cmsplugin_set.count()
            global_limit = limits.get("global", None)
            type_limit = limits.get(plugin_type, None)
            # check the global limit first
            if global_limit and count >= global_limit:
                return HttpResponseBadRequest(
                    "This placeholder already has the maximum number of plugins."
                )
            elif type_limit: # then check the type specific limit
                type_count = CMSPlugin.objects.filter(
                    language=language, placeholder=placeholder, plugin_type=plugin_type
                ).count()
                if type_count >= type_limit:
                    return HttpResponseBadRequest(
                        "This placeholder already has the maximum number (%s) "
                        "of %s plugins." % (type_limit, plugin_type)
                    )

        # position plugin at the end of the list
        position = CMSPlugin.objects.filter(placeholder=placeholder).count()

        # actually add the plugin
        plugin = CMSPlugin(language=language, plugin_type=plugin_type,
            position=position, placeholder=placeholder, parent=parent) 
        plugin.save()
        
        # returns it's ID as response
        return HttpResponse(str(plugin.pk))
开发者ID:rfeldbinder,项目名称:django-cms,代码行数:59,代码来源:placeholderadmin.py

示例4: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
 def add_plugin(self, request):
     if request.method != "POST":
         raise Http404
     plugin_type = request.POST['plugin_type']
     placeholder_id = request.POST['placeholder']
     placeholder = get_object_or_404(Placeholder, pk=placeholder_id)
     position = None
     language = get_language_from_request(request)
     plugin = CMSPlugin(language=language, plugin_type=plugin_type,
         position=position, placeholder=placeholder) 
     plugin.save()
     return HttpResponse(str(plugin.pk))
开发者ID:kkubasik,项目名称:django-cms-2.0,代码行数:14,代码来源:placeholderadmin.py

示例5: test_list_plugins

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
    def test_list_plugins(self):
        out = StringIO()
        apps = ["cms", "menus", "sekizai", "cms.test_utils.project.sampleapp"]
        with SettingsOverride(INSTALLED_APPS=apps):
            placeholder = Placeholder.objects.create(slot="test")
            add_plugin(placeholder, TextPlugin, "en", body="en body")
            add_plugin(placeholder, TextPlugin, "en", body="en body")
            link_plugin = add_plugin(placeholder, "LinkPlugin", "en", name="A Link", url="https://www.django-cms.org")
            self.assertEqual(CMSPlugin.objects.filter(plugin_type=PLUGIN).count(), 2)
            self.assertEqual(CMSPlugin.objects.filter(plugin_type="LinkPlugin").count(), 1)

            # create a CMSPlugin with an unsaved instance
            instanceless_plugin = CMSPlugin(language="en", plugin_type="TextPlugin")
            instanceless_plugin.save()

            # create a bogus CMSPlugin to simulate one which used to exist but
            # is no longer installed
            bogus_plugin = CMSPlugin(language="en", plugin_type="BogusPlugin")
            bogus_plugin.save()

            report = plugin_report()

            # there should be reports for three plugin types
            self.assertEqual(len(report), 3)

            # check the bogus plugin
            bogus_plugins_report = report[0]
            self.assertEqual(bogus_plugins_report["model"], None)

            self.assertEqual(bogus_plugins_report["type"], u"BogusPlugin")

            self.assertEqual(bogus_plugins_report["instances"][0], bogus_plugin)

            # check the link plugin
            link_plugins_report = report[1]
            self.assertEqual(link_plugins_report["model"], link_plugin.__class__)

            self.assertEqual(link_plugins_report["type"], u"LinkPlugin")

            self.assertEqual(link_plugins_report["instances"][0].get_plugin_instance()[0], link_plugin)

            # check the text plugins
            text_plugins_report = report[2]
            self.assertEqual(text_plugins_report["model"], TextPlugin.model)

            self.assertEqual(text_plugins_report["type"], u"TextPlugin")

            self.assertEqual(len(text_plugins_report["instances"]), 3)

            self.assertEqual(text_plugins_report["instances"][2], instanceless_plugin)

            self.assertEqual(text_plugins_report["unsaved_instances"], [instanceless_plugin])
开发者ID:conrado,项目名称:django-cms,代码行数:54,代码来源:management.py

示例6: test_delete_orphaned_plugins

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
    def test_delete_orphaned_plugins(self):
        apps = ["cms", "menus", "sekizai", "cms.test_utils.project.sampleapp"]
        with SettingsOverride(INSTALLED_APPS=apps):
            placeholder = Placeholder.objects.create(slot="test")
            add_plugin(placeholder, TextPlugin, "en", body="en body")
            add_plugin(placeholder, TextPlugin, "en", body="en body")
            link_plugin = add_plugin(placeholder, "LinkPlugin", "en", name="A Link", url="https://www.django-cms.org")

            instanceless_plugin = CMSPlugin(language="en", plugin_type="TextPlugin")
            instanceless_plugin.save()

            # create a bogus CMSPlugin to simulate one which used to exist but
            # is no longer installed
            bogus_plugin = CMSPlugin(language="en", plugin_type="BogusPlugin")
            bogus_plugin.save()

            report = plugin_report()

            # there should be reports for three plugin types
            self.assertEqual(len(report), 3)

            # check the bogus plugin
            bogus_plugins_report = report[0]
            self.assertEqual(len(bogus_plugins_report["instances"]), 1)

            # check the link plugin
            link_plugins_report = report[1]
            self.assertEqual(len(link_plugins_report["instances"]), 1)

            # check the text plugins
            text_plugins_report = report[2]
            self.assertEqual(len(text_plugins_report["instances"]), 3)

            self.assertEqual(len(text_plugins_report["unsaved_instances"]), 1)

            management.call_command("cms", "delete_orphaned_plugins", stdout=StringIO(), interactive=False)
            report = plugin_report()

            # there should be reports for two plugin types (one should have been deleted)
            self.assertEqual(len(report), 2)

            # check the link plugin
            link_plugins_report = report[0]
            self.assertEqual(len(link_plugins_report["instances"]), 1)

            # check the text plugins
            text_plugins_report = report[1]
            self.assertEqual(len(text_plugins_report["instances"]), 2)

            self.assertEqual(len(text_plugins_report["unsaved_instances"]), 0)
开发者ID:conrado,项目名称:django-cms,代码行数:52,代码来源:management.py

示例7: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
 def add_plugin(self, request):
     if request.method != "POST":
         raise Http404
     plugin_type = request.POST['plugin_type']
     placeholder_id = request.POST.get('placeholder', None)
     position = None
     language = get_language_from_request(request)
     if not placeholder_id:
         parent_id = request.POST.get('parent_id', None)
         if not parent_id:
             raise Http404
         parent = get_object_or_404(CMSPlugin, pk=parent_id)
         plugin = CMSPlugin(language=language, plugin_type=plugin_type,
             position=position, parent=parent, placeholder=parent.placeholder)
     else:
         placeholder = get_object_or_404(Placeholder, pk=placeholder_id)
         plugin = CMSPlugin(language=language, plugin_type=plugin_type,
             position=position, placeholder=placeholder) 
     plugin.save()
     return HttpResponse(str(plugin.pk))
开发者ID:CreativeCubes,项目名称:django-cms,代码行数:22,代码来源:placeholderadmin.py

示例8: test_check_plugin_instances

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
    def test_check_plugin_instances(self):
        self.assertCheck(True, warnings=0, errors=0 )

        placeholder = Placeholder.objects.create(slot="test")
        add_plugin(placeholder, TextPlugin, "en", body="en body")
        add_plugin(placeholder, TextPlugin, "en", body="en body")
        add_plugin(placeholder, "LinkPlugin", "en",
                   name="A Link", external_link="https://www.django-cms.org")

        # create a CMSPlugin with an unsaved instance
        instanceless_plugin = CMSPlugin(language="en", plugin_type="TextPlugin")
        instanceless_plugin.save()

        self.assertCheck(False, warnings=0, errors=2)

        # create a bogus CMSPlugin to simulate one which used to exist but
        # is no longer installed
        bogus_plugin = CMSPlugin(language="en", plugin_type="BogusPlugin")
        bogus_plugin.save()

        self.assertCheck(False, warnings=0, errors=3)
开发者ID:quanpower,项目名称:django-cms,代码行数:23,代码来源:test_check.py

示例9: test_check_plugin_instances

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
    def test_check_plugin_instances(self):
        self.assertCheck(True, warnings=0, errors=0 )

        apps = ["cms", "menus", "sekizai", "cms.test_utils.project.sampleapp", "treebeard"]
        with self.settings(INSTALLED_APPS=apps):
            placeholder = Placeholder.objects.create(slot="test")
            add_plugin(placeholder, TextPlugin, "en", body="en body")
            add_plugin(placeholder, TextPlugin, "en", body="en body")
            add_plugin(placeholder, "LinkPlugin", "en",
                name="A Link", url="https://www.django-cms.org")

            # create a CMSPlugin with an unsaved instance
            instanceless_plugin = CMSPlugin(language="en", plugin_type="TextPlugin")
            instanceless_plugin.save()

            self.assertCheck(False, warnings=0, errors=2)

            # create a bogus CMSPlugin to simulate one which used to exist but
            # is no longer installed
            bogus_plugin = CMSPlugin(language="en", plugin_type="BogusPlugin")
            bogus_plugin.save()

            self.assertCheck(False, warnings=0, errors=3)
开发者ID:AllenYang0308,项目名称:django-cms,代码行数:25,代码来源:check.py

示例10: test_delete_orphaned_plugins

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
    def test_delete_orphaned_plugins(self):
        placeholder = Placeholder.objects.create(slot="test")
        add_plugin(placeholder, TextPlugin, "en", body="en body")
        add_plugin(placeholder, TextPlugin, "en", body="en body")
        add_plugin(placeholder, "LinkPlugin", "en",
                   name="A Link", url="https://www.django-cms.org")

        instanceless_plugin = CMSPlugin(
            language="en", plugin_type="TextPlugin")
        instanceless_plugin.save()

        # create a bogus CMSPlugin to simulate one which used to exist but
        # is no longer installed
        bogus_plugin = CMSPlugin(language="en", plugin_type="BogusPlugin")
        bogus_plugin.save()

        report = plugin_report()

        # there should be reports for three plugin types
        self.assertEqual(
            len(report),
            3)

        # check the bogus plugin
        bogus_plugins_report = report[0]
        self.assertEqual(
            len(bogus_plugins_report["instances"]),
            1)

        # check the link plugin
        link_plugins_report = report[1]
        self.assertEqual(
            len(link_plugins_report["instances"]),
            1)

        # check the text plugins
        text_plugins_report = report[2]
        self.assertEqual(
            len(text_plugins_report["instances"]),
            3)

        self.assertEqual(
            len(text_plugins_report["unsaved_instances"]),
            1)

        out = StringIO()
        management.call_command('cms', 'delete-orphaned-plugins', interactive=False, stdout=out)
        report = plugin_report()

        # there should be reports for two plugin types (one should have been deleted)
        self.assertEqual(
            len(report),
            2)

        # check the link plugin
        link_plugins_report = report[0]
        self.assertEqual(
            len(link_plugins_report["instances"]),
            1)

        # check the text plugins
        text_plugins_report = report[1]
        self.assertEqual(
            len(text_plugins_report["instances"]),
            2)

        self.assertEqual(
            len(text_plugins_report["unsaved_instances"]),
            0)
开发者ID:evildmp,项目名称:django-cms,代码行数:71,代码来源:test_management.py

示例11: test_list_plugins

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
    def test_list_plugins(self):
        out = StringIO()
        placeholder = Placeholder.objects.create(slot="test")
        add_plugin(placeholder, TextPlugin, "en", body="en body")
        add_plugin(placeholder, TextPlugin, "en", body="en body")
        link_plugin = add_plugin(placeholder, "LinkPlugin", "en",
                                 name="A Link", url="https://www.django-cms.org")
        self.assertEqual(
            CMSPlugin.objects.filter(plugin_type=PLUGIN).count(),
            2)
        self.assertEqual(
            CMSPlugin.objects.filter(plugin_type="LinkPlugin").count(),
            1)

        # create a CMSPlugin with an unsaved instance
        instanceless_plugin = CMSPlugin(language="en", plugin_type="TextPlugin")
        instanceless_plugin.save()

        # create a bogus CMSPlugin to simulate one which used to exist but
        # is no longer installed
        bogus_plugin = CMSPlugin(language="en", plugin_type="BogusPlugin")
        bogus_plugin.save()

        management.call_command('cms', 'list', 'plugins', interactive=False, stdout=out)
        report = plugin_report()

        # there should be reports for three plugin types
        self.assertEqual(
            len(report),
            3)

        # check the bogus plugin
        bogus_plugins_report = report[0]
        self.assertEqual(
            bogus_plugins_report["model"],
            None)

        self.assertEqual(
            bogus_plugins_report["type"],
            u'BogusPlugin')

        self.assertEqual(
            bogus_plugins_report["instances"][0],
            bogus_plugin)

        # check the link plugin
        link_plugins_report = report[1]
        self.assertEqual(
            link_plugins_report["model"],
            link_plugin.__class__)

        self.assertEqual(
            link_plugins_report["type"],
            u'LinkPlugin')

        self.assertEqual(
            link_plugins_report["instances"][0].get_plugin_instance()[0],
            link_plugin)

        # check the text plugins
        text_plugins_report = report[2]
        self.assertEqual(
            text_plugins_report["model"],
            TextPlugin.model)

        self.assertEqual(
            text_plugins_report["type"],
            u'TextPlugin')

        self.assertEqual(
            len(text_plugins_report["instances"]),
            3)

        self.assertEqual(
            text_plugins_report["instances"][2],
            instanceless_plugin)

        self.assertEqual(
            text_plugins_report["unsaved_instances"],
            [instanceless_plugin])
开发者ID:evildmp,项目名称:django-cms,代码行数:82,代码来源:test_management.py

示例12: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import save [as 别名]
    def add_plugin(self, request):
        """
        POST request should have the following data:

        - placeholder_id
        - plugin_type
        - plugin_language
        - plugin_parent (optional)
        """
        plugin_type = request.POST["plugin_type"]

        placeholder_id = request.POST.get("placeholder_id", None)
        parent_id = request.POST.get("parent_id", None)
        if parent_id:
            warnings.warn(
                "parent_id is deprecated and will be removed in 3.1, use plugin_parent instead", DeprecationWarning
            )
        if not parent_id:
            parent_id = request.POST.get("plugin_parent", None)
        placeholder = get_object_or_404(Placeholder, pk=placeholder_id)
        if not self.has_add_plugin_permission(request, placeholder, plugin_type):
            return HttpResponseForbidden(force_unicode(_("You do not have permission to add a plugin")))
        parent = None
        language = request.POST.get("plugin_language") or get_language_from_request(request)
        try:
            has_reached_plugin_limit(
                placeholder, plugin_type, language, template=self.get_placeholder_template(request, placeholder)
            )
        except PluginLimitReached as er:
            return HttpResponseBadRequest(er)
            # page add-plugin
        if not parent_id:

            position = request.POST.get(
                "plugin_order", CMSPlugin.objects.filter(language=language, placeholder=placeholder).count()
            )
        # in-plugin add-plugin
        else:
            parent = get_object_or_404(CMSPlugin, pk=parent_id)
            placeholder = parent.placeholder
            position = request.POST.get(
                "plugin_order", CMSPlugin.objects.filter(language=language, parent=parent).count()
            )
            # placeholder (non-page) add-plugin

        # Sanity check to make sure we're not getting bogus values from JavaScript:
        if settings.USE_I18N:
            if not language or not language in [lang[0] for lang in settings.LANGUAGES]:
                return HttpResponseBadRequest(force_unicode(_("Language must be set to a supported language!")))
            if parent and parent.language != language:
                return HttpResponseBadRequest(force_unicode(_("Parent plugin language must be same as language!")))
        else:
            language = settings.LANGUAGE_CODE
        plugin = CMSPlugin(language=language, plugin_type=plugin_type, position=position, placeholder=placeholder)

        if parent:
            plugin.position = CMSPlugin.objects.filter(parent=parent).count()
            plugin.insert_at(parent, position="last-child", save=False)
        plugin.save()
        self.post_add_plugin(request, placeholder, plugin)
        response = {
            "url": force_unicode(
                reverse(
                    "admin:%s_%s_edit_plugin" % (self.model._meta.app_label, self.model._meta.module_name),
                    args=[plugin.pk],
                )
            ),
            "delete": force_unicode(
                reverse(
                    "admin:%s_%s_delete_plugin" % (self.model._meta.app_label, self.model._meta.module_name),
                    args=[plugin.pk],
                )
            ),
            "breadcrumb": plugin.get_breadcrumb(),
        }
        return HttpResponse(json.dumps(response), content_type="application/json")
开发者ID:bennylope,项目名称:django-cms,代码行数:78,代码来源:placeholderadmin.py


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