Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
``get_absolute_url`` implementation.
"""
# NOTE! All categories require a matching entry in
# app.pages.models.Page.APPLICATIONS.
CATEGORIES = (
('blog', _('blog')),
('publications', _('publications')),
)
is_active = models.BooleanField(_('is active'), default=False)
title = models.CharField(_('title'), max_length=200)
slug = models.SlugField(_('slug'), unique_for_year='publication_date')
publication_date = models.DateTimeField(
_('publication date'), default=timezone.now)
body = CleansedRichTextField(_('body'))
category = models.CharField(
_('category'),
max_length=20,
db_index=True,
choices=CATEGORIES,
)
objects = ArticleManager()
class Meta:
get_latest_by = 'publication_date'
ordering = ['-publication_date']
verbose_name = _('article')
verbose_name_plural = _('articles')
def __str__(self):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Article',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('is_active', models.BooleanField(default=False, verbose_name='is active')),
('title', models.CharField(max_length=200, verbose_name='title')),
('slug', models.SlugField(unique_for_year='publication_date', verbose_name='slug')),
('publication_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='publication date')),
('body', feincms3.cleanse.CleansedRichTextField(verbose_name='body')),
('category', models.CharField(choices=[('blog', 'blog'), ('publications', 'publications')], db_index=True, max_length=20, verbose_name='category')),
],
options={
'verbose_name': 'article',
'ordering': ['-publication_date'],
'get_latest_by': 'publication_date',
'verbose_name_plural': 'articles',
},
),
migrations.CreateModel(
name='Image',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', imagefield.fields.ImageField(height_field='height', upload_to='images/%Y/%m', verbose_name='image', width_field='width')),
('width', models.PositiveIntegerField(blank=True, editable=False, null=True, verbose_name='image width')),
('height', models.PositiveIntegerField(blank=True, editable=False, null=True, verbose_name='image height')),
('position', models.PositiveIntegerField(db_index=True, default=0, editable=False)),
('path', models.CharField(blank=True, help_text="Generated automatically if 'static path' is unset.", max_length=1000, unique=True, validators=[django.core.validators.RegexValidator(message='Path must start and end with a slash (/).', regex='^/(|.+/)$')], verbose_name='path')),
('static_path', models.BooleanField(default=False, verbose_name='static path')),
('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='pages.Page')),
],
options={
'verbose_name': 'page',
'verbose_name_plural': 'pages',
'abstract': False,
},
),
migrations.CreateModel(
name='RichText',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', feincms3.cleanse.CleansedRichTextField(verbose_name='text')),
('region', models.CharField(max_length=255)),
('ordering', models.IntegerField(default=0)),
('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pages_richtext_set', to='pages.Page')),
],
options={
'verbose_name': 'rich text',
'verbose_name_plural': 'rich texts',
'abstract': False,
},
),
migrations.AddField(
model_name='image',
name='parent',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pages_image_set', to='pages.Page'),
),
__all__ = ("RichText", "RichTextInline", "render_richtext")
class RichText(models.Model):
"""
Rich text plugin
To use this, a `django-ckeditor
`_ configuration named
``richtext-plugin`` is required. See the section :mod:`HTML cleansing
` for the recommended configuration.
"""
text = CleansedRichTextField(_("text"), config_name="richtext-plugin")
class Meta:
abstract = True
verbose_name = _("rich text")
verbose_name_plural = _("rich texts")
def __str__(self):
# Return the first few words of the content (with tags stripped)
return Truncator(strip_tags(self.text)).words(10, truncate=" ...")
class RichTextInline(ContentEditorInline):
"""
The only difference with the standard ``ContentEditorInline`` is that this
inline adds the ``feincms3/plugin_ckeditor.js`` file which handles the
CKEditor widget activation and deactivation inside the content editor.