Skip to content

Commit

Permalink
Merge branch 'master' into test/django-main
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun authored Nov 22, 2023
2 parents 0fca6fd + 0d5b461 commit ba0047d
Show file tree
Hide file tree
Showing 18 changed files with 492 additions and 443 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ concurrency:
cancel-in-progress: true

jobs:
sqlite-unit-tests:
sqlite:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ 3.9, "3.10", "3.11" ] # latest release minus two
python-version: [ 3.9, "3.10", "3.11", "3.12" ] # latest release minus two
requirements-file: [
dj32_cms41.txt,
dj40_cms41.txt,
Expand All @@ -39,12 +39,12 @@ jobs:
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v2

postgres-unit-tests:
postgres:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ 3.9, "3.10", "3.11" ] # latest release minus two
python-version: [ 3.9, "3.10", "3.11", "3.12" ] # latest release minus two
requirements-file: [
dj32_cms41.txt,
dj40_cms41.txt,
Expand Down Expand Up @@ -85,12 +85,12 @@ jobs:
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v2

mysql-unit-tests:
mysql:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ 3.9, "3.10", "3.11" ] # latest release minus two
python-version: [ 3.9, "3.10", "3.11", "3.12" ] # latest release minus two
requirements-file: [
dj32_cms41.txt,
dj40_cms41.txt,
Expand Down
19 changes: 5 additions & 14 deletions djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,13 +1177,8 @@ def compare_view(self, request, object_id):
get_cms_setting("CMS_TOOLBAR_URL__DISABLE"): 1,
get_cms_setting("CMS_TOOLBAR_URL__PERSIST"): 0,
}
v1_preview_url = add_url_parameters(
reverse(
"admin:cms_placeholder_render_object_preview",
args=(v1.content_type_id, v1.object_id),
),
**persist_params
)
v1_preview_url = get_preview_url(v1.content)
v1_preview_url = add_url_parameters(v1_preview_url, **persist_params)
# Get the list of versions for the grouper. This is for use
# in the dropdown to choose a version.
version_list = Version.objects.filter_by_content_grouping_values(
Expand All @@ -1206,16 +1201,12 @@ def compare_view(self, request, object_id):
request, self.model._meta, request.GET["compare_to"]
)
else:
v2_preview_url = get_preview_url(v2.content)
v2_preview_url = add_url_parameters(v2_preview_url, **persist_params)
context.update(
{
"v2": v2,
"v2_preview_url": add_url_parameters(
reverse(
"admin:cms_placeholder_render_object_preview",
args=(v2.content_type_id, v2.object_id),
),
**persist_params
),
"v2_preview_url": v2_preview_url,
}
)
return TemplateResponse(
Expand Down
3 changes: 2 additions & 1 deletion djangocms_versioning/cms_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .helpers import (
get_latest_admin_viewable_content,
inject_generic_relation_to_version,
is_editable,
placeholder_content_is_unlocked_for_user,
register_versionadmin_proxy,
replace_admin_for_models,
Expand Down Expand Up @@ -408,5 +409,5 @@ class VersioningCMSConfig(CMSAppConfig):
)
]
cms_toolbar_mixin = CMSToolbarVersioningMixin
PageContent.add_to_class("is_editable", indicators.is_editable)
PageContent.add_to_class("is_editable", is_editable)
PageContent.add_to_class("content_indicator", indicators.content_indicator)
2 changes: 1 addition & 1 deletion djangocms_versioning/cms_menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def get_nodes(self, request):

# Depending on the toolbar mode, we need to get the correct version.
# On edit or preview mode: return DRAFT,
# if DRAFT does not exists then return PUBLISHED.
# if DRAFT does not exist then return PUBLISHED.
# On public mode: return PUBLISHED.
if edit_or_preview:
states = [constants.DRAFT, constants.PUBLISHED]
Expand Down
11 changes: 10 additions & 1 deletion djangocms_versioning/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
emit_content_change = None


def is_editable(content_obj, request):
"""Check of content_obj is editable"""
from .models import Version

return Version.objects.get_for_content(content_obj).check_modify.as_bool(request.user)


def versioning_admin_factory(admin_class, mixin):
"""A class factory returning admin class with overriden
versioning functionality.
Expand Down Expand Up @@ -147,6 +154,8 @@ def inject_generic_relation_to_version(model):
related_query_name = f"{model._meta.app_label}_{model._meta.model_name}"
model.add_to_class("versions", GenericRelation(
Version, related_query_name=related_query_name))
if not hasattr(model, "is_editable"):
model.add_to_class("is_editable", is_editable)


def _set_default_manager(model, manager):
Expand Down Expand Up @@ -264,8 +273,8 @@ def get_preview_url(content_obj: models.Model, language: typing.Union[str, None]
return versionable.preview_url(content_obj)
if is_editable_model(content_obj.__class__):
url = get_object_preview_url(content_obj, language=language)
# Or else, the standard change view should be used
else:
# Or else, the standard change view should be used
url = admin_reverse(
f"{content_obj._meta.app_label}_{content_obj._meta.model_name}_change",
args=[content_obj.pk],
Expand Down
9 changes: 0 additions & 9 deletions djangocms_versioning/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,3 @@ def content_indicator(content_obj):
content_obj._indicator_status = None
content_obj._version = [None]
return content_obj._indicator_status


def is_editable(content_obj, request):
"""Check of content_obj is editable"""
if not content_obj.content_indicator():
# Something's wrong: content indicator not identified. Maybe no version?
return False
versions = content_obj._version
return versions[0].check_modify.as_bool(request.user)
Loading

0 comments on commit ba0047d

Please sign in to comment.