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: static_alias unnecessarily creates now content objects when used with versioning #201

Closed
wants to merge 9 commits into from
Closed
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
21 changes: 12 additions & 9 deletions djangocms_alias/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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,
Expand Down Expand Up @@ -41,20 +42,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,
Expand Down
5 changes: 2 additions & 3 deletions djangocms_alias/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,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,
Expand Down Expand Up @@ -193,8 +193,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):
Expand Down
5 changes: 1 addition & 4 deletions djangocms_alias/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,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')
Expand Down
4 changes: 2 additions & 2 deletions djangocms_alias/internal_search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.template import RequestContext
from django.utils.translation import gettext_lazy as _

from cms.toolbar.utils import get_toolbar_from_request
from cms.toolbar.utils import get_object_preview_url, get_toolbar_from_request

from djangocms_internalsearch.base import BaseSearchConfig
from djangocms_internalsearch.helpers import get_request, get_version_object
Expand Down Expand Up @@ -79,7 +79,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)
Expand Down
17 changes: 1 addition & 16 deletions djangocms_alias/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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

Expand Down Expand Up @@ -64,7 +63,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_edit_url(self):
"""Builds the url to the admin category change view"""
return admin_reverse(CHANGE_CATEGORY_URL_NAME, args=[self.pk])

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -296,9 +284,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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% for item in object.objects_using %}
<li>
{{ item|verbose_name|capfirst|escape }}:
<a href="{{ item.get_absolute_url }}">{{ item }}</a>
{% if item.get_absolute_url %}<a href="{{ item.get_absolute_url }}">{{ item }}</a>{% else %}{{ item }}{% endif %}
</li>
{% endfor %}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion djangocms_alias/templatetags/djangocms_alias_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _get_alias(self, request, static_code, extra_bits):

alias = Alias.objects.create(category=default_category, **alias_creation_kwargs)

if not AliasContent._default_manager.filter(alias=alias, language=language).exists():
if not AliasContent._base_manager.filter(alias=alias, language=language).exists():
# Create a first content object if none exists in the given language.
# If versioning is enabled we can only create the records with a logged-in user / staff member
if is_versioning_enabled() and not request.user.is_authenticated:
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements/py311-dj40-cms41-default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements/py311-dj40-cms41-versioning.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/py311-dj41-cms41-default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ coverage==7.2.3
# via -r requirements.in
dj-database-url==2.0.0
# via django-app-helper
django==4.1.9
django==4.1.13
# via
# dj-database-url
# django-classy-tags
Expand All @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/py311-dj41-cms41-versioning.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ coverage==7.2.3
# via -r requirements.in
dj-database-url==2.0.0
# via django-app-helper
django==4.1.9
django==4.1.13
# via
# dj-database-url
# django-classy-tags
Expand All @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/py311-dj42-cms41-default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ coverage==7.2.3
# via -r requirements.in
dj-database-url==2.0.0
# via django-app-helper
django==4.2.1
django==4.2.7
# via
# dj-database-url
# django-classy-tags
Expand All @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/py311-dj42-cms41-versioning.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ coverage==7.2.3
# via -r requirements.in
dj-database-url==2.0.0
# via django-app-helper
django==4.2.1
django==4.2.7
# via
# dj-database-url
# django-classy-tags
Expand All @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/py311-djmain-cms41-default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# requirements/compile.py
#
asgiref==3.6.0
asgiref==3.7.2
# via django
beautifulsoup4==4.12.2
# via bs4
Expand All @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
git+https://github.com/django-cms/django-cms@develop-4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/py311-djmain-cms41-versioning.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# requirements/compile.py
#
asgiref==3.6.0
asgiref==3.7.2
# via django
beautifulsoup4==4.12.2
# via bs4
Expand All @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
git+https://github.com/django-cms/django-cms@develop-4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/py39-dj32-cms41-default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ coverage==7.2.3
# via -r requirements.in
dj-database-url==2.0.0
# via django-app-helper
django==3.2.19
django==3.2.23
# via
# dj-database-url
# django-classy-tags
Expand All @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/py39-dj32-cms41-versioning.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ coverage==7.2.3
# via -r requirements.in
dj-database-url==2.0.0
# via django-app-helper
django==3.2.19
django==3.2.23
# via
# dj-database-url
# django-classy-tags
Expand All @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements/py39-dj40-cms41-default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements/py39-dj40-cms41-versioning.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/py39-dj41-cms41-default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ coverage==7.2.3
# via -r requirements.in
dj-database-url==2.0.0
# via django-app-helper
django==4.1.9
django==4.1.13
# via
# dj-database-url
# django-classy-tags
Expand All @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/py39-dj41-cms41-versioning.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ coverage==7.2.3
# via -r requirements.in
dj-database-url==2.0.0
# via django-app-helper
django==4.1.9
django==4.1.13
# via
# dj-database-url
# django-classy-tags
Expand All @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/py39-dj42-cms41-default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ coverage==7.2.3
# via -r requirements.in
dj-database-url==2.0.0
# via django-app-helper
django==4.2.1
django==4.2.7
# via
# dj-database-url
# django-classy-tags
Expand All @@ -31,7 +31,7 @@ django-classy-tags==4.0.0
# -r requirements.in
# django-cms
# django-sekizai
django-cms==4.1.0rc3
django-cms==4.1.0rc4
# via
# -r requirements.in
# djangocms-versioning
Expand Down
Loading
Loading