From 76445bd19c0958d96ef70159c4c9d345281b8c45 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 10 Mar 2022 16:27:53 -0500 Subject: [PATCH] Move bulk edit/delete buttons to template tags --- netbox/templates/generic/object_list.html | 16 +++-------- .../templates/buttons/bulk_delete.html | 5 ++++ .../templates/buttons/bulk_edit.html | 5 ++++ netbox/utilities/templatetags/buttons.py | 28 +++++++++++++++++++ 4 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 netbox/utilities/templates/buttons/bulk_delete.html create mode 100644 netbox/utilities/templates/buttons/bulk_edit.html diff --git a/netbox/templates/generic/object_list.html b/netbox/templates/generic/object_list.html index f180004ed..1e2ae796f 100644 --- a/netbox/templates/generic/object_list.html +++ b/netbox/templates/generic/object_list.html @@ -75,14 +75,10 @@ Context:
{% if 'bulk_edit' in actions %} - + {% bulk_edit_button model query_params=request.GET %} {% endif %} {% if 'bulk_delete' in actions %} - + {% bulk_delete_button model query_params=request.GET %} {% endif %}
@@ -115,14 +111,10 @@ Context:
{% block bulk_buttons %} {% if 'bulk_edit' in actions %} - + {% bulk_edit_button model query_params=request.GET %} {% endif %} {% if 'bulk_delete' in actions %} - + {% bulk_delete_button model query_params=request.GET %} {% endif %} {% endblock %}
diff --git a/netbox/utilities/templates/buttons/bulk_delete.html b/netbox/utilities/templates/buttons/bulk_delete.html new file mode 100644 index 000000000..55e477743 --- /dev/null +++ b/netbox/utilities/templates/buttons/bulk_delete.html @@ -0,0 +1,5 @@ +{% if url %} + +{% endif %} diff --git a/netbox/utilities/templates/buttons/bulk_edit.html b/netbox/utilities/templates/buttons/bulk_edit.html new file mode 100644 index 000000000..cdac49b46 --- /dev/null +++ b/netbox/utilities/templates/buttons/bulk_edit.html @@ -0,0 +1,5 @@ +{% if url %} + +{% endif %} diff --git a/netbox/utilities/templatetags/buttons.py b/netbox/utilities/templatetags/buttons.py index a7a8cbfa9..4b8178405 100644 --- a/netbox/utilities/templatetags/buttons.py +++ b/netbox/utilities/templatetags/buttons.py @@ -92,3 +92,31 @@ def export_button(context, model): 'export_templates': export_templates, 'data_format': data_format, } + + +@register.inclusion_tag('buttons/bulk_edit.html') +def bulk_edit_button(model, action='bulk_edit', query_params=None): + try: + url = reverse(get_viewname(model, action)) + if query_params: + url = f'{url}?{query_params.urlencode()}' + except NoReverseMatch: + url = None + + return { + 'url': url, + } + + +@register.inclusion_tag('buttons/bulk_delete.html') +def bulk_delete_button(model, action='bulk_delete', query_params=None): + try: + url = reverse(get_viewname(model, action)) + if query_params: + url = f'{url}?{query_params.urlencode()}' + except NoReverseMatch: + url = None + + return { + 'url': url, + }