Skip to content

Commit

Permalink
Add caching to PageContent __bool__ (#346)
Browse files Browse the repository at this point in the history
* fix: avoid triggering __bool__ on PageContent when checking for None

* fix: adjust slug changes test for django-cms 4.1.0rc4

Slugs are no longer slugified on clean in ChangePageForm

* fix: remove __bool__ on PageContent checking if version exists

Tests pass without, need unclear, but causing excessive database queries
  • Loading branch information
stefanw authored Sep 11, 2023
1 parent 172a2b3 commit ad24c93
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog
Unreleased
==========
* feat: Reversable generic foreign key lookup from version
* fix: Remove version check when evaluating CMS PageContent objects

2.0.0rc1
========
Expand Down
1 change: 0 additions & 1 deletion djangocms_versioning/cms_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,3 @@ class VersioningCMSConfig(CMSAppConfig):
cms_toolbar_mixin = CMSToolbarVersioningMixin
PageContent.add_to_class("is_editable", indicators.is_editable)
PageContent.add_to_class("content_indicator", indicators.content_indicator)
PageContent.add_to_class("__bool__", lambda self: self.versions.exists())
2 changes: 1 addition & 1 deletion djangocms_versioning/test_utils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def get_plugin_language(plugin):
"""Helper function to get the language from a plugin's relationships.
Use this in plugin factory classes
"""
if plugin.placeholder.source:
if plugin.placeholder.source is not None:
return plugin.placeholder.source.language
# NOTE: If plugin.placeholder.source is None then language will
# also be None unless set manually
Expand Down
8 changes: 4 additions & 4 deletions tests/test_cms_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ def test_published_version_with_new_version_retains_pageurl_unmanaged(self):

def test_changing_slug_changes_page_url(self):
"""Using change form to change title / slug updates path?"""
new_title = "new slug here"
new_slug = "new-slug-here"
data = {
"title": self.content.title,
"slug": new_title
"slug": new_slug
}

request = req_factory.get("/?language=en")
Expand All @@ -125,8 +125,8 @@ def test_changing_slug_changes_page_url(self):
page = Page.objects.get(pk=self.page.pk)
url = page.get_urls().first()

self.assertEqual(url.slug, slugify(new_title))
self.assertEqual(url.path, slugify(new_title))
self.assertEqual(url.slug, new_slug)
self.assertEqual(url.path, new_slug)


class VersioningExtensionUnitTestCase(CMSTestCase):
Expand Down

0 comments on commit ad24c93

Please sign in to comment.