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

fix: Preview link language #357

Merged
merged 17 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
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
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

Check warning on line 31 in djangocms_versioning/helpers.py

View check run for this annotation

Codecov / codecov/patch

djangocms_versioning/helpers.py#L31

Added line #L31 was not covered by tests

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
djangocms_versioning.models
begins an import cycle.

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

Check warning on line 33 in djangocms_versioning/helpers.py

View check run for this annotation

Codecov / codecov/patch

djangocms_versioning/helpers.py#L33

Added line #L33 was not covered by tests


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 @@
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 @@
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
Loading