Add support for social tags via django-meta-mixin

This commit is contained in:
Iacopo Spalletti 2014-04-19 19:18:11 +02:00
parent 0a9ae13c69
commit a2bd384d2b
6 changed files with 96 additions and 24 deletions

View file

@ -1 +1 @@
__version__ = '0.2b1.dev1'
__version__ = '0.2b2'

View file

@ -27,23 +27,29 @@ class PostAdmin(EnhancedModelAdminMixin, FrontendEditableAdmin,
raw_id_fields = ['author']
frontend_editable_fields = ("title", "abstract")
enhance_exclude = ('main_image', 'tags')
_fieldsets = [
(None, {
'fields': [('title', 'slug', 'publish'),
('categories', 'tags'),
('date_published', 'date_published_end')]
'fields': [('title', 'slug', 'publish'), 'abstract']
}),
(None, {
'fields': [('main_image', 'main_image_thumbnail', 'main_image_full'),
'abstract', ('meta_description', 'meta_keywords')]
('Info', {
'fields': (['categories', 'tags'],
('date_published', 'date_published_end')),
'classes': ('collapse',)
}),
('Immagine', {
'fields': (('main_image', 'main_image_thumbnail', 'main_image_full'),),
'classes': ('collapse',)
}),
('SEO', {
'fields': [('meta_description', 'meta_keywords')],
'classes': ('collapse',)
}),
]
def get_fieldsets(self, request, obj=None):
if request.user.is_superuser:
fsets = deepcopy(self._fieldsets)
fsets[0][1]['fields'].append('author')
fsets[1][1]['fields'][0].append('author')
return fsets
else:
return self._fieldsets

View file

@ -15,6 +15,7 @@ from parler.managers import TranslationManager
from taggit_autosuggest.managers import TaggableManager
from . import settings
from meta_mixin.models import ModelMeta
from .managers import GenericDateTaggedManager
BLOG_CURRENT_POST_IDENTIFIER = 'djangocms_post_current'
@ -57,7 +58,7 @@ class BlogCategory(TranslatableModel):
self.save_translations()
class Post(TranslatableModel):
class Post(ModelMeta, TranslatableModel):
"""
Blog post
"""
@ -81,13 +82,13 @@ class Post(TranslatableModel):
blank=True, null=True)
main_image_full = models.ForeignKey(ThumbnailOption,
verbose_name=_('Main image full'),
related_name='blog_post_full',
related_name='djangocms_blog_post_full',
blank=True, null=True)
translations = TranslatedFields(
title=models.CharField(_('Title'), max_length=255),
slug=models.SlugField(_('slug'), blank=True, db_index=True),
abstract=HTMLField(_('Text')),
abstract=HTMLField(_('Abstract')),
meta_description=models.TextField(verbose_name=_(u'Post meta description'),
blank=True, default=''),
meta_keywords=models.TextField(verbose_name=_(u'Post meta keywords'),
@ -99,6 +100,52 @@ class Post(TranslatableModel):
objects = GenericDateTaggedManager()
tags = TaggableManager(blank=True, related_name='djangocms_blog_tags')
_metadata = {
'title': 'title',
'description': 'get_description',
'og_description': 'get_description',
'twitter_description': 'get_description',
'gplus_description': 'get_description',
'keywords': 'get_keywords',
'locale': None,
'image': 'get_image_url',
'object_type': settings.BLOG_TYPE,
'og_type': settings.BLOG_FB_TYPE,
'og_app_id': settings.BLOG_FB_APPID,
'og_profile_id': settings.BLOG_FB_PROFILE_ID,
'og_publisher': settings.BLOG_FB_PUBLISHER,
'og_author_url': settings.BLOG_FB_AUTHOR_URL,
'twitter_type': settings.BLOG_TWITTER_TYPE,
'twitter_site': settings.BLOG_TWITTER_SITE,
'twitter_author': settings.BLOG_TWITTER_AUTHOR,
'gplus_type': settings.BLOG_GPLUS_TYPE,
'gplus_author': settings.BLOG_GPLUS_AUTHOR,
'published_time': 'date_published',
'modified_time': 'date_modified',
'expiration_time': 'date_published_end',
'tag': 'get_tags',
'url': 'get_absolute_url',
}
def get_keywords(self):
return self.safe_translation_getter('meta_keywords', language_code=get_language()).strip().split(",")
def get_description(self):
description = self.safe_translation_getter('meta_description', language_code=get_language())
if not description:
description = self.safe_translation_getter('abstract', language_code=get_language())
return description.strip()
def get_image_url(self):
return self.main_image
def get_tags(self):
taglist = [tag.name for tag in self.tags.all()]
return ",".join(taglist)
def get_author(self):
return self.author
class Meta:
verbose_name = _('blog article')
verbose_name_plural = _('blog articles')
@ -129,6 +176,12 @@ class Post(TranslatableModel):
else:
return settings.BLOG_IMAGE_THUMBNAIL_SIZE
def full_image_options(self):
if self.main_image_fulll_id:
return self.main_image_full.as_dict
else:
return settings.BLOG_IMAGE_FULL_SIZE
def get_full_url(self):
s = Site.objects.get_current()
if s.domain.find('http') > -1:
@ -136,12 +189,6 @@ class Post(TranslatableModel):
else:
return "http://%s%s" % (s.domain, self.get_absolute_url())
def full_image_options(self):
if self.main_image_fulll_id:
return self.main_image_full.as_dict
else:
return settings.BLOG_IMAGE_FULL_SIZE
class LatestPostsPlugin(CMSPlugin):

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from django.conf import settings
from meta_mixin import settings as meta_settings
BLOG_IMAGE_THUMBNAIL_SIZE = getattr(settings, 'BLOG_IMAGE_THUMBNAIL_SIZE', {
'size': '120x120',
@ -19,3 +19,15 @@ 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_TYPE = getattr(settings, 'BLOG_TYPE', 'Article')
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_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', 'Article')
BLOG_GPLUS_AUTHOR = getattr(settings, 'BLOG_GPLUS_AUTHOR', 'get_author_gplus')

View file

@ -1,7 +1,13 @@
{% extends "base.html" %}
{% block meta %}
{% if meta %}
{% include "meta_mixin/meta.html" %}
{% endif %}
{% endblock meta %}
{% block content %}
<div class="app app-blog span8">
{% block content_blog %}{% endblock %}
</div>
{% endblock %}
{% endblock content %}

View file

@ -5,7 +5,6 @@ from django.contrib.auth.models import User
from django.core.urlresolvers import resolve
from django.http import Http404
from django.views.generic import ListView, DetailView
from parler.utils import get_active_language_choices
from parler.views import ViewUrlMixin
@ -58,9 +57,11 @@ class PostDetailView(BaseBlogView, DetailView):
def get_context_data(self, **kwargs):
context = super(PostDetailView, self).get_context_data(**kwargs)
context['meta'] = self.get_object().as_meta()
setattr(self.request, BLOG_CURRENT_POST_IDENTIFIER, self.get_object())
return context
class PostArchiveView(BaseBlogView, ListView):
model = Post
context_object_name = 'post_list'