From 41b400aa608cf493ea4e44f8074ac0d0d7a159c4 Mon Sep 17 00:00:00 2001 From: abidibo Date: Thu, 30 May 2024 10:38:55 +0200 Subject: [PATCH 1/2] feat: add rebuild command in admin --- README.rst | 9 +++++++++ docs/usage.rst | 8 ++++++++ lineup/admin.py | 1 + .../admin/lineup/menuitem/change_list.html | 13 +++++++++++++ lineup/urls.py | 8 ++++++++ lineup/views.py | 10 +++++++++- 6 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 lineup/templates/admin/lineup/menuitem/change_list.html create mode 100644 lineup/urls.py diff --git a/README.rst b/README.rst index 7c490f7..e0cd584 100644 --- a/README.rst +++ b/README.rst @@ -39,6 +39,14 @@ Add it to your `INSTALLED_APPS`: ... ) +Add to your main `urls.py`: + +.. code-block:: python + + ... + path("lineup/", include("lineup.urls", namespace="lineup")), + ... + Make sure the ``requests`` context processor is included (it is by default): .. code-block:: python @@ -134,6 +142,7 @@ Features - Render menu tree templatetags - Breadcrumbs templetetag - Import a menu from json management command +- Rebuild tree button in admin - `Django Baton `_ integration to highlight different menu in the admin Running Tests diff --git a/docs/usage.rst b/docs/usage.rst index 78b964a..37e850c 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -12,6 +12,14 @@ To use Django Lineup in a project, add it to your `INSTALLED_APPS`: ... ) +Add to your main `urls.py`: + +.. code-block:: python + + ... + path("lineup/", include("lineup.urls", namespace="lineup")), + ... + Be sure the ``requests`` context processor is included (it is by default): .. code-block:: python diff --git a/lineup/admin.py b/lineup/admin.py index 7a9325f..35b282d 100644 --- a/lineup/admin.py +++ b/lineup/admin.py @@ -26,6 +26,7 @@ class MenuItemInline(admin.StackedInline): @admin.register(MenuItem) class MenuItemAdmin(MPTTModelAdmin): + change_list_template = "admin/lineup/menuitem/change_list.html" list_display = ('slug', 'label', 'parent', 'link', 'order', 'login_required', 'enabled', ) list_filter = (('parent', RelatedDropdownFilter, ) if baton else 'parent', 'enabled', 'login_required', ) list_editable = ('order', ) diff --git a/lineup/templates/admin/lineup/menuitem/change_list.html b/lineup/templates/admin/lineup/menuitem/change_list.html new file mode 100644 index 0000000..8a72145 --- /dev/null +++ b/lineup/templates/admin/lineup/menuitem/change_list.html @@ -0,0 +1,13 @@ +{% extends "admin/change_list.html" %} +{% load admin_list i18n mptt_admin %} + +{% block result_list %} + {% if action_form and actions_on_top and cl.show_admin_actions %}{% admin_actions %}{% endif %} + {% mptt_result_list cl %} + {% if action_form and actions_on_bottom and cl.show_admin_actions %}{% admin_actions %}{% endif %} +{% endblock %} + +{% block object-tools-items %} +
  • {% trans "Rebuild" %}
  • + {{ block.super }} +{% endblock %} diff --git a/lineup/urls.py b/lineup/urls.py new file mode 100644 index 0000000..cb60b21 --- /dev/null +++ b/lineup/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from . import views + +app_name = "lineup" +urlpatterns = [ + path("", views.RebuildTreeView.as_view(), name="rebuild"), +] diff --git a/lineup/views.py b/lineup/views.py index 40a96af..6f3f83b 100644 --- a/lineup/views.py +++ b/lineup/views.py @@ -1 +1,9 @@ -# -*- coding: utf-8 -*- +from django.urls import reverse +from django.views.generic import View +from django.shortcuts import redirect +from .models import MenuItem + +class RebuildTreeView(View): + def get(self, request): + MenuItem.objects.rebuild() + return redirect(reverse('admin:lineup_menuitem_changelist')) From cf0d873cf18002a12af1e5efe4d361fbc0721c60 Mon Sep 17 00:00:00 2001 From: abidibo Date: Thu, 30 May 2024 10:40:29 +0200 Subject: [PATCH 2/2] build: bump version number to 0.3.2 --- HISTORY.rst | 5 +++++ docs/conf.py | 4 ++-- lineup/__init__.py | 2 +- setup.cfg | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 7c46f0c..c10250d 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,11 @@ History ------- +0.3.2 (2024-05-30) +++++++++++++++++++ + +* Adds rebuild command in admin + 0.3.1 (2022-12-22) ++++++++++++++++++ diff --git a/docs/conf.py b/docs/conf.py index d4172aa..88875bf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -54,9 +54,9 @@ # built documents. # # The short X.Y version. -version = u'0.3.1' +version = u'0.3.2' # The full version, including alpha/beta/rc tags. -release = u'0.3.1' +release = u'0.3.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/lineup/__init__.py b/lineup/__init__.py index e1424ed..73e3bb4 100644 --- a/lineup/__init__.py +++ b/lineup/__init__.py @@ -1 +1 @@ -__version__ = '0.3.1' +__version__ = '0.3.2' diff --git a/setup.cfg b/setup.cfg index cbbbedf..e9e4948 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,12 +1,12 @@ [bumpversion] -current_version = 0.3.1 +current_version = 0.3.2 [wheel] universal = 1 [flake8] ignore = D203 -exclude = +exclude = lineup/migrations, .git, .tox,