Add meta attributes

This commit is contained in:
Iacopo Spalletti 2015-09-24 21:51:54 +02:00
parent 8d69fb107e
commit 63adbb1131
3 changed files with 100 additions and 54 deletions

View file

@ -25,25 +25,65 @@ class BlogConfig(TranslatableModel, AppHookConfig):
class BlogConfigForm(AppDataForm):
default_published = forms.BooleanField(label=_('Post published by default'), required=False,
initial=get_setting('DEFAULT_PUBLISHED'))
use_placeholder = forms.BooleanField(label=_('Use placeholder and plugins for article body'),
required=False,
initial=get_setting('USE_PLACEHOLDER'))
use_abstract = forms.BooleanField(label=_('Use abstract field'),
required=False,
initial=get_setting('USE_ABSTRACT'))
set_author = forms.BooleanField(label=_('Set author'),
required=False,
help_text=_('Set author by default'),
initial=get_setting('AUTHOR_DEFAULT'))
paginate_by = forms.IntegerField(label=_('Paginate size'),
required=False,
initial=get_setting('PAGINATION'),
help_text=_('When paginating list views, '
'how many articles per page?'))
template_prefix = forms.CharField(label=_('Template prefix'), required=False, initial='',
help_text=_('Alternative directory to load the blog '
'templates from')
)
default_published = forms.BooleanField(
label=_('Post published by default'), required=False,
initial=get_setting('DEFAULT_PUBLISHED')
)
use_placeholder = forms.BooleanField(
label=_('Use placeholder and plugins for article body'), required=False,
initial=get_setting('USE_PLACEHOLDER')
)
use_abstract = forms.BooleanField(
label=_('Use abstract field'), required=False,
initial=get_setting('USE_ABSTRACT')
)
set_author = forms.BooleanField(
label=_('Set author'), required=False, help_text=_('Set author by default'),
initial=get_setting('AUTHOR_DEFAULT')
)
paginate_by = forms.IntegerField(
label=_('Paginate size'), required=False, initial=get_setting('PAGINATION'),
help_text=_('When paginating list views, how many articles per page?')
)
template_prefix = forms.CharField(
label=_('Template prefix'), required=False, initial='',
help_text=_('Alternative directory to load the blog templates from')
)
object_type = forms.ChoiceField(
label=_('Object type'), required=False,
choices=get_setting('TYPES_GENERIC'), initial=get_setting('TYPE')
)
og_type = forms.ChoiceField(
label=_('Facebook type'), required=False,
choices=get_setting('TYPES_FACEBOOK'), initial=get_setting('TYPES_FACEBOOK')[0][0]
)
og_app_id = forms.CharField(
max_length=200, label=_('Facebook application ID'), required=False,
)
og_profile_id = forms.CharField(
max_length=200, label=_('Facebook profile ID'), required=False,
)
og_publisher = forms.CharField(
max_length=200, label=_('Facebook page URL'), required=False
)
og_author_url = forms.CharField(
max_length=200, label=_('Facebook author URL'), required=False
)
twitter_type = forms.ChoiceField(
label=_('Twitter type'), required=False,
choices=get_setting('TYPES_TWITTER'), initial=get_setting('TYPES_TWITTER')[0][0]
)
twitter_site = forms.CharField(
max_length=200, label=_('Twitter site handle'), required=False
)
twitter_author = forms.CharField(
max_length=200, label=_('Twitter author handle'), required=False
)
gplus_type = forms.CharField(
max_length=200, label=_('Google+ type'), required=False,
choices=get_setting('TYPES_GPLUS'), initial=get_setting('TYPES_GPLUS')[0][0]
)
gplus_author = forms.CharField(
max_length=200, label=_('Google+ author name'), required=False
)
setup_config(BlogConfigForm, BlogConfig)

View file

@ -144,20 +144,19 @@ class Post(ModelMeta, TranslatableModel):
'og_description': 'get_description',
'twitter_description': 'get_description',
'gplus_description': 'get_description',
'keywords': 'get_keywords',
'locale': None,
'image': 'get_image_full_url',
'object_type': get_setting('TYPE'),
'og_type': get_setting('FB_TYPE'),
'og_app_id': get_setting('FB_APPID'),
'og_profile_id': get_setting('FB_PROFILE_ID'),
'og_publisher': get_setting('FB_PUBLISHER'),
'og_author_url': get_setting('FB_AUTHOR_URL'),
'twitter_type': get_setting('TWITTER_TYPE'),
'twitter_site': get_setting('TWITTER_SITE'),
'twitter_author': get_setting('TWITTER_AUTHOR'),
'gplus_type': get_setting('GPLUS_TYPE'),
'gplus_author': get_setting('GPLUS_AUTHOR'),
'object_type': 'get_meta_attribute',
'og_type': 'get_meta_attribute',
'og_app_id': 'get_meta_attribute',
'og_profile_id': 'get_meta_attribute',
'og_publisher': 'get_meta_attribute',
'og_author_url': 'get_meta_attribute',
'twitter_type': 'get_meta_attribute',
'twitter_site': 'get_meta_attribute',
'twitter_author': 'get_meta_attribute',
'gplus_type': 'get_meta_attribute',
'gplus_author': 'get_meta_attribute',
'published_time': 'date_published',
'modified_time': 'date_modified',
'expiration_time': 'date_published_end',
@ -185,6 +184,13 @@ class Post(ModelMeta, TranslatableModel):
any_language=True)}
return reverse('%s:post-detail' % self.app_config.namespace, kwargs=kwargs)
def get_meta_attribute(self, param):
"""
Retrieves django-meta attributes from apphook config instance
:param param: django-meta attribute passed as key
"""
return getattr(self.app_config, param)
def save_translation(self, translation, *args, **kwargs):
if not translation.slug and translation.title:
translation.slug = slugify(translation.title)

