From 96dc21019bcc74cf6358d1f484086ad0123087c2 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 9 Mar 2023 12:08:21 +0000 Subject: [PATCH] Add extra button functionality to list and detail views --- .../templates/mixins/window-content/object.html | 17 +++++++++++++++++ .../mixins/window-content/objects.html | 17 +++++++++++++++++ mixins/views.py | 9 +++++++++ 3 files changed, 43 insertions(+) diff --git a/mixins/templates/mixins/window-content/object.html b/mixins/templates/mixins/window-content/object.html index 06eedc4..b694bfa 100644 --- a/mixins/templates/mixins/window-content/object.html +++ b/mixins/templates/mixins/window-content/object.html @@ -39,6 +39,23 @@ {% endif %} + {% for button in extra_buttons %} + + {% endfor %} {% include detail_template %} diff --git a/mixins/templates/mixins/window-content/objects.html b/mixins/templates/mixins/window-content/objects.html index 5313ec4..df10af2 100644 --- a/mixins/templates/mixins/window-content/objects.html +++ b/mixins/templates/mixins/window-content/objects.html @@ -39,6 +39,23 @@ {% endif %} + {% for button in extra_buttons %} + + {% endfor %} {% include list_template %} diff --git a/mixins/views.py b/mixins/views.py index fc6426e..535c341 100644 --- a/mixins/views.py +++ b/mixins/views.py @@ -50,6 +50,8 @@ class ObjectList(RestrictedViewMixin, ObjectNameMixin, ListView): delete_all_url_name = None widget_options = None + extra_buttons = None + def queryset_mutate(self, queryset): pass @@ -130,6 +132,8 @@ class ObjectList(RestrictedViewMixin, ObjectNameMixin, ListView): context["delete_all_url"] = reverse(self.delete_all_url_name) if self.widget_options: context["widget_options"] = self.widget_options + if self.extra_buttons is not None: + context["extra_buttons"] = self.extra_buttons # Return partials for HTMX if self.request.htmx: @@ -261,6 +265,8 @@ class ObjectRead(RestrictedViewMixin, ObjectNameMixin, DetailView): request = None + extra_buttons = None + def get(self, request, *args, **kwargs): type = kwargs.get("type", None) if not type: @@ -306,6 +312,9 @@ class ObjectRead(RestrictedViewMixin, ObjectNameMixin, DetailView): self.detail_url_name, kwargs=detail_url_args ) + if self.extra_buttons is not None: + context["extra_buttons"] = self.extra_buttons + # Return partials for HTMX if self.request.htmx: if request.headers["HX-Target"] == self.context_object_name + "-info":