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: Remove get_absolute_url from both Alias and AliasContent models #199

Merged
merged 24 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5b15e0b
Remove `get_absolute_url()` from Alias
fsbraun Nov 12, 2023
1591a8a
Merge branch 'master' of github.com:fsbraun/djangocms-alias
fsbraun Nov 12, 2023
b67a43a
Merge branch 'master' into fix/remove_get_abs_url
fsbraun Nov 12, 2023
6622478
ci: auto fixes from pre-commit hooks
pre-commit-ci[bot] Nov 12, 2023
6a26f16
Fix: remove unused import
fsbraun Nov 12, 2023
d8248cf
Merge branch 'fix/remove_get_abs_url' of github.com:fsbraun/djangocms…
fsbraun Nov 12, 2023
7907064
Fix: flake8 errors
fsbraun Nov 12, 2023
04909a1
Add `get_admin_change_url` to alias category model
fsbraun Nov 12, 2023
81dd080
Merge branch 'master' into fix/remove_get_abs_url
fsbraun Nov 18, 2023
1cfa272
Reintroduce links to aliases in alias usage view
fsbraun Nov 24, 2023
8b93c4e
Merge branch 'fix/remove_get_abs_url' of github.com:fsbraun/djangocms…
fsbraun Nov 24, 2023
1edbc3c
Adjust djmain test requirements
fsbraun Nov 24, 2023
c29e29e
Correct url for django-cms@develop-4
fsbraun Nov 24, 2023
e72a168
Update delete_confirmation.html to contain object's admin urls
fsbraun Nov 24, 2023
d015eb5
Merge branch 'master' into fix/remove_get_abs_url
fsbraun Dec 12, 2023
9b8e6d0
Merge branch 'master' into fix/remove_get_abs_url
fsbraun Jan 30, 2024
def2d56
Merge branch 'master' into fix/remove_get_abs_url
fsbraun Feb 12, 2024
a026a8a
ci: auto fixes from pre-commit hooks
pre-commit-ci[bot] Feb 12, 2024
0cfb612
Merge branch 'master' into fix/remove_get_abs_url
fsbraun Feb 12, 2024
ef5760e
Merge branch 'master' into fix/remove_get_abs_url
fsbraun Mar 5, 2024
af96fae
ci: auto fixes from pre-commit hooks
pre-commit-ci[bot] Mar 5, 2024
23313b3
Update djangocms_alias/templatetags/djangocms_alias_tags.py
fsbraun Mar 5, 2024
3ee50d1
Update tests to allow new redirect of edit object endpoint
fsbraun Mar 5, 2024
c70892b
ci: auto fixes from pre-commit hooks
pre-commit-ci[bot] Mar 5, 2024
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 @@
@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()

Check failure on line 45 in djangocms_alias/cms_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

multiple spaces after operator

Check failure on line 45 in djangocms_alias/cms_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

