10000 Merge back release candidate 4.1.0rc3 into develop-4 by fsbraun · Pull Request #7573 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Merge back release candidate 4.1.0rc3 into develop-4 #7573

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

Merged
merged 13 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: empty actions shown without unwanted spaces (#7545) (#7552)
* Fix empty actions

* Add tests

* Fix tests
  • Loading branch information
fsbraun authored May 10, 2023
commit aee76b492d8a96daf140dfe109fd1864ed26aae8
9 changes: 5 additions & 4 deletions cms/admin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class Media:
)
css = {"all": (static_with_version("cms/css/cms.admin.css"),)}

EMPTY_ACTION = mark_safe('<span class="cms-empty-action"></span>')

def get_actions_list(
self,
) -> typing.List[typing.Callable[[models.Model, HttpRequest], str]]:
Expand Down Expand Up @@ -77,12 +79,11 @@ class MyModelAdmin(AdminActionsMixin, admin.ModelAdmin):

def list_actions(obj: models.Model) -> str:
"""The name of this inner function must not change. css styling and js depends on it."""
EMPTY = mark_safe('<span class="cms-empty-action"></span>')
return format_html_join(
"",
"{}",
(
(action(obj, request) or EMPTY,)
(action(obj, request),)
for action in self.get_actions_list()
),
)
Expand Down Expand Up @@ -147,7 +148,7 @@ def my_custom_button(self, obj, request, disabled=False):
{
"url": url or "",
"icon": icon,
"action": action,
"method": action,
"disabled": disabled,
"keepsideframe": keepsideframe,
"title": title,
Expand Down Expand Up @@ -557,7 +558,7 @@ def _get_view_action(self, obj, request: HttpRequest) -> str:
keepsideframe=False,
name="view",
)
return ""
return self.EMPTY_ACTION

def _get_settings_action(self, obj: models.Model, request: HttpRequest) -> str:
edit_url = admin_reverse(
Expand Down
2 changes: 1 addition & 1 deletion cms/static/cms/js/admin/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.cms-actions-dropdown-menu-item-anchor`)
.on('click', function(e) {
let action = $(e.currentTarget);
let formMethod = action.attr('class').indexOf('cms-form-get-method') !== -1 ? 'GET': 'POST';
let formMethod = action.attr('class').indexOf('cms-form-post-method') !== -1 ? 'POST': 'GET';
let keepSideFrame = action.attr('class').indexOf('js-keep-sideframe') !== -1;

if (formMethod === 'GET') {
Expand Down
2 changes: 1 addition & 1 deletion cms/templates/admin/cms/icons/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% spaceless %}
<a class="btn{% if disabled %} inactive{% endif %}{% if get|default_if_none:True %} cms-form-get-method{% endif %}{% if burger_menu %} cms-burger-action-btn{% endif %} cms-action-btn cms-action-{% block name %}{{ name }}{% endblock %}{% if action|default_if_none:True %} js-action{% endif %} {% if keepsideframe|default_if_none:True %}js-keep-sideframe{% else %}js-close-sideframe{% endif %}"{% if not disabled %} href="{{ url }}"{% endif %} title="{% block title %}{{ title }}{% endblock %}">
<a class="btn{% if disabled %} inactive{% endif %} cms-form-{{ method }}-method{% if burger_menu %} cms-burger-action-btn{% endif %} cms-action-btn{% block name %}{% if name %} cms-action-{{ name }}{% endif %}{% endblock %}{% if action|default_if_none:True %} js-action{% endif %} {% if keepsideframe|default_if_none:True %}js-keep-sideframe{% else %}js-close-sideframe{% endif %}"{% if not disabled %} href="{{ url }}"{% endif %} title="{% block title %}{{ title }}{% endblock %}">
<span class="cms-icon cms-icon-{% block icon %}{{ icon }}{% endblock %}"></span>
</a>
{% endspaceless %}
24 changes: 24 additions & 0 deletions cms/tests/test_grouper_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@ def test_change_action(self):
f'/change/?language=en"')
self.assertContains(response, 'class="cms-icon cms-icon-view"')

def test_get_action(self):
admin = site._registry[GrouperModel]

get_action = admin.admin_action_button(
"/some/url",
icon="info",
title="Info",
action="get",
)
self.assertIn("cms-form-get-method", get_action)
self.assertNotIn("cms-form-post-method", get_action)

def test_post_action(self):
admin = site._registry[GrouperModel]

get_action = admin.admin_action_button(
"/some/url",
icon="bin",
title="Delete",
action="post",
)
self.assertNotIn("cms-form-get-method", get_action)
self.assertIn("cms-form-post-method", get_action)


class GrouperModelAdminTestCase(SetupMixin, CMSTestCase):
def test_form_class_created(self):
Expand Down
0