-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for djangoCMS 4.x (#226)
* fix: make Page queryies ready for djangocms 4.x * feat: add support for djangoCMS 4 * tests: refactor tests for djangoCMS 4 support * chore: extract 'django cms 4' compatibility function to reuse it between fields * fix: isort the tests/ directory
- Loading branch information
1 parent
f8132ce
commit 9d0a24b
Showing
8 changed files
with
99 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def get_queryset_manager(base): | ||
if hasattr(base, "drafts"): | ||
return base.drafts() | ||
return base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from django.apps import apps | ||
|
||
from cms import __version__ | ||
|
||
|
||
DJANGO_CMS4 = not (__version__ < "4") | ||
DJANGOCMS_VERSIONING = apps.is_installed("djangocms_versioning") | ||
|
||
|
||
class TestFixture: | ||
"""Sets up generic setUp and tearDown methods for tests.""" | ||
|
||
def setUp(self): | ||
self.language = "en" | ||
self.superuser = self.get_superuser() | ||
return super().setUp() | ||
|
||
def tearDown(self): | ||
if DJANGOCMS_VERSIONING: | ||
from djangocms_versioning.models import Version | ||
|
||
Version.objects.all().delete() | ||
return super().tearDown() | ||
|
||
if DJANGO_CMS4: # CMS V4 | ||
|
||
def _get_version(self, grouper, version_state, language=None): | ||
language = language or self.language | ||
|
||
from djangocms_versioning.models import Version | ||
|
||
versions = Version.objects.filter_by_grouper(grouper).filter( | ||
state=version_state | ||
) | ||
for version in versions: | ||
if ( | ||
hasattr(version.content, "language") | ||
and version.content.language == language | ||
): | ||
return version | ||
return None | ||
|
||
def publish(self, grouper, language=None): | ||
if DJANGOCMS_VERSIONING: | ||
from djangocms_versioning.constants import DRAFT | ||
|
||
version = self._get_version(grouper, DRAFT, language) | ||
if version is not None: | ||
version.publish(self.superuser) | ||
|
||
def unpublish(self, grouper, language=None): | ||
if DJANGOCMS_VERSIONING: | ||
from djangocms_versioning.constants import PUBLISHED | ||
|
||
version = self._get_version(grouper, PUBLISHED, language) | ||
if version is not None: | ||
version.unpublish(self.superuser) | ||
|
||
def get_placeholders(self, page, language=None): | ||
return page.get_placeholders(language or self.language) | ||
|
||
else: # CMS V3 | ||
|
||
def publish(self, page, language=None): | ||
page.publish(language) | ||
|
||
def unpublish(self, page, language=None): | ||
page.unpublish(language) | ||
|
||
def get_placeholders(self, page, language=None): | ||
return page.get_placeholders() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters