Merge pull request #132 from skirsdeda/feature/optabstract

Make Post.abstract optional
This commit is contained in:
Iacopo Spalletti 2015-07-20 05:23:19 +02:00
commit 3629cee267
7 changed files with 233 additions and 3 deletions

View file

@ -33,7 +33,7 @@ class PostAdmin(EnhancedModelAdminMixin, FrontendEditableAdminMixin,
enhance_exclude = ('main_image', 'tags') enhance_exclude = ('main_image', 'tags')
_fieldsets = [ _fieldsets = [
(None, { (None, {
'fields': [('title', 'categories', 'publish'), 'abstract'] 'fields': [('title', 'categories', 'publish')]
}), }),
('Info', { ('Info', {
'fields': (['slug', 'tags'], 'fields': (['slug', 'tags'],
@ -62,6 +62,8 @@ class PostAdmin(EnhancedModelAdminMixin, FrontendEditableAdminMixin,
def get_fieldsets(self, request, obj=None): def get_fieldsets(self, request, obj=None):
fsets = deepcopy(self._fieldsets) fsets = deepcopy(self._fieldsets)
if get_setting('USE_ABSTRACT'):
fsets[0][1]['fields'].append('abstract')
if not get_setting('USE_PLACEHOLDER'): if not get_setting('USE_PLACEHOLDER'):
fsets[0][1]['fields'].append('post_text') fsets[0][1]['fields'].append('post_text')
if get_setting('MULTISITE'): if get_setting('MULTISITE'):

View file

@ -5,6 +5,7 @@ from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from .models import Post from .models import Post
from .settings import get_setting
class LatestEntriesFeed(Feed): class LatestEntriesFeed(Feed):
@ -22,7 +23,9 @@ class LatestEntriesFeed(Feed):
return item.safe_translation_getter('title') return item.safe_translation_getter('title')
def item_description(self, item): def item_description(self, item):
if get_setting('USE_ABSTRACT'):
return item.safe_translation_getter('abstract') return item.safe_translation_getter('abstract')
return item.safe_translation_getter('post_text')
class TagFeed(LatestEntriesFeed): class TagFeed(LatestEntriesFeed):

View file

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import djangocms_text_ckeditor.fields
class Migration(migrations.Migration):
dependencies = [
('djangocms_blog', '0005_auto_20150212_1118'),
]
operations = [
migrations.AlterField(
model_name='posttranslation',
name='abstract',
field=djangocms_text_ckeditor.fields.HTMLField(verbose_name='Abstract', blank=True, default=''),
preserve_default=True,
),
]

View file

@ -106,7 +106,7 @@ class Post(ModelMeta, TranslatableModel):
translations = TranslatedFields( translations = TranslatedFields(
title=models.CharField(_('Title'), max_length=255), title=models.CharField(_('Title'), max_length=255),
slug=models.SlugField(_('slug'), blank=True, db_index=True), slug=models.SlugField(_('slug'), blank=True, db_index=True),
abstract=HTMLField(_('Abstract')), abstract=HTMLField(_('Abstract'), blank=True, default=''),
meta_description=models.TextField(verbose_name=_(u'Post meta description'), meta_description=models.TextField(verbose_name=_(u'Post meta description'),
blank=True, default=''), blank=True, default=''),
meta_keywords=models.TextField(verbose_name=_(u'Post meta keywords'), meta_keywords=models.TextField(verbose_name=_(u'Post meta keywords'),

View file

@ -47,6 +47,7 @@ def get_setting(name):
'BLOG_GPLUS_AUTHOR': getattr(settings, 'BLOG_GPLUS_AUTHOR', 'BLOG_GPLUS_AUTHOR': getattr(settings, 'BLOG_GPLUS_AUTHOR',
'get_author_gplus'), 'get_author_gplus'),
'BLOG_ENABLE_COMMENTS': getattr(settings, 'BLOG_ENABLE_COMMENTS', True), 'BLOG_ENABLE_COMMENTS': getattr(settings, 'BLOG_ENABLE_COMMENTS', True),
'BLOG_USE_ABSTRACT': getattr(settings, 'BLOG_USE_ABSTRACT', True),
'BLOG_USE_PLACEHOLDER': getattr(settings, 'BLOG_USE_PLACEHOLDER', True), 'BLOG_USE_PLACEHOLDER': getattr(settings, 'BLOG_USE_PLACEHOLDER', True),
'BLOG_MULTISITE': getattr(settings, 'BLOG_MULTISITE', True), 'BLOG_MULTISITE': getattr(settings, 'BLOG_MULTISITE', True),
'BLOG_AUTHOR_DEFAULT': getattr(settings, 'BLOG_AUTHOR_DEFAULT', True), 'BLOG_AUTHOR_DEFAULT': getattr(settings, 'BLOG_AUTHOR_DEFAULT', True),

View file

@ -0,0 +1,196 @@
# -*- coding: utf-8 -*-
from south.db import db
from south.v2 import SchemaMigration
class Migration(SchemaMigration):
def forwards(self, orm):
db.alter_column(u'djangocms_blog_post_translation', 'abstract', self.gf('djangocms_text_ckeditor.fields.HTMLField')(blank=True, default=''))
def backwards(self, orm):
db.alter_column(u'djangocms_blog_post_translation', 'abstract', self.gf('djangocms_text_ckeditor.fields.HTMLField')())
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '80', 'unique': 'True'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'to': "orm['auth.Permission']", 'symmetrical': 'False'})
},
'auth.permission': {
'Meta': {'object_name': 'Permission', 'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)"},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'blank': 'True', 'max_length': '75'}),
'first_name': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '30'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'symmetrical': 'False', 'to': "orm['auth.Group']", 'related_name': "'user_set'"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '30'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'symmetrical': 'False', 'to': "orm['auth.Permission']", 'related_name': "'user_set'"}),
'username': ('django.db.models.fields.CharField', [], {'max_length': '30', 'unique': 'True'})
},
'cms.cmsplugin': {
'Meta': {'object_name': 'CMSPlugin'},
'changed_date': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'depth': ('django.db.models.fields.PositiveIntegerField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15'}),
'numchild': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'null': 'True', 'to': "orm['cms.CMSPlugin']"}),
'path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'unique': 'True'}),
'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'null': 'True', 'to': "orm['cms.Placeholder']"}),
'plugin_type': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '50'}),
'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'blank': 'True', 'null': 'True'})
},
'cms.placeholder': {
'Meta': {'object_name': 'Placeholder'},
'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'slot': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '255'})
},
'cmsplugin_filer_image.thumbnailoption': {
'Meta': {'object_name': 'ThumbnailOption', 'ordering': "('width', 'height')"},
'crop': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'height': ('django.db.models.fields.IntegerField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'upscale': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'width': ('django.db.models.fields.IntegerField', [], {})
},
'contenttypes.contenttype': {
'Meta': {'object_name': 'ContentType', 'db_table': "'django_content_type'", 'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'djangocms_blog.authorentriesplugin': {
'Meta': {'object_name': 'AuthorEntriesPlugin'},
'authors': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False'}),
'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'primary_key': 'True', 'unique': 'True', 'to': "orm['cms.CMSPlugin']"}),
'latest_posts': ('django.db.models.fields.IntegerField', [], {'default': '5'})
},
'djangocms_blog.blogcategory': {
'Meta': {'object_name': 'BlogCategory'},
'date_created': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'}),
'date_modified': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'null': 'True', 'to': "orm['djangocms_blog.BlogCategory']"})
},
'djangocms_blog.blogcategorytranslation': {
'Meta': {'object_name': 'BlogCategoryTranslation', 'db_table': "'djangocms_blog_blogcategory_translation'", 'unique_together': "[('language_code', 'slug'), ('language_code', 'master')]"},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language_code': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15'}),
'master': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['djangocms_blog.BlogCategory']", 'null': 'True', 'related_name': "'translations'"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'slug': ('django.db.models.fields.SlugField', [], {'blank': 'True', 'max_length': '50'})
},
'djangocms_blog.latestpostsplugin': {
'Meta': {'object_name': 'LatestPostsPlugin'},
'categories': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'to': "orm['djangocms_blog.BlogCategory']", 'symmetrical': 'False'}),
'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'primary_key': 'True', 'unique': 'True', 'to': "orm['cms.CMSPlugin']"}),
'latest_posts': ('django.db.models.fields.IntegerField', [], {'default': '5'}),
'tags': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'to': "orm['taggit.Tag']", 'symmetrical': 'False'})
},
'djangocms_blog.post': {
'Meta': {'object_name': 'Post', 'ordering': "('-date_published', '-date_created')"},
'author': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'to': "orm['auth.User']", 'null': 'True', 'related_name': "'djangocms_blog_post_author'"}),
'categories': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['djangocms_blog.BlogCategory']", 'related_name': "'blog_posts'"}),
'content': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True', 'related_name': "'post_content'"}),
'date_created': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'}),
'date_modified': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'date_published': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'date_published_end': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'null': 'True'}),
'enable_comments': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'main_image': ('django.db.models.fields.related.ForeignKey', [], {'on_delete': 'models.SET_NULL', 'blank': 'True', 'to': "orm['filer.Image']", 'null': 'True', 'related_name': "'djangocms_blog_post_image'"}),
'main_image_full': ('django.db.models.fields.related.ForeignKey', [], {'on_delete': 'models.SET_NULL', 'blank': 'True', 'to': "orm['cmsplugin_filer_image.ThumbnailOption']", 'null': 'True', 'related_name': "'djangocms_blog_post_full'"}),
'main_image_thumbnail': ('django.db.models.fields.related.ForeignKey', [], {'on_delete': 'models.SET_NULL', 'blank': 'True', 'to': "orm['cmsplugin_filer_image.ThumbnailOption']", 'null': 'True', 'related_name': "'djangocms_blog_post_thumbnail'"}),
'publish': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'sites': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'to': "orm['sites.Site']", 'null': 'True', 'symmetrical': 'False'})
},
'djangocms_blog.posttranslation': {
'Meta': {'object_name': 'PostTranslation', 'db_table': "'djangocms_blog_post_translation'", 'unique_together': "[('language_code', 'slug'), ('language_code', 'master')]"},
'abstract': ('djangocms_text_ckeditor.fields.HTMLField', [], {'blank': 'True', 'default': "''"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language_code': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15'}),
'master': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['djangocms_blog.Post']", 'null': 'True', 'related_name': "'translations'"}),
'meta_description': ('django.db.models.fields.TextField', [], {'blank': 'True', 'default': "''"}),
'meta_keywords': ('django.db.models.fields.TextField', [], {'blank': 'True', 'default': "''"}),
'meta_title': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '255', 'default': "''"}),
'post_text': ('djangocms_text_ckeditor.fields.HTMLField', [], {'blank': 'True', 'default': "''"}),
'slug': ('django.db.models.fields.SlugField', [], {'blank': 'True', 'max_length': '50'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
},
'filer.file': {
'Meta': {'object_name': 'File'},
'_file_size': ('django.db.models.fields.IntegerField', [], {'blank': 'True', 'null': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'file': ('django.db.models.fields.files.FileField', [], {'blank': 'True', 'null': 'True', 'max_length': '255'}),
'folder': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'to': "orm['filer.Folder']", 'null': 'True', 'related_name': "'all_files'"}),
'has_all_mandatory_data': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_public': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'modified_at': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '255', 'default': "''"}),
'original_filename': ('django.db.models.fields.CharField', [], {'blank': 'True', 'null': 'True', 'max_length': '255'}),
'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'to': "orm['auth.User']", 'null': 'True', 'related_name': "'owned_files'"}),
'polymorphic_ctype': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'related_name': "'polymorphic_filer.file_set+'"}),
'sha1': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '40', 'default': "''"}),
'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'})
},
'filer.folder': {
'Meta': {'object_name': 'Folder', 'ordering': "('name',)", 'unique_together': "(('parent', 'name'),)"},
'created_at': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'modified_at': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'to': "orm['auth.User']", 'null': 'True', 'related_name': "'filer_owned_folders'"}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'to': "orm['filer.Folder']", 'null': 'True', 'related_name': "'children'"}),
'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'})
},
'filer.image': {
'Meta': {'object_name': 'Image'},
'_height': ('django.db.models.fields.IntegerField', [], {'blank': 'True', 'null': 'True'}),
'_width': ('django.db.models.fields.IntegerField', [], {'blank': 'True', 'null': 'True'}),
'author': ('django.db.models.fields.CharField', [], {'blank': 'True', 'null': 'True', 'max_length': '255'}),
'date_taken': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'null': 'True'}),
'default_alt_text': ('django.db.models.fields.CharField', [], {'blank': 'True', 'null': 'True', 'max_length': '255'}),
'default_caption': ('django.db.models.fields.CharField', [], {'blank': 'True', 'null': 'True', 'max_length': '255'}),
'file_ptr': ('django.db.models.fields.related.OneToOneField', [], {'primary_key': 'True', 'unique': 'True', 'to': "orm['filer.File']"}),
'must_always_publish_author_credit': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'must_always_publish_copyright': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'subject_location': ('django.db.models.fields.CharField', [], {'blank': 'True', 'null': 'True', 'default': 'None', 'max_length': '64'})
},
'sites.site': {
'Meta': {'object_name': 'Site', 'db_table': "'django_site'", 'ordering': "('domain',)"},
'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'taggit.tag': {
'Meta': {'object_name': 'Tag'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'unique': 'True'}),
'slug': ('django.db.models.fields.SlugField', [], {'max_length': '100', 'unique': 'True'})
}
}
complete_apps = ['djangocms_blog']

View file

@ -35,6 +35,13 @@ class AdminTest(BaseTest):
fsets = post_admin.get_fieldsets(request) fsets = post_admin.get_fieldsets(request)
self.assertTrue('post_text' in fsets[0][1]['fields']) self.assertTrue('post_text' in fsets[0][1]['fields'])
with self.settings(BLOG_USE_ABSTRACT=True):
fsets = post_admin.get_fieldsets(request)
self.assertTrue('abstract' in fsets[0][1]['fields'])
with self.settings(BLOG_USE_ABSTRACT=False):
fsets = post_admin.get_fieldsets(request)
self.assertFalse('abstract' in fsets[0][1]['fields'])
with self.settings(BLOG_MULTISITE=True): with self.settings(BLOG_MULTISITE=True):
fsets = post_admin.get_fieldsets(request) fsets = post_admin.get_fieldsets(request)
self.assertTrue('sites' in fsets[1][1]['fields'][0]) self.assertTrue('sites' in fsets[1][1]['fields'][0])