multiple spaces after operator
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(

Check failure on line 53 in djangocms_alias/cms_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

indentation is not a multiple of 4

Check failure on line 53 in djangocms_alias/cms_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

over-indented

Check failure on line 53 in djangocms_alias/cms_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

indentation is not a multiple of 4

Check failure on line 53 in djangocms_alias/cms_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

over-indented
PluginMenuItem(

Check failure on line 54 in djangocms_alias/cms_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

continuation line under-indented for hanging indent

Check failure on line 54 in djangocms_alias/cms_plugins.py

View workflow job for this annotation

GitHub Actions / flake8

continuation line under-indented for hanging indent
_('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
9 changes: 5 additions & 4 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.utils.timezone import localtime

from cms.api import add_plugin
from cms.toolbar.utils import get_object_edit_url, get_object_preview_url

Check failure on line 9 in tests/test_admin.py

View workflow job for this annotation

GitHub Actions / flake8

'cms.toolbar.utils.get_object_edit_url' imported but unused

Check failure on line 9 in tests/test_admin.py

View workflow job for this annotation

GitHub Actions / flake8

'cms.toolbar.utils.get_object_edit_url' imported but unused
Fixed Show fixed Hide fixed
from cms.utils.i18n import force_language
from cms.utils.urlutils import add_url_parameters, admin_reverse

Expand Down Expand Up @@ -223,7 +224,7 @@
response_content_decoded = response.content.decode()

self.assertIn(
expected_en_content.get_absolute_url(),
get_object_preview_url(expected_en_content),
response_content_decoded,
)
self.assertNotIn(
Expand Down Expand Up @@ -425,9 +426,9 @@
self.assertNotContains(response, "Published")
self.assertNotContains(response, "Draft")

aliascontent1_url = alias1.get_absolute_url()
aliascontent2_url = alias2.get_absolute_url()
aliascontent3_url = alias3.get_absolute_url()
aliascontent1_url = get_object_preview_url(alias1.get_content(show_draft_content=True))
aliascontent2_url = get_object_preview_url(alias2.get_content(show_draft_content=True))
aliascontent3_url = get_object_preview_url(alias3.get_content(show_draft_content=True))

# when versioning is not enabled, the django admin change form
# is used which used links to the aliascontent_change view
Expand Down
7 changes: 4 additions & 3 deletions tests/test_cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from urllib.parse import urlparse

from cms.api import add_plugin, create_title
from cms.toolbar.utils import get_object_edit_url
from cms.utils import get_current_site
from cms.utils.plugins import downcast_plugins
from cms.utils.urlutils import admin_reverse
Expand Down Expand Up @@ -51,8 +52,8 @@ def test_extra_plugin_items_for_alias_plugins(self):
self.assertEqual(len(extra_items), 2)
first, second = extra_items
self.assertEqual(first.name, 'Edit Alias')
self.assertEqual(first.url, alias.get_absolute_url())
self.assertEqual(first.action, 'sideframe')
self.assertEqual(first.url, get_object_edit_url(alias.get_content()))
self.assertEqual(first.action, '')

self.assertEqual(second.name, 'Detach Alias')
self.assertEqual(second.action, 'modal')
Expand Down Expand Up @@ -96,7 +97,7 @@ def test_extra_plugin_items_with_versioning_checks(self):
first = extra_items[0]
# We cannot detach alias on undraft page
self.assertEqual(first.name, 'Edit Alias')
self.assertEqual(first.url, alias.get_absolute_url())
self.assertEqual(first.url, get_object_edit_url(alias.get_content()))

def test_rendering_plugin_on_page(self):
alias = self._create_alias(published=True)
Expand Down
6 changes: 4 additions & 2 deletions tests/test_menu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from cms.toolbar.utils import get_object_edit_url

from djangocms_alias.utils import is_versioning_enabled

from .base import BaseAliasPluginTestCase
Expand All @@ -8,8 +10,8 @@ class AliasMenuTestCase(BaseAliasPluginTestCase):
def test_alias_pages_have_no_menu_nodes(self):
alias = self._create_alias()
with self.login_user_context(self.superuser):
response = self.client.get(alias.get_absolute_url())
if is_versioning_enabled():
response = self.client.get(get_object_edit_url(alias.get_content()))
if is_versioning_enabled() and False:
self.assertNotContains(response, '<ul class="nav">')
else:
self.assertInHTML('<ul class="nav"></ul>', response.content.decode())
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def test_delete(self):
alias.save() # Django 4.1+ disallows to use relations (cmsplugins) of unsaved objects.
self.assertEqual(alias.cms_plugins.count(), 0)

def test_category_get_absolute_url(self):
def test_category_get_edit_url(self):
"""
Category uses the admin change view as its absolute url
"""
Expand All @@ -420,7 +420,7 @@ def test_category_get_absolute_url(self):
f"admin:{app_label}_category_change", args=[category.pk]
)

self.assertEqual(category.get_absolute_url(), expected)
self.assertEqual(category.get_edit_url(), expected)

def test_category_name_same_across_languages(self):
"""
Expand Down
27 changes: 14 additions & 13 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from cms.api import add_plugin
from cms.models import Placeholder
from cms.toolbar.utils import get_object_edit_url
from cms.utils import get_current_site
from cms.utils.i18n import force_language
from cms.utils.plugins import downcast_plugins
Expand Down Expand Up @@ -396,7 +397,7 @@ def test_detach_view(self):
def test_alias_content_preview_view(self):
alias = self._create_alias([self.plugin])
with self.login_user_context(self.superuser):
response = self.client.get(alias.get_content().get_absolute_url())
response = self.client.get(get_object_edit_url(alias.get_content()))

self.assertEqual(response.status_code, 200)
self.assertContains(response, alias.name)
Expand Down Expand Up @@ -844,13 +845,13 @@ def test_alias_usage_view(self):
str(self.page),
),
)
self.assertRegex(
str(response.content),
r'href="{}"[\w+]?>{}<\/a>'.format(
re.escape(root_alias.get_absolute_url()),
str(alias),
),
)
# self.assertRegex(
fsbraun marked this conversation as resolved.
Show resolved Hide resolved
# str(response.content),
# r'href="{}"[\w+]?>{}<\/a>'.format(
# re.escape(get_object_edit_url(root_alias.get_content())),
# str(alias),
# ),
# )
self.assertRegex(
str(response.content),
r'href="{}"[\w+]?>{}<\/a>'.format(
Expand Down Expand Up @@ -1470,7 +1471,7 @@ def test_view_multilanguage(self):
if is_versioning_enabled():
# we need to call get_absolute_url on the AliasContent object when versioning is enabled,
# otherwise we are taken to the version list url
detail_response = self.client.get(alias.get_content(language="en").get_absolute_url())
detail_response = self.client.get(get_object_edit_url(alias.get_content(language="en")))
else:
detail_response = self.client.get(alias.get_absolute_url())
list_response = self.client.get(
Expand All @@ -1488,9 +1489,9 @@ def test_view_multilanguage(self):
if is_versioning_enabled():
# we need to call get_absolute_url on the AliasContent object when versioning is enabled,
# otherwise we are taken to the version list url
detail_response = self.client.get(alias_content_de.get_absolute_url())
detail_response = self.client.get(get_object_edit_url(alias_content_de))
else:
detail_response = self.client.get(alias.get_absolute_url())
detail_response = self.client.get(get_object_edit_url(alias.get_content()))
list_response = self.client.get(
admin_reverse(LIST_ALIAS_URL_NAME),
)
Expand All @@ -1506,9 +1507,9 @@ def test_view_multilanguage(self):
if is_versioning_enabled():
# we need to call get_absolute_url on the AliasContent object when versioning is enabled,
# otherwise we are taken to the version list url
detail_response = self.client.get(alias_content_fr.get_absolute_url())
detail_response = self.client.get(get_object_edit_url(alias_content_fr))
else:
detail_response = self.client.get(alias.get_absolute_url())
detail_response = self.client.get(get_object_edit_url(alias.get_content()))
list_response = self.client.get(
admin_reverse(LIST_ALIAS_URL_NAME), # noqa: E501
)
Expand Down
6 changes: 4 additions & 2 deletions tests/test_wizards.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.sites.models import Site
from django.utils import translation

from cms.toolbar.utils import get_object_edit_url
from cms.utils import get_current_site
from cms.wizards.forms import WizardStep2BaseForm, step2_form_factory
from cms.wizards.helpers import get_entries as get_wizard_entires
Expand Down Expand Up @@ -65,7 +66,8 @@ def test_create_alias_wizard_form(self):
self.assertEqual(form.fields['site'].initial, get_current_site())

with self.login_user_context(self.superuser):
response = self.client.get(alias.get_absolute_url())
url = get_object_edit_url(alias.get_content(show_draft_content=True))
response = self.client.get(url)
self.assertContains(response, data['name'])

if is_versioning_enabled():
Expand Down Expand Up @@ -137,5 +139,5 @@ def test_create_alias_category_wizard_form(self):
category = form.save()

with self.login_user_context(self.superuser):
response = self.client.get(category.get_absolute_url())
response = self.client.get(category.get_edit_url())
self.assertContains(response, data['name'])
Loading