From ee4218c901644778e162da7d12f16c2fc98cf401 Mon Sep 17 00:00:00 2001 From: shagi Date: Tue, 5 Jan 2021 16:16:54 +0100 Subject: [PATCH] Allow actions in every view --- gas/templates/gas/base.html | 14 ++++++++++++++ gas/templates/gas/base_form.html | 8 +++++--- gas/templates/gas/base_list.html | 10 ---------- gas/views.py | 10 +++++----- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/gas/templates/gas/base.html b/gas/templates/gas/base.html index 443ce1c..bfa13e7 100644 --- a/gas/templates/gas/base.html +++ b/gas/templates/gas/base.html @@ -74,6 +74,20 @@ {% endif %} {% endblock %} + {% block actions %} + {% if actions %} + + {% endif %} + {% endblock %} + {% block content %} {% endblock %} diff --git a/gas/templates/gas/base_form.html b/gas/templates/gas/base_form.html index abb2980..9751b5c 100644 --- a/gas/templates/gas/base_form.html +++ b/gas/templates/gas/base_form.html @@ -15,8 +15,10 @@ {% endfor %} {% endblock %} + {% block extra_form %}{% endblock %} + {% endblock %} diff --git a/gas/templates/gas/base_list.html b/gas/templates/gas/base_list.html index 4e1a1b3..1f0770d 100644 --- a/gas/templates/gas/base_list.html +++ b/gas/templates/gas/base_list.html @@ -4,16 +4,6 @@ {% load form_tags %} {% block content %} - {% block actions %} - {% if actions %} - - {% endif %} - {% endblock %} - {% block filter_form %} {% if filter_form %}
diff --git a/gas/views.py b/gas/views.py index 3108592..837e948 100644 --- a/gas/views.py +++ b/gas/views.py @@ -44,6 +44,7 @@ class GASMixin: help_text = '' success_message = _("Operation successful.") breadcrumbs = [] + actions = None def dispatch(self, *args, **kwargs): user = self.request.user @@ -93,6 +94,9 @@ class GASMixin: " Returns a list of (url, label) tuples for the breadcrumbs " return self.breadcrumbs + def get_actions(self): + return self.actions or [] + def get_context_data(self, **kwargs): ctx = super().get_context_data(**kwargs) ctx.update({ @@ -101,6 +105,7 @@ class GASMixin: 'title': self.get_title(), 'help_text': self.get_help_text(), 'breadcrumbs': self.get_breadcrumbs(), + 'actions': self.get_actions(), 'gas_title': gas_settings.TITLE, 'logo_static_url': gas_settings.LOGO, 'css': gas_settings.MEDIA['css'], @@ -112,7 +117,6 @@ class GASMixin: class GASListView(GASMixin, ListView): """ ListView, permite indicar un formulario para filtrar contenido. """ filter_form_class = None - actions = None def get_filter_form(self): if self.filter_form_class is None: @@ -131,14 +135,10 @@ class GASListView(GASMixin, ListView): qs = super().get_queryset() return self.filter_queryset(qs) - def get_actions(self): - return self.actions or [] - def get_context_data(self, **kwargs): ctx = super().get_context_data(**kwargs) ctx.update({ 'filter_form': self.filter_form, - 'actions': self.get_actions(), }) return ctx