commit
c88e641846
9 changed files with 95 additions and 5 deletions
|
@ -25,6 +25,7 @@ HELPER_SETTINGS = dict(
|
|||
'taggit_autosuggest',
|
||||
'aldryn_apphooks_config',
|
||||
'aldryn_search',
|
||||
'sortedm2m',
|
||||
],
|
||||
LANGUAGE_CODE='en',
|
||||
LANGUAGES=(
|
||||
|
|
|
@ -88,6 +88,9 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
|
|||
(None, {
|
||||
'fields': [['title', 'categories', 'publish', 'app_config']]
|
||||
}),
|
||||
(None, {
|
||||
'fields': [['related', ]]
|
||||
}),
|
||||
(_('Info'), {
|
||||
'fields': [['slug', 'tags'],
|
||||
['date_published', 'date_published_end', 'date_featured'],
|
||||
|
@ -244,7 +247,7 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
|
|||
if request.user.is_superuser:
|
||||
fsets[1][1]['fields'][0].append('author')
|
||||
if apps.is_installed('djangocms_blog.liveblog'):
|
||||
fsets[1][1]['fields'][2].append('enable_liveblog')
|
||||
fsets[2][1]['fields'][2].append('enable_liveblog')
|
||||
filter_function = get_setting('ADMIN_POST_FIELDSET_FILTER')
|
||||
if callable(filter_function):
|
||||
fsets = filter_function(fsets, request, obj=obj)
|
||||
|
@ -289,7 +292,6 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
|
|||
|
||||
|
||||
class BlogConfigAdmin(BaseAppHookConfig, TranslatableAdmin):
|
||||
|
||||
@property
|
||||
def declared_fieldsets(self):
|
||||
return self.get_fieldsets(None)
|
||||
|
|
9
djangocms_blog/fields.py
Normal file
9
djangocms_blog/fields.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django.db.models import SlugField
|
||||
|
||||
__all__ = ['AutoSlugField']
|
||||
|
||||
|
||||
class AutoSlugField(SlugField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.allow_unicode = kwargs.pop('allow_unicode', False)
|
||||
super(SlugField, self).__init__(*args, **kwargs)
|
20
djangocms_blog/migrations/0029_post_related.py
Normal file
20
djangocms_blog/migrations/0029_post_related.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-04-07 07:35
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('djangocms_blog', '0028_auto_20170304_1040'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='post',
|
||||
name='related',
|
||||
field=models.ManyToManyField(blank=True, to='djangocms_blog.Post', verbose_name='Related Posts'),
|
||||
),
|
||||
]
|
21
djangocms_blog/migrations/0030_auto_20170509_1831.py
Normal file
21
djangocms_blog/migrations/0030_auto_20170509_1831.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-07-22 05:28
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
import djangocms_blog.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('djangocms_blog', '0029_post_related'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='posttranslation',
|
||||
name='slug',
|
||||
field=djangocms_blog.fields.AutoSlugField(allow_unicode=True, blank=True, db_index=False, max_length=255, verbose_name='slug'),
|
||||
),
|
||||
]
|
22
djangocms_blog/migrations/0031_auto_20170610_1744.py
Normal file
22
djangocms_blog/migrations/0031_auto_20170610_1744.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-06-10 12:14
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
import sortedm2m.fields
|
||||
from sortedm2m.operations import AlterSortedManyToManyField
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('djangocms_blog', '0030_auto_20170509_1831'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
AlterSortedManyToManyField(
|
||||
model_name='post',
|
||||
name='related',
|
||||
field=sortedm2m.fields.SortedManyToManyField(blank=True, help_text=None, to='djangocms_blog.Post', verbose_name='Related Posts'),
|
||||
),
|
||||
]
|
|
@ -3,6 +3,7 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||
|
||||
import hashlib
|
||||
|
||||
import django
|
||||
from aldryn_apphooks_config.fields import AppHookConfigField
|
||||
from aldryn_apphooks_config.managers.parler import AppHookConfigTranslatableManager
|
||||
from cms.models import CMSPlugin, PlaceholderField
|
||||
|
@ -25,9 +26,11 @@ from filer.fields.image import FilerImageField
|
|||
from meta.models import ModelMeta
|
||||
from parler.models import TranslatableModel, TranslatedFields
|
||||
from parler.utils.context import switch_language
|
||||
from sortedm2m.fields import SortedManyToManyField
|
||||
from taggit_autosuggest.managers import TaggableManager
|
||||
|
||||
from .cms_appconfig import BlogConfig
|
||||
from .fields import AutoSlugField
|
||||
from .managers import GenericDateTaggedManager
|
||||
from .settings import get_setting
|
||||
|
||||
|
@ -171,7 +174,8 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
|
|||
|
||||
translations = TranslatedFields(
|
||||
title=models.CharField(_('title'), max_length=255),
|
||||
slug=models.SlugField(_('slug'), max_length=255, blank=True, db_index=True),
|
||||
slug=AutoSlugField(_('slug'), max_length=255, blank=True,
|
||||
db_index=True, allow_unicode=True),
|
||||
abstract=HTMLField(_('abstract'), blank=True, default=''),
|
||||
meta_description=models.TextField(verbose_name=_('post meta description'),
|
||||
blank=True, default=''),
|
||||
|
@ -186,11 +190,17 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
|
|||
)
|
||||
content = PlaceholderField('post_content', related_name='post_content')
|
||||
liveblog = PlaceholderField('live_blog', related_name='live_blog')
|
||||
enable_liveblog = models.BooleanField(verbose_name=_('enable liveblog on post'), default=False)
|
||||
enable_liveblog = models.BooleanField(verbose_name=_('enable liveblog on post'),
|
||||
default=False)
|
||||
|
||||
objects = GenericDateTaggedManager()
|
||||
tags = TaggableManager(blank=True, related_name='djangocms_blog_tags')
|
||||
|
||||
related = SortedManyToManyField('self',
|
||||
verbose_name=_('Related Posts'),
|
||||
blank=True,
|
||||
symmetrical=False)
|
||||
|
||||
_metadata = {
|
||||
'title': 'get_title',
|
||||
'description': 'get_description',
|
||||
|
@ -251,6 +261,9 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
|
|||
if self.publish and self.date_published is None:
|
||||
self.date_published = timezone.now()
|
||||
if not self.slug and self.title:
|
||||
if django.VERSION >= (1, 9):
|
||||
self.slug = slugify(self.title, allow_unicode=True)
|
||||
else:
|
||||
self.slug = slugify(self.title)
|
||||
super(Post, self).save(*args, **kwargs)
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ Add ``djangocms_blog`` and its dependencies to INSTALLED_APPS::
|
|||
'taggit',
|
||||
'taggit_autosuggest',
|
||||
'meta',
|
||||
'sortedm2m',
|
||||
'djangocms_blog',
|
||||
...
|
||||
]
|
||||
|
|
1
setup.py
1
setup.py
|
@ -41,6 +41,7 @@ setup(
|
|||
'django-meta-mixin>=0.3',
|
||||
'aldryn-apphooks-config>=0.2.6',
|
||||
'djangocms-apphook-setup',
|
||||
'django-sortedm2m',
|
||||
],
|
||||
extras_require={
|
||||
'search': ['aldryn-search'],
|
||||
|
|
Loading…
Reference in a new issue