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 9 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
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
2 changes: 1 addition & 1 deletion djangocms_versioning/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def get_page_content(self, language=None):
return get_latest_admin_viewable_content(self.page, language=language)

def populate(self):
self.page = self.request.current_page or getattr(self.toolbar.obj, "page", None)
self.page = self.request.current_page
fsbraun marked this conversation as resolved.
Show resolved Hide resolved
self.title = self.get_page_content() if self.page else None
self.permissions_activated = get_cms_setting("PERMISSION")

Expand Down
4 changes: 4 additions & 0 deletions djangocms_versioning/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.db import models
from django.template.loader import render_to_string
from django.utils.encoding import force_str
from django.utils.translation import get_language

from . import versionables
from .conf import EMAIL_NOTIFICATIONS_FAIL_SILENTLY
Expand Down Expand Up @@ -263,6 +264,9 @@ def get_preview_url(content_obj: models.Model, language: typing.Union[str, None]
if versionable.preview_url:
return versionable.preview_url(content_obj)
if is_editable_model(content_obj.__class__):
if not language:
# Use language field is content object has one to determine the language
language = getattr(content_obj, "language", get_language())
url = get_object_preview_url(content_obj, language=language)
# Or else, the standard change view should be used
else:
Expand Down
Loading
Loading