Skip to content

Commit

Permalink
Add a CMS toolbar item for category and tag list (#729)
Browse files Browse the repository at this point in the history
* Add a CMS toolbar item for category and tag list

With these links, one can manage BlogCategory and Tag, without visiting django admin site.

Co-authored-by: Adrien Delhorme <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 20, 2023
1 parent a6eb725 commit 33e455d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/676.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a CMS toolbar item for category and tag list
7 changes: 7 additions & 0 deletions djangocms_blog/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def populate(self):
with override(self.current_lang):
url = reverse("admin:djangocms_blog_post_changelist")
admin_menu.add_modal_item(_("Post list"), url=url)

url = reverse("admin:djangocms_blog_blogcategory_changelist")
admin_menu.add_modal_item(_("Category list"), url=url)

url = reverse("admin:taggit_tag_changelist")
admin_menu.add_modal_item(_("Tag list"), url=url)

url = reverse("admin:djangocms_blog_post_add")
admin_menu.add_modal_item(_("Add post"), url=url)
current_config = getattr(self.request, get_setting("CURRENT_NAMESPACE"), None)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def test_toolbar_with_items(self):
toolbar.get_left_items()
blog_menu = toolbar.menus["djangocms_blog"]
self.assertEqual(len(blog_menu.find_items(ModalItem, url=reverse("admin:djangocms_blog_post_changelist"))), 1)
self.assertEqual(
len(blog_menu.find_items(ModalItem, url=reverse("admin:djangocms_blog_blogcategory_changelist"))),
1,
)
self.assertEqual(len(blog_menu.find_items(ModalItem, url=reverse("admin:taggit_tag_changelist"))), 1)
self.assertEqual(len(blog_menu.find_items(ModalItem, url=reverse("admin:djangocms_blog_post_add"))), 1)
self.assertEqual(
len(blog_menu.find_items(ModalItem, url=reverse("admin:djangocms_blog_post_change", args=(posts[0].pk,)))),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_post_list_view(self):
self.assertContains(response, context["post_list"][0].get_absolute_url())
blog_menu = request.toolbar.get_or_create_menu("djangocms_blog", _("Blog"))

self.assertEqual(len(blog_menu.items), 3)
self.assertEqual(len(blog_menu.items), 5)
self.assertEqual(
len(blog_menu.find_items(ModalItem, url=reverse("admin:djangocms_blog_post_changelist"))), 1
)
Expand Down

0 comments on commit 33e455d

Please sign in to comment.