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


Python CMSPlugin.get_breadcrumb方法代码示例

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


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

示例1: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import get_breadcrumb [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

示例2: add_plugin

# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import get_breadcrumb [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.get_breadcrumb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。