diff --git a/djangocms_alias/cms_plugins.py b/djangocms_alias/cms_plugins.py index f440106e..4bc764a2 100644 --- a/djangocms_alias/cms_plugins.py +++ b/djangocms_alias/cms_plugins.py @@ -2,6 +2,7 @@ from cms.plugin_base import CMSPluginBase, PluginMenuItem from cms.plugin_pool import plugin_pool +from cms.toolbar.utils import get_object_edit_url from cms.utils.permissions import ( get_model_permission_codename, has_plugin_permission, @@ -39,20 +40,22 @@ def get_render_template(self, context, instance, placeholder): @classmethod def get_extra_plugin_menu_items(cls, request, plugin): if plugin.plugin_type == cls.__name__: - edit_endpoint = plugin.alias.get_absolute_url() + alias_content = plugin.alias.get_content() detach_endpoint = admin_reverse( DETACH_ALIAS_PLUGIN_URL_NAME, args=[plugin.pk], ) - plugin_menu_items = [ - PluginMenuItem( - _("Edit Alias"), - edit_endpoint, - action="sideframe", - attributes={"cms-icon": "alias"}, - ), - ] + plugin_menu_items = [] + if alias_content: + plugin_menu_items.append( + PluginMenuItem( + _("Edit Alias"), + get_object_edit_url(alias_content), + action="", + attributes={"cms-icon": "alias"}, + ), + ) if cls.can_detach( request.user, diff --git a/djangocms_alias/cms_toolbars.py b/djangocms_alias/cms_toolbars.py index 87f102c5..7d241470 100644 --- a/djangocms_alias/cms_toolbars.py +++ b/djangocms_alias/cms_toolbars.py @@ -8,10 +8,10 @@ SHORTCUTS_BREAK, ) from cms.toolbar.items import Break, ButtonList +from cms.toolbar.utils import get_object_edit_url from cms.toolbar_base import CMSToolbar from cms.toolbar_pool import toolbar_pool from cms.utils.i18n import ( - force_language, get_default_language, get_language_dict, get_language_tuple, @@ -185,8 +185,7 @@ def override_language_switcher(self): show_draft_content=True, ) if alias_content: - with force_language(code): - url = alias_content.get_absolute_url() + url = get_object_edit_url(alias_content, language=code) language_menu.add_link_item(name, url=url, active=self.current_lang == code) def change_language_menu(self): diff --git a/djangocms_alias/forms.py b/djangocms_alias/forms.py index afc1f886..d128b491 100644 --- a/djangocms_alias/forms.py +++ b/djangocms_alias/forms.py @@ -148,15 +148,11 @@ def save(self): category=self.cleaned_data.get("category"), site=self.cleaned_data.get("site"), ) - alias_content = AliasContent.objects.create( + alias_content = AliasContent.objects.with_user(self.user).create( alias=alias, name=self.cleaned_data.get("name"), language=self.cleaned_data.get("language"), ) - if is_versioning_enabled(): - from djangocms_versioning.models import Version - - Version.objects.create(content=alias_content, created_by=self.user) if self.cleaned_data.get("replace"): placeholder = self.cleaned_data.get("placeholder") plugin = self.cleaned_data.get("plugin") diff --git a/djangocms_alias/internal_search.py b/djangocms_alias/internal_search.py index 34d4d835..30b02c15 100644 --- a/djangocms_alias/internal_search.py +++ b/djangocms_alias/internal_search.py @@ -1,4 +1,4 @@ -from cms.toolbar.utils import get_toolbar_from_request +from cms.toolbar.utils import get_object_preview_url, get_toolbar_from_request from django.template import RequestContext from django.utils.translation import gettext_lazy as _ from djangocms_internalsearch.base import BaseSearchConfig @@ -77,7 +77,7 @@ def prepare_text(self, obj): return content def prepare_url(self, obj): - return obj.get_absolute_url() + return get_object_preview_url(obj) def prepare_category(self, obj): obj.alias.category.set_current_language(obj.language) diff --git a/djangocms_alias/models.py b/djangocms_alias/models.py index f9190817..4e0b397f 100644 --- a/djangocms_alias/models.py +++ b/djangocms_alias/models.py @@ -5,7 +5,6 @@ from cms.models import CMSPlugin, Placeholder from cms.models.fields import PlaceholderRelationField from cms.models.managers import WithUserMixin -from cms.toolbar.utils import get_object_preview_url from cms.utils.plugins import copy_plugins_to_placeholder from cms.utils.urlutils import admin_reverse from django.conf import settings @@ -62,7 +61,7 @@ def __str__(self): # Be sure to be able to see the category name even if it's not in the current language return self.safe_translation_getter("name", any_language=True) - def get_absolute_url(self): + def get_admin_change_url(self): """Builds the url to the admin category change view""" return admin_reverse(CHANGE_CATEGORY_URL_NAME, args=[self.pk]) @@ -160,17 +159,6 @@ def get_name(self, language=None): return name - def get_absolute_url(self, language=None): - if is_versioning_enabled(): - from djangocms_versioning.helpers import ( - version_list_url_for_grouper, - ) - - return version_list_url_for_grouper(self) - content = self.get_content(language=language) - if content: - return content.get_absolute_url() - def get_content(self, language=None, show_draft_content=False): if not language: language = get_language() @@ -300,9 +288,6 @@ def placeholder(self): def get_placeholders(self): return [self.placeholder] - def get_absolute_url(self): - return get_object_preview_url(self) - def get_template(self): return "djangocms_alias/alias_content.html" diff --git a/djangocms_alias/templates/admin/djangocms_alias/alias/delete_confirmation.html b/djangocms_alias/templates/admin/djangocms_alias/alias/delete_confirmation.html index ae4878ab..cef5e7fd 100644 --- a/djangocms_alias/templates/admin/djangocms_alias/alias/delete_confirmation.html +++ b/djangocms_alias/templates/admin/djangocms_alias/alias/delete_confirmation.html @@ -26,7 +26,7 @@ {% for item in object.objects_using %}