Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch property to cached_property #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions wagtailseo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class Meta:
),
)

@property
@cached_property
def at_twitter_site(self):
"""
The Twitter site handle, prepended with "@".
Expand Down Expand Up @@ -403,7 +403,7 @@ def get_preview_template(self, request, mode_name):

# -- SEO properties -------------------------------------------------------

@property
@cached_property
def seo_author(self) -> str:
"""
Gets the name of the author of this page.
Expand All @@ -413,7 +413,7 @@ def seo_author(self) -> str:
return self.owner.get_full_name()
return ""

@property
@cached_property
def seo_canonical_url(self) -> str:
"""
Gets the full/absolute/canonical URL preferred for meta tags and search engines.
Expand All @@ -426,7 +426,7 @@ def seo_canonical_url(self) -> str:
return url
return self.get_full_url()

@property
@cached_property
def seo_description(self) -> str:
"""
Gets the correct search engine and Open Graph description of this page.
Expand All @@ -439,7 +439,7 @@ def seo_description(self) -> str:
return text
return ""

@property
@cached_property
def seo_image(self) -> Optional[AbstractImage]:
"""
Gets the primary Open Graph image of this page.
Expand All @@ -451,7 +451,7 @@ def seo_image(self) -> Optional[AbstractImage]:
return image
return None

@property
@cached_property
def seo_image_url(self) -> str:
"""
Gets the absolute URL for the primary Open Graph image of this page.
Expand All @@ -472,7 +472,7 @@ class containing ``SeoOrgFields``
"""
return SeoSettings.for_site(site=self.get_site())

@property
@cached_property
def seo_logo(self) -> Optional[AbstractImage]:
"""
Gets the primary logo of the organization.
Expand All @@ -481,7 +481,7 @@ def seo_logo(self) -> Optional[AbstractImage]:
return self.seo_org_fields.struct_org_logo
return None

@property
@cached_property
def seo_logo_url(self) -> str:
"""
Gets the absolute URL for the organization logo.
Expand All @@ -492,15 +492,15 @@ def seo_logo_url(self) -> str:
return utils.ensure_absolute_url(url, base_url)
return ""

@property
@cached_property
def seo_og_type(self) -> str:
"""
Gets the correct Open Graph type for this page.
Override in your Page model as necessary.
"""
return self.seo_content_type.value

@property
@cached_property
def seo_sitename(self) -> str:
"""
Gets the site name.
Expand All @@ -511,7 +511,7 @@ def seo_sitename(self) -> str:
return s.site_name
return ""

@property
@cached_property
def seo_pagetitle(self) -> str:
"""
Gets the correct search engine and Open Graph title of this page.
Expand All @@ -528,23 +528,23 @@ def seo_pagetitle(self) -> str:
self.title, settings.get("WAGTAILSEO_SEP"), self.seo_sitename
)

@property
@cached_property
def seo_published_at(self) -> datetime:
"""
Gets the date this page was first published.
Override in your Page model as necessary.
"""
return self.first_published_at

@property
@cached_property
def seo_twitter_card_content(self) -> str:
"""
Gets the correct style of twitter card for this page.
Override in your Page model as necessary.
"""
return self.seo_twitter_card.value

@property
@cached_property
def seo_struct_org_name(self) -> str:
"""
Gets org name for structured data using a fallback.
Expand All @@ -553,7 +553,7 @@ def seo_struct_org_name(self) -> str:
return self.seo_org_fields.struct_org_name
return self.seo_sitename

@property
@cached_property
def seo_struct_org_base_dict(self) -> dict:
"""
Gets generic "Organization" data for use as a subset of other
Expand Down Expand Up @@ -609,13 +609,13 @@ def seo_struct_org_base_dict(self) -> dict:

return sd_dict

@property
@cached_property
def seo_struct_org_base_json(self) -> str:
return json.dumps(
self.seo_struct_org_base_dict, cls=utils.StructDataEncoder
)

@property
@cached_property
def seo_struct_org_dict(self) -> dict:
"""
Gets full "Organization" structured data on top of base organization data.
Expand Down Expand Up @@ -671,18 +671,18 @@ def seo_struct_org_dict(self) -> dict:

return sd_dict

@property
@cached_property
def seo_struct_org_json(self) -> str:
return json.dumps(self.seo_struct_org_dict, cls=utils.StructDataEncoder)

@property
@cached_property
def seo_struct_publisher_dict(self) -> Optional[dict]:
"""
Gets the base organization info.
"""
return self.seo_struct_org_base_dict or None

@property
@cached_property
def seo_struct_article_dict(self) -> dict:
sd_dict = {
"@context": "http://schema.org",
Expand Down Expand Up @@ -717,7 +717,7 @@ def seo_struct_article_dict(self) -> dict:

return sd_dict

@property
@cached_property
def seo_struct_article_json(self) -> str:
return json.dumps(
self.seo_struct_article_dict, cls=utils.StructDataEncoder
Expand Down
Loading