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: wizard creation error #245

Merged
merged 9 commits into from
Aug 20, 2024
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()

Comment on lines +16 to +18
Copy link
Member

@fsbraun fsbraun Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Alias situation is different. I'd prefer it to go to the edit endpoint of Alias. But that might be for a different PR. What do you think, @joshyu ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fsbraun,
I tested this feature by installing this PR to djangocms-quickstart locally and creating new alias from wizard button, and it seems that it's working correctly.
I don't know what do you mean here go to the edit endpoint of Alias.

Copy link
Member

@fsbraun fsbraun Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you create a page with the wizard, you end up in the edit mode for that page. I would expect the same to happen for the alias: end in edit mode (where you can add plugins) and not in the "settings", i.e. the aliases admin. That would imply a different UX. What do you think? Could this be a topic for a different PR?


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