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


Python models.CMSPlugin方法代码示例

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


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

示例1: record_plugin_history

# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import CMSPlugin [as 别名]
def record_plugin_history(self, sender, instance, **kwargs):
        """When a plugin is created or edited"""
        from cms.models import CMSPlugin, Page
        from .models import EditHistory
        if not isinstance(instance, CMSPlugin):
            return

        user_id = cache.get('cms-user-id')
        comment = cache.get('cms-comment')
        content = generate_content(instance)
        if content is None:
            return

        # Don't record a history of change if nothing changed.
        history = EditHistory.objects.filter(plugin_id=instance.id)
        if history.count() > 0:
            # Temporary history object for uuid
            this = EditHistory(content=content)
            latest = history.latest()
            if latest.content == content or this.uuid == latest.uuid:
                return

        EditHistory.objects.record(instance, user_id, comment, content) 
开发者ID:doctormo,项目名称:django-cmsplugin-diff,代码行数:25,代码来源:apps.py

示例2: _get_attached_fields

# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import CMSPlugin [as 别名]
def _get_attached_fields(self):
        """
        Returns an ITERATOR of all non-cmsplugin reverse foreign key related fields.
        """
        from cms.models import CMSPlugin
        if not hasattr(self, '_attached_fields_cache'):
            self._attached_fields_cache = []
            relations = self._get_related_objects()
            for rel in relations:
                if issubclass(rel.model, CMSPlugin):
                    continue
                from cms.admin.placeholderadmin import PlaceholderAdminMixin
                parent = rel.related_model
                if parent in admin.site._registry and isinstance(admin.site._registry[parent], PlaceholderAdminMixin):
                    field = getattr(self, rel.get_accessor_name())
                    try:
                        if field.count():
                            self._attached_fields_cache.append(rel.field)
                    except:
                        pass
        return self._attached_fields_cache 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:23,代码来源:placeholdermodel.py

示例3: _get_attached_field

# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import CMSPlugin [as 别名]
def _get_attached_field(self):
        from cms.models import CMSPlugin, StaticPlaceholder, Page
        if not hasattr(self, '_attached_field_cache'):
            self._attached_field_cache = None
            relations = self._get_related_objects()
            for rel in relations:
                parent = rel.related_model
                if parent == Page or parent == StaticPlaceholder:
                    relations.insert(0, relations.pop(relations.index(rel)))
            for rel in relations:
                if issubclass(rel.model, CMSPlugin):
                    continue
                from cms.admin.placeholderadmin import PlaceholderAdminMixin
                parent = rel.related_model
                if parent in admin.site._registry and isinstance(admin.site._registry[parent], PlaceholderAdminMixin):
                    field = getattr(self, rel.get_accessor_name())
                    try:
                        if field.count():
                            self._attached_field_cache = rel.field
                            break
                    except:
                        pass
        return self._attached_field_cache 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:25,代码来源:placeholdermodel.py

示例4: get_context

# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import CMSPlugin [as 别名]
def get_context(self, context, obj):
        # Prepend frontedit toolbar output if applicable
        request = context['request']
        items = []
        if isinstance(obj, CMSPlugin):
            plugin = obj
            plugin_class_inst = plugin.get_plugin_class_instance()
            item = plugin_class_inst.get_extra_local_plugin_menu_items(request, plugin)
            if item:
                items += item
            plugin_classes = plugin_pool.get_all_plugins()
            for plugin_class in plugin_classes:
                plugin_class_inst = plugin_class()
                item = plugin_class_inst.get_extra_global_plugin_menu_items(request, plugin)
                if item:
                    items += item

        elif isinstance(obj, PlaceholderModel):
            plugin_classes = plugin_pool.get_all_plugins()
            for plugin_class in plugin_classes:
                plugin_class_inst = plugin_class()
                item = plugin_class_inst.get_extra_placeholder_menu_items(request, obj)
                if item:
                    items += item
        return {'items': items} 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:27,代码来源:cms_tags.py

