Clarify meta tags fields in BlogConfig

This commit is contained in:
Iacopo Spalletti 2015-10-18 13:01:00 +02:00
parent 2490447f44
commit 0e9a80cb42
4 changed files with 25 additions and 2 deletions

View file

@ -9,6 +9,7 @@ from django import forms
from django.conf import settings from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.utils.translation import ugettext_lazy as _
from parler.admin import TranslatableAdmin from parler.admin import TranslatableAdmin
from .cms_appconfig import BlogConfig from .cms_appconfig import BlogConfig
@ -157,16 +158,25 @@ class BlogConfigAdmin(BaseAppHookConfig, TranslatableAdmin):
'fields': ( 'fields': (
'config.og_type', 'config.og_app_id', 'config.og_profile_id', 'config.og_type', 'config.og_app_id', 'config.og_profile_id',
'config.og_publisher', 'config.og_author_url', 'config.og_author', 'config.og_publisher', 'config.og_author_url', 'config.og_author',
),
'description': _(
'You can provide plain strings, Post model attribute or method names'
) )
}), }),
('Twitter', { ('Twitter', {
'fields': ( 'fields': (
'config.twitter_type', 'config.twitter_site', 'config.twitter_author', 'config.twitter_type', 'config.twitter_site', 'config.twitter_author',
),
'description': _(
'You can provide plain strings, Post model attribute or method names'
) )
}), }),
('Google+', { ('Google+', {
'fields': ( 'fields': (
'config.gplus_type', 'config.gplus_author', 'config.gplus_type', 'config.gplus_author',
),
'description': _(
'You can provide plain strings, Post model attribute or method names'
) )
}), }),
] ]

View file

@ -150,7 +150,7 @@ class Post(ModelMeta, TranslatableModel):
'og_description': 'get_description', 'og_description': 'get_description',
'twitter_description': 'get_description', 'twitter_description': 'get_description',
'gplus_description': 'get_description', 'gplus_description': 'get_description',
'locale': None, 'locale': 'get_locale',
'image': 'get_image_full_url', 'image': 'get_image_full_url',
'object_type': 'get_meta_attribute', 'object_type': 'get_meta_attribute',
'og_type': 'get_meta_attribute', 'og_type': 'get_meta_attribute',
@ -233,6 +233,9 @@ class Post(ModelMeta, TranslatableModel):
def get_keywords(self): def get_keywords(self):
return self.safe_translation_getter('meta_keywords').strip().split(',') return self.safe_translation_getter('meta_keywords').strip().split(',')
def get_locale(self):
return self.get_current_language()
def get_description(self): def get_description(self):
description = self.safe_translation_getter('meta_description', any_language=True) description = self.safe_translation_getter('meta_description', any_language=True)
if not description: if not description:

View file

@ -213,6 +213,9 @@ class ModelsTest(BaseTest):
def test_model_attributes(self): def test_model_attributes(self):
self.get_pages() self.get_pages()
self.app_config_1.app_data.config.gplus_author = 'RandomJoe'
self.app_config_1.save()
post = self._get_post(self._post_data[0]['en']) post = self._get_post(self._post_data[0]['en'])
post = self._get_post(self._post_data[0]['it'], post, 'it') post = self._get_post(self._post_data[0]['it'], post, 'it')
post.main_image = self.create_filer_image_object() post.main_image = self.create_filer_image_object()
@ -225,6 +228,14 @@ class ModelsTest(BaseTest):
self.assertEqual(meta_en.description, post.meta_description) self.assertEqual(meta_en.description, post.meta_description)
self.assertEqual(meta_en.keywords, post.meta_keywords.split(',')) self.assertEqual(meta_en.keywords, post.meta_keywords.split(','))
self.assertEqual(meta_en.published_time, post.date_published) self.assertEqual(meta_en.published_time, post.date_published)
self.assertEqual(meta_en.locale, 'en')
self.assertEqual(meta_en.twitter_site, '')
self.assertEqual(meta_en.twitter_author, '')
self.assertEqual(meta_en.twitter_type, 'summary')
self.assertEqual(meta_en.gplus_author, 'RandomJoe')
self.assertEqual(meta_en.gplus_type, 'Blog')
self.assertEqual(meta_en.og_type, 'Article')
self.assertEqual(meta_en.facebook_app_id, None)
post.set_current_language('it') post.set_current_language('it')
meta_it = post.as_meta() meta_it = post.as_meta()
self.assertEqual(meta_it.title, post.title) self.assertEqual(meta_it.title, post.title)

View file

@ -17,7 +17,6 @@
</style> </style>
</head> </head>
<body> <body>
Post
{% cms_toolbar %} {% cms_toolbar %}
<div style="width: 940px; margin:0 auto"> <div style="width: 940px; margin:0 auto">
<ul class="nav"> <ul class="nav">