View file

@ -6,6 +6,11 @@ def get_setting(name):
from django.conf import settings
from meta_mixin import settings as meta_settings
OBJECT_TYPES = {
'Article': _('Article'),
'Website': _('Website'),
}
default = {
'BLOG_IMAGE_THUMBNAIL_SIZE': getattr(settings, 'BLOG_IMAGE_THUMBNAIL_SIZE', {
'size': '120x120',
@ -23,30 +28,25 @@ def get_setting(name):
'BLOG_TAGCLOUD_MAX': getattr(settings, 'BLOG_TAGCLOUD_MAX', 10),
'BLOG_PAGINATION': getattr(settings, 'BLOG_PAGINATION', 10),
'BLOG_LATEST_POSTS': getattr(settings, 'BLOG_LATEST_POSTS', 5),
'BLOG_POSTS_LIST_TRUNCWORDS_COUNT': getattr(settings,
'BLOG_POSTS_LIST_TRUNCWORDS_COUNT',
100),
'BLOG_POSTS_LIST_TRUNCWORDS_COUNT': getattr(
settings, 'BLOG_POSTS_LIST_TRUNCWORDS_COUNT', 100
),
'BLOG_TYPE': getattr(settings, 'BLOG_TYPE', 'Article'),
'BLOG_TYPES': getattr(settings, 'BLOG_TYPES', ),
'BLOG_FB_TYPE': getattr(settings, 'BLOG_FB_TYPE', 'Article'),
'BLOG_FB_APPID': getattr(settings, 'BLOG_FB_APPID',
meta_settings.FB_APPID),
'BLOG_FB_PROFILE_ID': getattr(settings, 'BLOG_FB_PROFILE_ID',
meta_settings.FB_PROFILE_ID),
'BLOG_FB_PUBLISHER': getattr(settings, 'BLOG_FB_PUBLISHER',
meta_settings.FB_PUBLISHER),
'BLOG_FB_AUTHOR_URL': getattr(settings, 'BLOG_FB_AUTHOR_URL',
'get_author_url'),
'BLOG_FB_AUTHOR': getattr(settings, 'BLOG_FB_AUTHOR',
'get_author_name'),
'BLOG_FB_TYPES': getattr(settings, 'BLOG_FB_TYPES', OBJECT_TYPES.items()),
'BLOG_FB_APPID': getattr(settings, 'BLOG_FB_APPID', meta_settings.FB_APPID),
'BLOG_FB_PROFILE_ID': getattr(settings, 'BLOG_FB_PROFILE_ID', meta_settings.FB_PROFILE_ID),
'BLOG_FB_PUBLISHER': getattr(settings, 'BLOG_FB_PUBLISHER', meta_settings.FB_PUBLISHER),
'BLOG_FB_AUTHOR_URL': getattr(settings, 'BLOG_FB_AUTHOR_URL', 'get_author_url'),
'BLOG_FB_AUTHOR': getattr(settings, 'BLOG_FB_AUTHOR', 'get_author_name'),
'BLOG_TWITTER_TYPE': getattr(settings, 'BLOG_TWITTER_TYPE', 'Summary'),
'BLOG_TWITTER_SITE': getattr(settings, 'BLOG_TWITTER_SITE',
meta_settings.TWITTER_SITE),
'BLOG_TWITTER_AUTHOR': getattr(settings, 'BLOG_TWITTER_AUTHOR',
'get_author_twitter'),
'BLOG_GPLUS_TYPE': getattr(settings, 'BLOG_GPLUS_SCOPE_CATEGORY',
'Blog'),
'BLOG_GPLUS_AUTHOR': getattr(settings, 'BLOG_GPLUS_AUTHOR',
'get_author_gplus'),
'BLOG_TWITTER_TYPES': getattr(settings, 'BLOG_TWITTER_TYPES', OBJECT_TYPES.items()),
'BLOG_TWITTER_SITE': getattr(settings, 'BLOG_TWITTER_SITE', meta_settings.TWITTER_SITE),
'BLOG_TWITTER_AUTHOR': getattr(settings, 'BLOG_TWITTER_AUTHOR', 'get_author_twitter'),
'BLOG_GPLUS_TYPE': getattr(settings, 'BLOG_GPLUS_SCOPE_CATEGORY', 'Blog'),
'BLOG_GPLUS_TYPES': getattr(settings, 'BLOG_GPLUS_TYPES', OBJECT_TYPES.items()),
'BLOG_GPLUS_AUTHOR': getattr(settings, 'BLOG_GPLUS_AUTHOR', 'get_author_gplus'),
'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),