def fill_empty_template_value(apps, schema_editor): """ Get every plugin entries to fill "template" field value if empty with default template """ LatestEntriesPlugin = apps.get_model("cmsplugin_zinnia", "LatestEntriesPlugin") for entry in LatestEntriesPlugin.objects.all(): if not entry.template_to_render: entry.template_to_render = get_default_template() entry.save() SelectedEntriesPlugin = apps.get_model("cmsplugin_zinnia", "SelectedEntriesPlugin") for entry in SelectedEntriesPlugin.objects.all(): if not entry.template_to_render: entry.template_to_render = get_default_template() entry.save() RandomEntriesPlugin = apps.get_model("cmsplugin_zinnia", "RandomEntriesPlugin") for entry in RandomEntriesPlugin.objects.all(): if not entry.template_to_render: entry.template_to_render = get_default_template() entry.save() QueryEntriesPlugin = apps.get_model("cmsplugin_zinnia", "QueryEntriesPlugin") for entry in QueryEntriesPlugin.objects.all(): if not entry.template_to_render: entry.template_to_render = get_default_template() entry.save()
class Migration(migrations.Migration): dependencies = [ ('cmsplugin_zinnia', '0002_fix_djangocms330_incompatible_change'), ] operations = [ migrations.AlterField( model_name='latestentriesplugin', name='template_to_render', field=models.CharField( blank=False, choices=get_template_choices(), default=get_default_template(), help_text='template used to display the plugin', max_length=250, verbose_name='template'), ), migrations.AlterField( model_name='queryentriesplugin', name='template_to_render', field=models.CharField( blank=False, choices=get_template_choices(), default=get_default_template(), help_text='template used to display the plugin', max_length=250, verbose_name='template'), ), migrations.AlterField( model_name='randomentriesplugin', name='template_to_render', field=models.CharField( blank=False, choices=get_template_choices(), default=get_default_template(), help_text='template used to display the plugin', max_length=250, verbose_name='template'), ), migrations.AlterField( model_name='selectedentriesplugin', name='template_to_render', field=models.CharField( blank=False, choices=get_template_choices(), default=get_default_template(), help_text='template used to display the plugin', max_length=250, verbose_name='template'), ), ]
class SelectedEntriesPlugin(CMSPlugin): """ CMS Plugin for displaying custom entries """ entries = models.ManyToManyField('zinnia.Entry', verbose_name=_('entries')) template_to_render = models.CharField( _('template'), blank=True, max_length=250, choices=get_template_choices(), default=get_default_template(), help_text=_('template used to display the plugin')) @property def render_template(self): """ Override render_template to use the template_to_render attribute """ return self.template_to_render def copy_relations(self, old_instance): """ Duplicate ManyToMany relations on plugin copy """ self.entries.set(old_instance.entries.all()) def __str__(self): return _('%s entries') % self.entries.count()
class QueryEntriesPlugin(CMSPlugin): """ CMS Plugin for displaying entries based on a search pattern """ query = models.CharField( _('query'), max_length=250, help_text=_( 'You can use - to exclude words or phrases, "double ' 'quotes" for exact phrases and the AND/OR boolean ' 'operators combined with parenthesis for complex queries.')) number_of_entries = models.PositiveIntegerField( _('number of entries'), default=5, help_text=_('0 means all the entries')) template_to_render = models.CharField( _('template'), blank=True, max_length=250, choices=get_template_choices(), default=get_default_template(), help_text=_('template used to display the plugin')) @property def render_template(self): """ Override render_template to use the template_to_render attribute """ return self.template_to_render def __str__(self): return _('%s entries') % self.number_of_entries
class LatestEntriesPlugin(CMSPlugin): """ CMS Plugin for displaying latest entries """ featured = models.BooleanField(_('featured'), blank=True, null=True, choices=((True, _('Show featured entries only')), (False, _('Hide featured entries')))) categories = models.ManyToManyField('zinnia.Category', verbose_name=_('categories'), blank=True) subcategories = models.BooleanField( _('include subcategories'), default=True, help_text=_('include the entries belonging the subcategories')) authors = models.ManyToManyField('zinnia.Author', verbose_name=_('authors'), blank=True) tags = models.ManyToManyField('tagging.Tag', verbose_name=_('tags'), blank=True) number_of_entries = models.PositiveIntegerField( _('number of entries'), default=5, help_text=_('0 means all the entries')) offset = models.PositiveIntegerField( _('offset'), default=0, help_text=_('number of entries to skip from top of list')) template_to_render = models.CharField( _('template'), blank=False, max_length=250, choices=get_template_choices(), default=get_default_template(), help_text=_('template used to display the plugin')) @property def render_template(self): """ Override render_template to use the template_to_render attribute """ return self.template_to_render def copy_relations(self, old_instance): """ Duplicate ManyToMany relations on plugin copy """ self.tags.set(old_instance.tags.all()) self.authors.set(old_instance.authors.all()) self.categories.set(old_instance.categories.all()) def __str__(self): return _('%s entries') % self.number_of_entries
class RandomEntriesPlugin(CMSPlugin): """ CMS Plugin for displaying random entries """ number_of_entries = models.PositiveIntegerField(_('number of entries'), default=5) template_to_render = models.CharField( _('template'), blank=True, max_length=250, choices=get_template_choices(), default=get_default_template(), help_text=_('template used to display the plugin')) def __str__(self): return _('%s entries') % self.number_of_entries