Skip to content

Commit

Permalink
Add support to django-meta 2.0 replacing g+ attributes with schema.org (
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Nov 14, 2020
1 parent 5d01a86 commit c8efbdc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 26 deletions.
1 change: 1 addition & 0 deletions changes/637.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace G+ metadata with Schema.org
2 changes: 1 addition & 1 deletion djangocms_blog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def get_fieldsets(self, request, obj=None):
},
),
(
"Google+",
"Schema.org",
{
"fields": (
"config.gplus_type",
Expand Down
16 changes: 12 additions & 4 deletions djangocms_blog/cms_appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class Meta:
def get_app_title(self):
return getattr(self, "app_title", _("untitled"))

@property
def schemaorg_type(self):
"""Compatibility shim to fetch data from legacy gplus_type field."""
return self.gplus_type


class BlogConfigForm(AppDataForm):
"""
Expand Down Expand Up @@ -176,13 +181,16 @@ class BlogConfigForm(AppDataForm):
twitter_author = forms.CharField(
max_length=200, label=_("Twitter author handle"), required=False, initial=get_setting("TWITTER_AUTHOR")
)
#: Schema.org object type (default: :ref:`GPLUS_TYPE <GPLUS_TYPE>`)
#: Schema.org object type (default: :ref:`SCHEMAORG_TYPE <SCHEMAORG_TYPE>`)
gplus_type = forms.ChoiceField(
label=_("Google+ type"), required=False, choices=get_setting("GPLUS_TYPES"), initial=get_setting("GPLUS_TYPE")
label=_("Schema.org type"),
required=False,
choices=get_setting("SCHEMAORG_TYPES"),
initial=get_setting("SCHEMAORG_TYPE"),
)
#: Google+ author name abstract field (default: :ref:`GPLUS_AUTHOR <GPLUS_AUTHOR>`)
#: Schema.org author name abstract field (default: :ref:`SCHEMAORG_AUTHOR <SCHEMAORG_AUTHOR>`)
gplus_author = forms.CharField(
max_length=200, label=_("Google+ author name"), required=False, initial=get_setting("GPLUS_AUTHOR")
max_length=200, label=_("Schema.org author name"), required=False, initial=get_setting("SCHEMAORG_AUTHOR")
)
#: Send notifications on post update. Require channels integration
send_knock_create = forms.BooleanField(
Expand Down
11 changes: 5 additions & 6 deletions djangocms_blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def get_meta_attribute(self, param):
Retrieves django-meta attributes from apphook config instance
:param param: django-meta attribute passed as key
"""
print(param, getattr(self.app_config, param))
return self._get_meta_value(param, getattr(self.app_config, param)) or ""

def get_locale(self):
Expand Down Expand Up @@ -111,7 +112,8 @@ class BlogCategory(BlogMetaMixin, TranslatableModel):
"description": "get_description",
"og_description": "get_description",
"twitter_description": "get_description",
"gplus_description": "get_description",
"schemaorg_description": "get_description",
"schemaorg_type": "get_meta_attribute",
"locale": "get_locale",
"object_type": "get_meta_attribute",
"og_type": "get_meta_attribute",
Expand All @@ -123,8 +125,6 @@ class BlogCategory(BlogMetaMixin, TranslatableModel):
"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",
"url": "get_absolute_url",
}

Expand Down Expand Up @@ -284,7 +284,7 @@ class Post(KnockerModel, BlogMetaMixin, TranslatableModel):
"keywords": "get_keywords",
"og_description": "get_description",
"twitter_description": "get_description",
"gplus_description": "get_description",
"schemaorg_description": "get_description",
"locale": "get_locale",
"image": "get_image_full_url",
"image_width": "get_image_width",
Expand All @@ -299,8 +299,7 @@ class Post(KnockerModel, BlogMetaMixin, TranslatableModel):
"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",
"schemaorg_type": "get_meta_attribute",
"published_time": "date_published",
"modified_time": "date_modified",
"expiration_time": "date_published_end",
Expand Down
14 changes: 7 additions & 7 deletions djangocms_blog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,25 +250,25 @@
Twitter account of the post author.
"""

BLOG_GPLUS_TYPE = "Blog"
BLOG_SCHEMAORG_TYPE = "Blog"
"""
.. _GPLUS_TYPE:
.. _SCHEMAORG_TYPE:
Schema.org type for the post object.
"""

BLOG_GPLUS_TYPES = meta_settings.GPLUS_TYPES
BLOG_SCHEMAORG_TYPES = meta_settings.SCHEMAORG_TYPES
"""
.. _GPLUS_TYPES:
.. _SCHEMAORG_TYPES:
Choices of available Schema.org types.
Default from ``GPLUS_TYPES`` defined in `django-meta settings`_.
Default from ``SCHEMAORG_TYPES`` defined in `django-meta settings`_.
"""

BLOG_GPLUS_AUTHOR = "get_author_gplus"
BLOG_SCHEMAORG_AUTHOR = "get_author_schemaorg"
"""
.. _GPLUS_AUTHOR:
.. _SCHEMAORG_AUTHOR:
Google+ account of the post author (deprecated).
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ install_requires =
django-taggit-autosuggest
djangocms-text-ckeditor>=3.9
easy-thumbnails>=2.4.1
django-meta>=1.4
django-meta>=2.0
aldryn-apphooks-config>=0.5
djangocms-apphook-setup
django-sortedm2m
Expand Down
11 changes: 4 additions & 7 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,6 @@ def test_slug(self):
def test_model_attributes(self):
self.get_pages()

self.app_config_1.app_data.config.gplus_author = "RandomJoe"
self.app_config_1.save()

featured_date = now() + timedelta(days=40)

post = self._get_post(self._post_data[0]["en"])
Expand All @@ -870,8 +867,9 @@ def test_model_attributes(self):
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.schemaorg_type, "Blog")
self.assertEqual(meta_en.schemaorg_title, post.title)
self.assertEqual(meta_en.schemaorg_description, post.meta_description)
self.assertEqual(meta_en.og_type, "Article")
self.assertEqual(meta_en.image_width, post.main_image.width)
self.assertEqual(meta_en.image_height, post.main_image.height)
Expand All @@ -892,8 +890,7 @@ def test_model_attributes(self):
self.assertEqual(meta_cat.twitter_site, "")
self.assertEqual(meta_cat.twitter_author, "")
self.assertEqual(meta_cat.twitter_type, "summary")
self.assertEqual(meta_cat.gplus_author, "RandomJoe")
self.assertEqual(meta_cat.gplus_type, "Blog")
self.assertEqual(meta_cat.schemaorg_type, "Blog")
self.assertEqual(meta_cat.og_type, "Article")
self.assertEqual(meta_cat.facebook_app_id, None)
self.assertTrue(meta_cat.url.endswith(category.get_absolute_url()))
Expand Down

0 comments on commit c8efbdc

Please sign in to comment.