Allow actions in every view
This commit is contained in:
parent
8ae1df31d7
commit
ee4218c901
|
@ -74,6 +74,20 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block actions %}
|
||||||
|
{% if actions %}
|
||||||
|
<ul class="actions">
|
||||||
|
{% for target_url, icon, label in actions %}
|
||||||
|
{% if icon %}
|
||||||
|
<li><a href="{{ target_url }}"><i class="fas {{ icon }}" title="{{ label }}"></i></a></li>
|
||||||
|
{% else %}
|
||||||
|
<li><a href="{{ target_url }}">{{ label }}</a></li>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,8 +15,10 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_form %}{% endblock %}
|
||||||
|
|
||||||
<ul class="actions">
|
<ul class="actions">
|
||||||
{% block actions %}
|
{% block form_actions %}
|
||||||
{% if not is_popup %}
|
{% if not is_popup %}
|
||||||
<li><a href="{{ view.get_success_url }}">{% trans "Cancel" %}</a></li>
|
<li><a href="{{ view.get_success_url }}">{% trans "Cancel" %}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -26,8 +28,8 @@
|
||||||
{% if not is_popup %}
|
{% if not is_popup %}
|
||||||
<li><button name="save_and_continue" type="submit">{% trans "Save and continue" %}</button>
|
<li><button name="save_and_continue" type="submit">{% trans "Save and continue" %}</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% block extra_actions %}{% endblock %}
|
{% block extra_form_actions %}{% endblock %}
|
||||||
{% endblock actions %}
|
{% endblock form_actions %}
|
||||||
</ul>
|
</ul>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -4,16 +4,6 @@
|
||||||
{% load form_tags %}
|
{% load form_tags %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% block actions %}
|
|
||||||
{% if actions %}
|
|
||||||
<ul class="actions">
|
|
||||||
{% for target_url, icon, label in actions %}
|
|
||||||
<li><a href="{{ target_url }}"><i class="fas {{ icon }}" title="{{ label }}"></i></a></li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block filter_form %}
|
{% block filter_form %}
|
||||||
{% if filter_form %}
|
{% if filter_form %}
|
||||||
<form class="filter-form form-inline" action="." method="GET">
|
<form class="filter-form form-inline" action="." method="GET">
|
||||||
|
|
10
gas/views.py
10
gas/views.py
|
@ -44,6 +44,7 @@ class GASMixin:
|
||||||
help_text = ''
|
help_text = ''
|
||||||
success_message = _("Operation successful.")
|
success_message = _("Operation successful.")
|
||||||
breadcrumbs = []
|
breadcrumbs = []
|
||||||
|
actions = None
|
||||||
|
|
||||||
def dispatch(self, *args, **kwargs):
|
def dispatch(self, *args, **kwargs):
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
|
@ -93,6 +94,9 @@ class GASMixin:
|
||||||
" Returns a list of (url, label) tuples for the breadcrumbs "
|
" Returns a list of (url, label) tuples for the breadcrumbs "
|
||||||
return self.breadcrumbs
|
return self.breadcrumbs
|
||||||
|
|
||||||
|
def get_actions(self):
|
||||||
|
return self.actions or []
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
ctx = super().get_context_data(**kwargs)
|
||||||
ctx.update({
|
ctx.update({
|
||||||
|
@ -101,6 +105,7 @@ class GASMixin:
|
||||||
'title': self.get_title(),
|
'title': self.get_title(),
|
||||||
'help_text': self.get_help_text(),
|
'help_text': self.get_help_text(),
|
||||||
'breadcrumbs': self.get_breadcrumbs(),
|
'breadcrumbs': self.get_breadcrumbs(),
|
||||||
|
'actions': self.get_actions(),
|
||||||
'gas_title': gas_settings.TITLE,
|
'gas_title': gas_settings.TITLE,
|
||||||
'logo_static_url': gas_settings.LOGO,
|
'logo_static_url': gas_settings.LOGO,
|
||||||
'css': gas_settings.MEDIA['css'],
|
'css': gas_settings.MEDIA['css'],
|
||||||
|
@ -112,7 +117,6 @@ class GASMixin:
|
||||||
class GASListView(GASMixin, ListView):
|
class GASListView(GASMixin, ListView):
|
||||||
""" ListView, permite indicar un formulario para filtrar contenido. """
|
""" ListView, permite indicar un formulario para filtrar contenido. """
|
||||||
filter_form_class = None
|
filter_form_class = None
|
||||||
actions = None
|
|
||||||
|
|
||||||
def get_filter_form(self):
|
def get_filter_form(self):
|
||||||
if self.filter_form_class is None:
|
if self.filter_form_class is None:
|
||||||
|
@ -131,14 +135,10 @@ class GASListView(GASMixin, ListView):
|
||||||
qs = super().get_queryset()
|
qs = super().get_queryset()
|
||||||
return self.filter_queryset(qs)
|
return self.filter_queryset(qs)
|
||||||
|
|
||||||
def get_actions(self):
|
|
||||||
return self.actions or []
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
ctx = super().get_context_data(**kwargs)
|
||||||
ctx.update({
|
ctx.update({
|
||||||
'filter_form': self.filter_form,
|
'filter_form': self.filter_form,
|
||||||
'actions': self.get_actions(),
|
|
||||||
})
|
})
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue