Skip to content

Commit

Permalink
Fix language issue with preview links
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Oct 24, 2023
1 parent a781615 commit 16e1252
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 392 deletions.
21 changes: 6 additions & 15 deletions djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from django.utils.encoding import force_str
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext_lazy as _, get_language

from . import conf, versionables
from .constants import DRAFT, INDICATOR_DESCRIPTIONS, PUBLISHED, VERSION_STATES
Expand Down 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": add_url_parameters(v2_preview_url, **persist_params),
}
)
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
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

0 comments on commit 16e1252

Please sign in to comment.