Skip to content

Commit

Permalink
fix: wizard creation error (#245)
Browse files Browse the repository at this point in the history
* fix: `get_absolute_url` method not found while creating new alias and category from wizard button.

* feat: Added search capability in AliasContent admin (migrate the 4.0.x feature from PR #236)

* ci: auto fixes from pre-commit hooks

for more information, see https://pre-commit.ci

* Update py311-djmain-cms4dev-default.txt

* Update py311-djmain-cms4dev-versioning.txt

* Update py311-djmain-cms41-default.txt

* Update py311-djmain-cms41-versioning.txt

* Update test_admin.py for Django 5.1+

* ci: auto fixes from pre-commit hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Fabian Braun <[email protected]>
  • Loading branch information
3 people authored Aug 20, 2024
1 parent 3dfa143 commit 25a7473
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Changelog
=========

Unreleased
==========
* fix: `get_absolute_url` method not found while creating new alias and category from wizard button.
* feat: Added search capability in AliasContent admin (migrate the 4.0.x feature from PR #236)


2.0.1 (2024-03-27)
==================

Expand Down
1 change: 1 addition & 0 deletions djangocms_alias/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class AliasAdmin(*alias_admin_classes):
)
fields = ("content__name", "category", "site", "content__language")
readonly_fields = ("static_code",)
search_fields = ["content__name"]
form = AliasGrouperAdminForm
extra_grouping_fields = ("language",)
EMPTY_CONTENT_VALUE = mark_safe(_("<i>Missing language</i>"))
Expand Down
6 changes: 6 additions & 0 deletions djangocms_alias/cms_wizards.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ class CreateAliasWizard(Wizard):
def user_has_add_permission(self, user, **kwargs):
return Alias.can_create_alias(user)

def get_success_url(self, obj, **kwargs):
return obj.get_admin_change_url()


class CreateAliasCategoryWizard(Wizard):
def user_has_add_permission(self, user, **kwargs):
return user.has_perm(
get_model_permission_codename(Category, "add"),
)

def get_success_url(self, obj, **kwargs):
return obj.get_admin_change_url()


create_alias_wizard = CreateAliasWizard(
title=_("New alias"),
Expand Down
5 changes: 4 additions & 1 deletion djangocms_alias/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.utils.translation import gettext_lazy as _
from parler.models import TranslatableModel, TranslatedFields

from .constants import CHANGE_CATEGORY_URL_NAME
from .constants import CHANGE_ALIAS_URL_NAME, CHANGE_CATEGORY_URL_NAME
from .utils import is_versioning_enabled

__all__ = [
Expand Down Expand Up @@ -123,6 +123,9 @@ def name(self):
def is_in_use(self):
return self.cms_plugins.exists()

def get_admin_change_url(self):
return admin_reverse(CHANGE_ALIAS_URL_NAME, args=[self.pk])

@cached_property
def objects_using(self):
objects = set()
Expand Down
2 changes: 1 addition & 1 deletion 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.7.2
asgiref==3.8.1
# via django
beautifulsoup4==4.12.2
# via bs4
Expand Down
2 changes: 1 addition & 1 deletion 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.7.2
asgiref==3.8.1
# via django
beautifulsoup4==4.12.2
# via bs4
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements/py311-djmain-cms4dev-default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# requirements/compile.py
#
asgiref==3.7.2
asgiref==3.8.1
# via django
beautifulsoup4==4.12.2
# via bs4
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements/py311-djmain-cms4dev-versioning.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# requirements/compile.py
#
asgiref==3.7.2
asgiref==3.8.1
# via django
beautifulsoup4==4.12.2
# via bs4
Expand Down
6 changes: 2 additions & 4 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,8 @@ def test_aliases_admin_entry_is_hidden(self):

response = self.client.get(index_url)

unexpected_content = (
'<th scope="row"><a href="/en/admin/djangocms_alias/aliascontent/">' "Alias contents</a></th>"
)
expected_content = '<th scope="row"><a href="/en/admin/djangocms_alias/alias/">Aliases</a></th>'
unexpected_content = '<a href="/en/admin/djangocms_alias/aliascontent/">' "Alias contents</a>"
expected_content = '<a href="/en/admin/djangocms_alias/alias/">Aliases</a>'

self.assertEqual(response.status_code, 200)
self.assertContains(response, expected_content)
Expand Down

0 comments on commit 25a7473

Please sign in to comment.