Skip to content

Commit

Permalink
Merge 913c9b6 into 3dce2ff
Browse files Browse the repository at this point in the history
  • Loading branch information
protoroto authored Aug 9, 2023
2 parents 3dce2ff + 913c9b6 commit 6c78c5f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions changes/127.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix schemaorg_description not being in Meta class
6 changes: 6 additions & 0 deletions meta/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, **kwargs):
self.og_title = kwargs.get("og_title")
self.twitter_title = kwargs.get("twitter_title")
self.schemaorg_title = kwargs.get("schemaorg_title")
self.schemaorg_description = kwargs.get("schemaorg_description")
self.description = kwargs.get("description")
self.extra_props = kwargs.get("extra_props")
self.extra_custom_props = kwargs.get("extra_custom_props")
Expand Down Expand Up @@ -152,6 +153,7 @@ class MetadataMixin:
og_title = None
twitter_title = None
schemaorg_title = None
schemaorg_description = None
description = None
extra_props = None
extra_custom_props = None
Expand Down Expand Up @@ -199,6 +201,9 @@ def get_meta_twitter_title(self, context=None):
def get_meta_schemaorg_title(self, context=None):
return self.schemaorg_title

def get_meta_schemaorg_description(self, context=None):
return self.schemaorg_description

def get_meta_description(self, context=None):
return self.description

Expand Down Expand Up @@ -274,6 +279,7 @@ def get_meta(self, context=None):
og_title=self.get_meta_og_title(context=context),
twitter_title=self.get_meta_twitter_title(context=context),
schemaorg_title=self.get_meta_schemaorg_title(context=context),
schemaorg_description=self.get_meta_schemaorg_description(context=context),
description=self.get_meta_description(context=context),
extra_props=self.get_meta_extra_props(context=context),
extra_custom_props=self.get_meta_extra_custom_props(context=context),
Expand Down
4 changes: 4 additions & 0 deletions tests/example_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Migration(migrations.Migration):
("og_title", models.CharField(max_length=255, verbose_name="Opengraph title", blank=True)),
("twitter_title", models.CharField(max_length=255, verbose_name="Twitter title", blank=True)),
("schemaorg_title", models.CharField(max_length=255, verbose_name="Schema.org title", blank=True)),
(
"schemaorg_description",
models.CharField(max_length=255, verbose_name="Schema.org description", blank=True),
),
("slug", models.SlugField(verbose_name="slug")),
("abstract", models.TextField(verbose_name="Abstract")),
("meta_description", models.TextField(blank=True, default="", verbose_name="Post meta description")),
Expand Down
2 changes: 2 additions & 0 deletions tests/example_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Post(ModelMeta, models.Model):
og_title = models.CharField(_("Opengraph title"), blank=True, max_length=255)
twitter_title = models.CharField(_("Twitter title"), blank=True, max_length=255)
schemaorg_title = models.CharField(_("Schema.org title"), blank=True, max_length=255)
schemaorg_description = models.CharField(_("Schema.org description"), blank=True, max_length=255)
slug = models.SlugField(_("slug"))
abstract = models.TextField(_("Abstract"))
meta_description = models.TextField(verbose_name=_("Post meta description"), blank=True, default="")
Expand All @@ -41,6 +42,7 @@ class Post(ModelMeta, models.Model):
"og_title": "og_title",
"twitter_title": "twitter title",
"schemaorg_title": "schemaorg title",
"schemaorg_description": "schemaorg description",
"description": "get_description",
"og_description": "get_description",
"keywords": "get_keywords",
Expand Down
1 change: 1 addition & 0 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_defaults(self):
self.assertEqual(m.title, None)
self.assertEqual(m.og_title, None)
self.assertEqual(m.schemaorg_title, None)
self.assertEqual(m.schemaorg_description, None)
self.assertEqual(m.twitter_title, None)
self.assertEqual(m.description, None)
self.assertEqual(m.extra_props, None)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_metadata_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def test_get_meta_schemaorg_title(self):
m.schemaorg_title = "Foo"
self.assertEqual(m.get_meta_schemaorg_title(), "Foo")

def test_get_meta_schemaorg_description(self):
m = MetadataMixin()
self.assertEqual(m.get_meta_schemaorg_description(), None)

m.schemaorg_description = "Foo"
self.assertEqual(m.get_meta_schemaorg_description(), "Foo")

def test_get_meta_description(self):
m = MetadataMixin()
self.assertEqual(m.get_meta_description(), None)
Expand Down
13 changes: 9 additions & 4 deletions tests/test_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def setUpTestData(cls):
og_title="og title",
twitter_title="twitter title",
schemaorg_title="schemaorg title",
schemaorg_description="schemaorg description",
slug="title",
abstract="post abstract",
meta_description="post meta",
Expand Down Expand Up @@ -55,7 +56,7 @@ def test_as_meta(self):
"og_title": "og title",
"twitter_title": "twitter title",
"schemaorg_title": "schemaorg title",
"schemaorg_description": "post meta",
"schemaorg_description": "schemaorg description",
"expiration_time": self.post.date_published_end,
"og_description": "post meta",
"description": "post meta",
Expand Down Expand Up @@ -124,7 +125,7 @@ def test_as_meta_with_request(self):
"og_title": "og title",
"twitter_title": "twitter title",
"schemaorg_title": "schemaorg title",
"schemaorg_description": "post meta",
"schemaorg_description": "schemaorg description",
"expiration_time": self.post.date_published_end,
"og_description": "post meta",
"description": "post meta",
Expand Down Expand Up @@ -181,7 +182,9 @@ def test_templatetag(self):
self.assertContains(
response, '<meta name="twitter:image" content="http://example.com{}">'.format(self.image_url)
)
self.assertContains(response, '<meta itemprop="description" content="{}">'.format(self.post.meta_description))
self.assertContains(
response, '<meta itemprop="description" content="{}">'.format(self.post.schemaorg_description)
)
self.assertContains(
response, '<meta name="twitter:description" content="{}">'.format(self.post.meta_description)
)
Expand Down Expand Up @@ -269,7 +272,9 @@ def test_templatetag_no_og(self):
settings.USE_OG_PROPERTIES = False
response = self.client.get("/title/")
self.assertFalse(response.rendered_content.find("og:description") > -1)
self.assertContains(response, '<meta itemprop="description" content="{}">'.format(self.post.meta_description))
self.assertContains(
response, '<meta itemprop="description" content="{}">'.format(self.post.schemaorg_description)
)
self.assertContains(
response, '<meta name="twitter:description" content="{}">'.format(self.post.meta_description)
)
Expand Down

0 comments on commit 6c78c5f

Please sign in to comment.