示例5: ready

# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import CMSPlugin [as 别名]
def ready(self):
        from cms.models import CMSPlugin, Page
        from cms.signals import post_publish
        from .cms_toolbar import DiffToolbar
        signals.pre_save.connect(self.ensure_initial)
        signals.post_save.connect(self.record_plugin_history)
        post_publish.connect(self.record_history, sender=Page) 
开发者ID:doctormo,项目名称:django-cmsplugin-diff,代码行数:9,代码来源:apps.py

示例6: register_plugin

# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import CMSPlugin [as 别名]
def register_plugin(self, plugin):
        """
        Registers the given plugin(s).

        Static sanity checks is also performed.

        If a plugin is already registered, this will raise PluginAlreadyRegistered.
        """
        if not issubclass(plugin, CMSPluginBase):
            raise ImproperlyConfigured(
                "CMS Plugins must be subclasses of CMSPluginBase, %r is not."
                % plugin
            )
        plugin_name = plugin.__name__
        if plugin_name in self.plugins:
            raise PluginAlreadyRegistered(
                "Cannot register %r, a plugin with this name (%r) is already "
                "registered." % (plugin, plugin_name)
            )

        plugin.value = plugin_name
        self.plugins[plugin_name] = plugin
        from cms.signals import pre_save_plugins, post_delete_plugins, pre_delete_plugins

        signals.pre_save.connect(pre_save_plugins, sender=plugin.model,
                                 dispatch_uid='cms_pre_save_plugin_%s' % plugin_name)
        signals.post_delete.connect(post_delete_plugins, sender=CMSPlugin,
                                    dispatch_uid='cms_post_delete_plugin_%s' % plugin_name)
        signals.pre_delete.connect(pre_delete_plugins, sender=CMSPlugin,
                                   dispatch_uid='cms_pre_delete_plugin_%s' % plugin_name)
        if is_installed('reversion'):
            from cms.utils.reversion_hacks import RegistrationError
            try:
                reversion_register(plugin.model)
            except RegistrationError:
                pass

        return plugin 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:40,代码来源:plugin_pool.py

示例7: ensure_initial

# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import CMSPlugin [as 别名]
def ensure_initial(self, sender, instance, **kwargs):
        """Ensure there is a previous history object"""
        from cms.models import CMSPlugin, Page
        from .models import EditHistory, PublishHistory
        if not (isinstance(instance, CMSPlugin) and instance.id):
            # Idn't a plugin or is being created
            return

        # We're looking at an initalisation request.
        history = EditHistory.objects.filter(plugin_id=instance.id)
        if history.count() > 0:
            return

        # We don't want to modified version, but the original one
        try:
            instance = type(instance).objects.get(pk=instance.id)
        except type(instance).DoesNotExist:
            return
        content = generate_content(instance)
        if content is None:
            return

        # So what's happened here, is that there is an existing plugin
        # that existed BEFORE this plugin was being used. So we're going
        # to track the initial state of the plugin, before it's changed.
        User = get_user_model()
        # We would use changed_by, but django-cms converts user id to First
        # and Last name, not even username. Making that field useless.
        (user, _) = User.objects.get_or_create(username='cms-user')

        public = instance.page.publisher_public
        kwargs = dict(page=public, language=get_language())
        publishings = PublishHistory.objects.filter(**kwargs)
        if publishings.count() == 0:
            kwargs['defaults'] = dict(user=user, date=public.changed_date)
            (pub, _) = PublishHistory.objects.get_or_create(**kwargs)
        else:
            # Get the first one created which should be the initial version.
            pub = publishings.latest('date')

        # Note: Do not make 'Inital' comment translatable.
        return EditHistory.objects.record(instance, user.id, 'Initial', content, pub) 
开发者ID:doctormo,项目名称:django-cmsplugin-diff,代码行数:44,代码来源:apps.py


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