From 2490447f440a8a5200ad4f38b6b1c8fea5d22efe Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sun, 18 Oct 2015 12:46:50 +0200 Subject: [PATCH] Use custom template to render meta tags properly --- cms_helper.py | 4 ++++ djangocms_blog/models.py | 16 ++++++++++++- tests/__init__.py | 6 ++--- tests/test_setup.py | 2 +- tests/test_utils/models.py | 1 + tests/test_utils/templates/blog.html | 36 ++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 tests/test_utils/models.py create mode 100644 tests/test_utils/templates/blog.html diff --git a/cms_helper.py b/cms_helper.py index 3b7af0d..667833d 100755 --- a/cms_helper.py +++ b/cms_helper.py @@ -19,6 +19,7 @@ HELPER_SETTINGS = dict( 'taggit', 'taggit_autosuggest', 'aldryn_apphooks_config', + 'tests.test_utils', ], LANGUAGE_CODE='en', LANGUAGES=( @@ -72,6 +73,9 @@ HELPER_SETTINGS = dict( MIGRATION_MODULES={ 'cmsplugin_filer_image': 'cmsplugin_filer_image.migrations_django', }, + CMS_TEMPLATES=( + ('blog.html', 'Blog template'), + ), META_SITE_PROTOCOL='http', META_SITE_DOMAIN='example.com', META_USE_OG_PROPERTIES=True, diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 418e39b..e41a0c4 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -203,7 +203,21 @@ class Post(ModelMeta, TranslatableModel): Retrieves django-meta attributes from apphook config instance :param param: django-meta attribute passed as key """ - return getattr(self.app_config, param) + attr = None + value = getattr(self.app_config, param) + if value: + attr = getattr(self, value, None) + if attr is not None: + if callable(attr): + try: + data = attr(param) + except TypeError: + data = attr() + else: + data = attr + else: + data = value + return data def save_translation(self, translation, *args, **kwargs): if not translation.slug and translation.title: diff --git a/tests/__init__.py b/tests/__init__.py index 6fad4a6..dcfbd5f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -31,14 +31,14 @@ class BaseTest(BaseTestCase): thumb_2 = None _pages_data = ( - {'en': {'title': 'page one', 'template': 'page.html', 'publish': True}, + {'en': {'title': 'page one', 'template': 'blog.html', 'publish': True}, 'fr': {'title': 'page un', 'publish': True}, 'it': {'title': 'pagina uno', 'publish': True}}, - {'en': {'title': 'page two', 'template': 'page.html', 'publish': True, + {'en': {'title': 'page two', 'template': 'blog.html', 'publish': True, 'apphook': 'BlogApp', 'apphook_namespace': 'sample_app'}, 'fr': {'title': 'page deux', 'publish': True}, 'it': {'title': 'pagina due', 'publish': True}}, - {'en': {'title': 'page three', 'template': 'page.html', 'publish': True, + {'en': {'title': 'page three', 'template': 'blog.html', 'publish': True, 'apphook': 'BlogApp', 'apphook_namespace': 'sample_app2'}, 'fr': {'title': 'page trois', 'publish': True}, 'it': {'title': 'pagina tre', 'publish': True}}, diff --git a/tests/test_setup.py b/tests/test_setup.py index fa8f1e7..7741307 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -54,7 +54,7 @@ class SetupTest(BaseTest): if not home: home = create_page( 'a new home', language=lang, - template='page.html', in_navigation=True, published=True + template='blog.html', in_navigation=True, published=True ) else: create_title( diff --git a/tests/test_utils/models.py b/tests/test_utils/models.py new file mode 100644 index 0000000..40a96af --- /dev/null +++ b/tests/test_utils/models.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/tests/test_utils/templates/blog.html b/tests/test_utils/templates/blog.html new file mode 100644 index 0000000..c1703d6 --- /dev/null +++ b/tests/test_utils/templates/blog.html @@ -0,0 +1,36 @@ +{% load cms_tags static menu_tags sekizai_tags %} + + + + {% block title %}{% page_attribute 'title' %}{% endblock title %} + {% render_block "css" %} + {% include "meta_mixin/meta.html" %} + + + +Post +{% cms_toolbar %} +
+ + {% block content %} + {% placeholder "content" %} + {% endblock content %} +
+{% render_block "js" %} +{% with_data "js-script" as jsset %} + {% for js in jsset %}{% endfor %} +{% end_with_data %} +{% render_block "js_end" %} + +