def _reversion(): exclude_fields = ['publisher_is_draft', 'publisher_public', 'publisher_state'] reversion_register( Title, exclude_fields=exclude_fields )
def register_plugin(self, plugin): """ Registers the given plugin(s). If a plugin is already registered, this will raise PluginAlreadyRegistered. """ if hasattr(plugin, '__iter__'): warnings.warn( "Registering more than one plugin at once will be deprecated in 2.3", DeprecationWarning) for single_plugin in plugin: self.register_plugin(single_plugin) return 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 if 'reversion' in settings.INSTALLED_APPS: try: from reversion.registration import RegistrationError except ImportError: from reversion.revisions import RegistrationError try: reversion_register(plugin.model) except RegistrationError: pass
def register_plugin(self, plugin): """ Registers the given plugin(s). If a plugin is already registered, this will raise PluginAlreadyRegistered. """ if hasattr(plugin,'__iter__'): for single_plugin in plugin: self.register_plugin(single_plugin) 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 if 'reversion' in settings.INSTALLED_APPS: try: from reversion.registration import RegistrationError except ImportError: from reversion.revisions import RegistrationError try: reversion_register(plugin.model) except RegistrationError: pass
def register_plugin(self, plugin_or_iterable): """ Registers the given plugin(s). If a plugin is already registered, this will raise PluginAlreadyRegistered. """ if not hasattr(plugin_or_iterable,'__iter__'): plugin_or_iterable = [plugin_or_iterable] for plugin in plugin_or_iterable: assert issubclass(plugin, CMSPluginBase) plugin_name = plugin.__name__ if plugin_name in self.plugins: raise PluginAlreadyRegistered("[%s] a plugin with this name is already registered" % plugin_name) plugin.value = plugin_name self.plugins[plugin_name] = plugin if 'reversion' in settings.INSTALLED_APPS: try: from reversion.registration import RegistrationError except ImportError: from reversion.revisions import RegistrationError try: reversion_register(plugin.model, follow=["cmsplugin_ptr"]) except RegistrationError: pass
def register_plugin(self, plugin): """ Registers the given plugin(s). 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 if 'reversion' in settings.INSTALLED_APPS: try: from reversion.registration import RegistrationError except ImportError: from reversion.revisions import RegistrationError try: reversion_register(plugin.model) except RegistrationError: pass
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 signals.pre_save.connect(pre_save_plugins, sender=plugin.model, dispatch_uid='cms_pre_save_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
def _reversion(): if "publisher" in settings.INSTALLED_APPS: exclude_fields = ["publisher_is_draft", "publisher_public", "publisher_state"] else: exclude_fields = [] reversion_register(Page, follow=["title_set", "placeholders", "pagepermission_set"], exclude_fields=exclude_fields)
def _reversion(): exclude_fields = ['publisher_is_draft', 'publisher_public', 'publisher_state'] reversion_register( Page, follow=["title_set", "placeholders", "pagepermission_set"], exclude_fields=exclude_fields )
def register_plugin(self, plugin): #from cms.plugins import CMSPluginBase assert issubclass(plugin, CMSPluginBase) if plugin.__name__ in self.plugins.keys(): raise PluginAllreadyRegistered, "[%s] a plugin with this name is already registered" % plugin.__name__ plugin.value = plugin.__name__ self.plugins[plugin.__name__] = plugin if 'reversion' in settings.INSTALLED_APPS: try: from reversion.registration import RegistrationError except ImportError: from reversion.revisions import RegistrationError try: reversion_register(plugin.model, follow=["cmsplugin_ptr"]) except RegistrationError: pass
def register_type(type_name, model_class): from cms.utils.helpers import reversion_register from .models import TextNG, TextNGVariableBase try: from reversion import unregister except ImportError: from reversion.revisions import unregister if type_name in _registry: if _registry[type_name] == model_class: # already registered return else: raise exceptions.VariableTypeAlreadyRegistered( 'The type "%s" is already registered by %s' % (type_name, _registry[type_name].__name__)) if not issubclass(model_class, TextNGVariableBase): raise exceptions.InvalidType( '%s is not a subclass of TextNGVariableBase' % model_class.__name__) try: field = model_class._meta.get_field_by_name('value')[0] except FieldDoesNotExist: raise exceptions.InvalidType('%s does not define a "value" field' % model_class.__name__) if not field.null: raise exceptions.InvalidType('"value" field of %s is not nullable' % model_class.__name__) _registry[type_name] = model_class fields = [ rel.get_accessor_name() for rel in TextNG._meta.get_all_related_objects() if issubclass(rel.related_model, TextNGVariableBase) ] try: #TextNG registration need to be upgraded unregister(TextNG) except: pass reversion_register(TextNG, follow=fields) reversion_register(model_class)
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
def register_type(type_name, model_class): from cms.utils.helpers import reversion_register from .models import TextNG, TextNGVariableBase try: from reversion import unregister except ImportError: from reversion.revisions import unregister if type_name in _registry: if _registry[type_name] == model_class: # already registered return else: raise exceptions.VariableTypeAlreadyRegistered( 'The type "%s" is already registered by %s' % (type_name, _registry[type_name].__name__) ) if not issubclass(model_class, TextNGVariableBase): raise exceptions.InvalidType('%s is not a subclass of TextNGVariableBase' % model_class.__name__) try: field = model_class._meta.get_field_by_name('value')[0] except FieldDoesNotExist: raise exceptions.InvalidType('%s does not define a "value" field' % model_class.__name__) if not field.null: raise exceptions.InvalidType('"value" field of %s is not nullable' % model_class.__name__) _registry[type_name] = model_class fields = [ rel.get_accessor_name() for rel in TextNG._meta.get_all_related_objects() if issubclass(rel.related_model, TextNGVariableBase)] try: #TextNG registration need to be upgraded unregister(TextNG) except: pass reversion_register(TextNG, follow=fields) reversion_register(model_class)
def register_plugin(self, plugin): """ Registers the given plugin(s). 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) if plugin.render_plugin and not type( plugin.render_plugin) == property or hasattr( plugin.model, 'render_template'): if plugin.render_template is None and not hasattr( plugin.model, 'render_template'): raise ImproperlyConfigured( "CMS Plugins must define a render template or set render_plugin=False: %s" % plugin) else: from django.template import loader template = hasattr( plugin.model, 'render_template' ) and plugin.model.render_template or plugin.render_template if isinstance(template, string_types) and template: try: loader.get_template(template) except TemplateDoesNotExist: raise ImproperlyConfigured( "CMS Plugins must define a render template (%s) that exist: %s" % (plugin, template)) except TemplateSyntaxError: pass else: if plugin.allow_children: raise ImproperlyConfigured( "CMS Plugins can not define render_plugin=False and allow_children=True: %s" % 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 'reversion' in settings.INSTALLED_APPS: try: from reversion.registration import RegistrationError except ImportError: from reversion.revisions import RegistrationError try: reversion_register(plugin.model) except RegistrationError: pass
def register_plugin(self, plugin): """ Registers the given plugin(s). 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 ) if (plugin.render_plugin and not type(plugin.render_plugin) == property or hasattr(plugin.model, 'render_template') or hasattr(plugin, 'get_render_template')): if (plugin.render_template is None and not hasattr(plugin.model, 'render_template') and not hasattr(plugin, 'get_render_template')): raise ImproperlyConfigured( "CMS Plugins must define a render template, " "a get_render_template method or " "set render_plugin=False: %s" % plugin ) # If plugin class defines get_render_template we cannot # statically check for valid template file as it depends # on plugin configuration and context. # We cannot prevent developer to shoot in the users' feet elif not hasattr(plugin, 'get_render_template'): from django.template import loader template = ((hasattr(plugin.model, 'render_template') and plugin.model.render_template) or plugin.render_template) if isinstance(template, six.string_types) and template: try: loader.get_template(template) except TemplateDoesNotExist as e: # Note that the template loader will throw # TemplateDoesNotExist if the plugin's render_template # does in fact exist, but it includes a template that # doesn't. if six.text_type(e) == template: raise ImproperlyConfigured( "CMS Plugins must define a render template (%s) that exists: %s" % (plugin, template) ) else: pass except TemplateSyntaxError: pass else: if plugin.allow_children: raise ImproperlyConfigured( "CMS Plugins can not define render_plugin=False and allow_children=True: %s" % 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 reversion.revisions import RegistrationError try: reversion_register(plugin.model) except RegistrationError: pass return plugin
from cms.utils.helpers import reversion_register from django.db import models class FileModel(models.Model): test_file = models.FileField(upload_to='fileapp/', blank=True, null=True) reversion_register(FileModel)
""" Returns language objects for every language for which the placeholder has plugins. This is not cached as it's meant to eb used in the frontend editor. """ languages = [] for lang_code in set(self.get_plugins().values_list('language', flat=True)): try: languages.append(get_language_object(lang_code)) except LanguageError: pass return languages def get_cached_plugins(self): return getattr(self, '_plugins_cache', []) @property def actions(self): if not hasattr(self, '_actions_cache'): field = self._get_attached_field() self._actions_cache = getattr(field, 'actions', PlaceholderNoAction()) return self._actions_cache reversion_register( Placeholder ) # follow=["cmsplugin_set"] not following plugins since they are a spechial case
# Stores the actual data class Snippet(models.Model): """ A snippet of HTML or a Django template """ name = models.CharField(_("name"), max_length=255, unique=True) html = models.TextField(_("HTML"), blank=True) template = models.CharField(_("template"), max_length=50, blank=True, \ help_text=_('Enter a template (i.e. "snippets/plugin_xy.html") which will be rendered. ' + \ 'If "template" is given, the contents of field "HTML" will be passed as template variable {{ html }} to the template. ' + \ 'Else, the content of "HTML" is rendered.')) def __unicode__(self): return self.name class Meta: ordering = ['name'] # Plugin model - just a pointer to Snippet class SnippetPtr(CMSPlugin): snippet = models.ForeignKey(Snippet) class Meta: verbose_name = _("Snippet") search_fields = ('snippet__html',) # We don't both with SnippetPtr, since all the data is actually in Snippet reversion_register(Snippet)
def overwrite_url(self): """Return overrwriten url, or None """ if self.has_url_overwrite: return self.path return None class EmptyTitle(object): """Empty title object, can be returned from Page.get_title_obj() if required title object doesn't exists. """ title = "" slug = "" path = "" meta_description = "" meta_keywords = "" redirect = "" has_url_overwite = False application_urls = "" menu_title = "" page_title = "" @property def overwrite_url(self): return None reversion_register(Title)
@property def overwrite_url(self): """Return overrwriten url, or None """ if self.has_url_overwrite: return self.path return None class EmptyTitle(object): """Empty title object, can be returned from Page.get_title_obj() if required title object doesn't exists. """ title = "" slug = "" path = "" meta_description = "" meta_keywords = "" redirect = "" has_url_overwite = False application_urls = "" menu_title = "" page_title = "" @property def overwrite_url(self): return None reversion_register(Title)
return self.publisher_public.published #return is_public_published(self) return False def requires_approvement(self): return self.moderator_state in (Page.MODERATOR_NEED_APPROVEMENT, Page.MODERATOR_NEED_DELETE_APPROVEMENT) def get_moderation_value(self, user): """Returns page moderation value for given user, moderation value is sum of moderations. """ moderation_value = getattr(self, '_moderation_value_cahce', None) if moderation_value is not None and self._moderation_value_cache_for_user_id == user.pk: return moderation_value try: page_moderator = self.pagemoderator_set.get(user=user) except ObjectDoesNotExist: return 0 moderation_value = page_moderator.get_decimal() self._moderation_value_cahce = moderation_value self._moderation_value_cache_for_user_id = user return moderation_value reversion_register(Page, follow=["title_set", "cmsplugin_set", "pagepermission_set"])
if field.count(): self._attached_field_cache = rel.field return self._attached_field_cache def _get_attached_field_name(self): field = self._get_attached_field() if field: return field.name return None def _get_attached_model(self): field = self._get_attached_field() if field: return field.model return None def get_plugins_list(self): return list(self.get_plugins()) def get_plugins(self): return self.cmsplugin_set.all().order_by('tree_id', '-rght') @property def actions(self): if not hasattr(self, '_actions_cache'): field = self._get_attached_field() self._actions_cache = getattr(field, 'actions', PlaceholderNoAction()) return self._actions_cache reversion_register(Placeholder, follow=["cmsplugin_set"])
return self.public_published_cache # othervise make db lookup if self.publisher_public_id: return self.publisher_public.published #return is_public_published(self) return False def requires_approvement(self): return self.moderator_state in (Page.MODERATOR_NEED_APPROVEMENT, Page.MODERATOR_NEED_DELETE_APPROVEMENT) def get_moderation_value(self, user): """Returns page moderation value for given user, moderation value is sum of moderations. """ moderation_value = getattr(self, '_moderation_value_cahce', None) if moderation_value is not None and self._moderation_value_cache_for_user_id == user.pk: return moderation_value try: page_moderator = self.pagemoderator_set.get(user=user) except ObjectDoesNotExist: return 0 moderation_value = page_moderator.get_decimal() self._moderation_value_cahce = moderation_value self._moderation_value_cache_for_user_id = user return moderation_value reversion_register(Page, follow=["title_set", "placeholders", "pagepermission_set"])
reverse("admin:%s_%s_edit_plugin" % (Page._meta.app_label, Page._meta.module_name), args=[parent.pk])) breadcrumb.append({'title': force_unicode(parent.get_plugin_name()), 'url': url}) return breadcrumb def get_breadcrumb_json(self): result = simplejson.dumps(self.get_breadcrumb()) result = mark_safe(result) return result def num_children(self): if self.child_plugin_instances: return len(self.child_plugin_instances) reversion_register(CMSPlugin) def deferred_class_factory(model, attrs): """ Returns a class object that is a copy of "model" with the specified "attrs" being replaced with DeferredAttribute objects. The "pk_value" ties the deferred attributes to a particular instance of the model. """ class Meta: pass setattr(Meta, "proxy", True) setattr(Meta, "app_label", model._meta.app_label)
raise ValidationError( _("A static placeholder with the same site and code already exists" )) def publish(self, request, language, force=False): if force or self.has_publish_permission(request): self.public.clear(language=language) plugins = self.draft.get_plugins_list(language=language) copy_plugins_to(plugins, self.public, no_signals=True) self.dirty = False self.save() return True return False def has_change_permission(self, request): if request.user.is_superuser: return True opts = self._meta return request.user.has_perm(opts.app_label + '.' + get_permission_codename('change', opts)) def has_publish_permission(self, request): if request.user.is_superuser: return True opts = self._meta return request.user.has_perm(opts.app_label + '.' + get_permission_codename('change', opts)) and \ request.user.has_perm(opts.app_label + '.' + 'publish_page') reversion_register(StaticPlaceholder)
def register_plugin(self, plugin): """ Registers the given plugin(s). 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 ) if plugin.render_plugin and not type(plugin.render_plugin) == property or hasattr(plugin.model, 'render_template'): if plugin.render_template is None and not hasattr(plugin.model, 'render_template'): raise ImproperlyConfigured( "CMS Plugins must define a render template or set render_plugin=False: %s" % plugin ) else: from django.template import loader template = hasattr(plugin.model, 'render_template') and plugin.model.render_template or plugin.render_template if isinstance(template, string_types) and template: try: loader.get_template(template) except TemplateDoesNotExist: raise ImproperlyConfigured( "CMS Plugins must define a render template (%s) that exist: %s" % (plugin, template) ) except TemplateSyntaxError: pass else: if plugin.allow_children: raise ImproperlyConfigured( "CMS Plugins can not define render_plugin=False and allow_children=True: %s" % 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 'reversion' in settings.INSTALLED_APPS: try: from reversion.registration import RegistrationError except ImportError: from reversion.revisions import RegistrationError try: reversion_register(plugin.model) except RegistrationError: pass
if field.count(): self._attached_field_cache = rel.field return self._attached_field_cache def _get_attached_field_name(self): field = self._get_attached_field() if field: return field.name return None def _get_attached_model(self): field = self._get_attached_field() if field: return field.model return None def get_plugins_list(self): return list(self.get_plugins()) def get_plugins(self): return self.cmsplugin_set.all().order_by('tree_id', '-rght') @property def actions(self): if not hasattr(self, '_actions_cache'): field = self._get_attached_field() self._actions_cache = getattr(field, 'actions', PlaceholderNoAction()) return self._actions_cache reversion_register(Placeholder) # follow=["cmsplugin_set"] not following plugins since they are a spechial case
from django.db import models from django.utils.translation import ugettext_lazy as _ from cms.models import CMSPlugin, Page from cms.utils.helpers import reversion_register class NavMenu(CMSPlugin): """ Plugin model for a sub-section navigation menu """ title = models.CharField(_("menu title"), max_length=255, blank=True, default="", help_text=_("Defaults to section page title if left blank.")) section = models.ForeignKey(Page, blank=True, null=True, help_text=_("Defaults to the root of current page if left blank.")) collapse = models.BooleanField(_("collapse menu"), default=False, help_text="Select this option if the menu should initially appear collapsed.") class Meta: verbose_name = _("Section Nav. Menu") def __unicode__(self): return self.title reversion_register(NavMenu)
class NavMenu(CMSPlugin): """ Plugin model for a sub-section navigation menu """ title = models.CharField( _("menu title"), max_length=255, blank=True, default="", help_text=_("Defaults to section page title if left blank.")) section = models.ForeignKey( Page, blank=True, null=True, help_text=_("Defaults to the root of current page if left blank.")) collapse = models.BooleanField( _("collapse menu"), default=False, help_text= "Select this option if the menu should initially appear collapsed.") class Meta: verbose_name = _("Section Nav. Menu") def __unicode__(self): return self.title reversion_register(NavMenu)
return self.public_published_cache # othervise make db lookup if self.publisher_public_id: return self.publisher_public.published #return is_public_published(self) return False def requires_approvement(self): return self.moderator_state in (Page.MODERATOR_NEED_APPROVEMENT, Page.MODERATOR_NEED_DELETE_APPROVEMENT) def get_moderation_value(self, user): """Returns page moderation value for given user, moderation value is sum of moderations. """ moderation_value = getattr(self, '_moderation_value_cahce', None) if moderation_value is not None and self._moderation_value_cache_for_user_id == user.pk: return moderation_value try: page_moderator = self.pagemoderator_set.get(user=user) except ObjectDoesNotExist: return 0 moderation_value = page_moderator.get_decimal() self._moderation_value_cahce = moderation_value self._moderation_value_cache_for_user_id = user return moderation_value reversion_register(Page, follow=["title_set", "cmsplugin_set", "pagepermission_set"])
verbose_name = _("Snippet") verbose_name_plural = _("Snippets") # Plugin model - just a pointer to Snippet @python_2_unicode_compatible class SnippetPtr(CMSPlugin): # Add an app namespace to related_name to avoid field name clashes # with any other plugins that have a field with the same name as the # lowercase of the class name of this model. # https://github.com/divio/django-cms/issues/5030 cmsplugin_ptr = models.OneToOneField( CMSPlugin, related_name='djangocms_snippet_snippetptr', parent_link=True) snippet = models.ForeignKey(Snippet) search_fields = ['snippet__html'] if SEARCH_ENABLED else [] class Meta: verbose_name = _("Snippet") def __str__(self): # Return the referenced snippet's name rather than the default (ID #) return self.snippet.name # We don't both with SnippetPtr, since all the data is actually in Snippet reversion_register(Snippet)
@property def delete_url(self): """ Returns a custom url to delete plugin instances """ return None @property def copy_url(self): """ Returns a custom url to copy plugin instances """ return None reversion_register(CMSPlugin) def get_plugin_media_path(instance, filename): """ Django 1.7 requires that unbound function used in fields' definitions are defined outside the parent class (see https://docs.djangoproject.com/en/dev/topics/migrations/#serializing-values) This function is used withing field definition: file = models.FileField(_("file"), upload_to=get_plugin_media_path) and it invokes the bounded method on the given instance at runtime """ return instance.get_media_path(filename)
app_label = 'cms' def __str__(self): page = self.page_id and force_text(self.page) or "None" return "%s :: %s has: %s" % (page, self.audience, force_text(dict(ACCESS_CHOICES)[self.grant_on])) class PageUser(User): """Cms specific user data, required for permission system """ created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="created_users") class Meta: verbose_name = _('User (page)') verbose_name_plural = _('Users (page)') app_label = 'cms' class PageUserGroup(Group): """Cms specific group data, required for permission system """ created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="created_usergroups") class Meta: verbose_name = _('User group (page)') verbose_name_plural = _('User groups (page)') app_label = 'cms' reversion_register(PagePermission)
return "%s :: %s has: %s" % (page, self.audience, force_unicode( dict(ACCESS_CHOICES)[self.grant_on])) class PageUser(User): """Cms specific user data, required for permission system """ created_by = models.ForeignKey(user_model_label, related_name="created_users") class Meta: verbose_name = _('User (page)') verbose_name_plural = _('Users (page)') app_label = 'cms' class PageUserGroup(Group): """Cms specific group data, required for permission system """ created_by = models.ForeignKey(user_model_label, related_name="created_usergroups") class Meta: verbose_name = _('User group (page)') verbose_name_plural = _('User groups (page)') app_label = 'cms' reversion_register(PagePermission)
return self.cmsplugin_set.all().order_by('path') def get_filled_languages(self): """ Returns language objects for every language for which the placeholder has plugins. This is not cached as it's meant to eb used in the frontend editor. """ languages = [] for lang_code in set(self.get_plugins().values_list('language', flat=True)): try: languages.append(get_language_object(lang_code)) except LanguageError: pass return languages def get_cached_plugins(self): return getattr(self, '_plugins_cache', []) @property def actions(self): from cms.utils.placeholder import PlaceholderNoAction if not hasattr(self, '_actions_cache'): field = self._get_attached_field() self._actions_cache = getattr(field, 'actions', PlaceholderNoAction()) return self._actions_cache reversion_register(Placeholder)
html = models.TextField(_("html"), blank=True) startDateTime = models.DateTimeField() endDateTime = models.DateTimeField() def __unicode__(self): return self.name class Meta: ordering = ["name"] verbose_name = _("ScheduledSnippet") verbose_name_plural = _("ScheduledSnippets") # Plugin model - just a pointer to ScheduledSnippet class ScheduledSnippetPtr(CMSPlugin): snippet = models.ForeignKey(ScheduledSnippet) class Meta: verbose_name = _("ScheduledSnippet") search_fields = ("snippet__html",) def __unicode__(self): # Return the referenced snippet's name rather than the default (ID #) return self.snippet.name # We don't both with ScheduledSnippetPtr, since all the data is actually in ScheduledSnippet reversion_register(ScheduledSnippet)
language = get_language_from_request(request, self.page) for instance, plugin in inner_plugin_iterator(language): if not instance: continue vary_on = plugin.get_vary_cache_on(request, instance, self) if not vary_on: # None, or an empty iterable continue if isinstance(vary_on, six.string_types): if vary_on.lower() not in vary_list: vary_list.add(vary_on.lower()) else: try: for vary_on_item in iter(vary_on): if vary_on_item.lower() not in vary_list: vary_list.add(vary_on_item.lower()) except TypeError: warnings.warn( 'Plugin %(plugin_class)s (%(pk)d) returned ' 'unexpected value %(value)s for ' 'get_vary_cache_on(), ignoring.' % { 'plugin_class': plugin.__class__.__name__, 'pk': instance.pk, 'value': force_text(vary_on), }) return sorted(list(vary_list)) reversion_register(Placeholder)
startDateTime = models.DateTimeField() endDateTime = models.DateTimeField() def __unicode__(self): return self.name class Meta: ordering = ['name'] verbose_name = _("ScheduledSnippet") verbose_name_plural = _("ScheduledSnippets") # Plugin model - just a pointer to ScheduledSnippet class ScheduledSnippetPtr(CMSPlugin): snippet = models.ForeignKey(ScheduledSnippet) class Meta: verbose_name = _("ScheduledSnippet") search_fields = ('snippet__html',) def __unicode__(self): # Return the referenced snippet's name rather than the default (ID #) return self.snippet.name # We don't both with ScheduledSnippetPtr, since all the data is actually in ScheduledSnippet reversion_register(ScheduledSnippet)