From 24f48b11e6fb0bbc6b3ba7fbeea361c3a45a558e Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Feb 2022 10:22:38 -0500 Subject: [PATCH] Closes #8530: Indicate CSV or YAML as format for "all data" export --- docs/release-notes/version-3.1.md | 1 + .../utilities/templates/buttons/export.html | 50 +++++++++---------- netbox/utilities/templatetags/buttons.py | 22 ++++---- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 46497bb03..d2d1f4018 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -13,6 +13,7 @@ * [#8476](https://github.com/netbox-community/netbox/issues/8476) - Bring the ASN Web UI up to the standard set by other objects * [#8494](https://github.com/netbox-community/netbox/issues/8494) - Include locations count under tenant view * [#8517](https://github.com/netbox-community/netbox/issues/8517) - Render boolean custom fields as icons in object tables +* [#8530](https://github.com/netbox-community/netbox/issues/8530) - Indicate CSV or YAML as format for "all data" export ### Bug Fixes diff --git a/netbox/utilities/templates/buttons/export.html b/netbox/utilities/templates/buttons/export.html index 20ecc2dff..bb6e4379c 100644 --- a/netbox/utilities/templates/buttons/export.html +++ b/netbox/utilities/templates/buttons/export.html @@ -1,31 +1,31 @@ diff --git a/netbox/utilities/templatetags/buttons.py b/netbox/utilities/templatetags/buttons.py index ecbcb1143..d8b4987ba 100644 --- a/netbox/utilities/templatetags/buttons.py +++ b/netbox/utilities/templatetags/buttons.py @@ -81,19 +81,19 @@ def import_button(url): @register.inclusion_tag('buttons/export.html', takes_context=True) -def export_button(context, content_type=None): - add_exporttemplate_link = None +def export_button(context, content_type): + user = context['request'].user - if content_type is not None: - user = context['request'].user - export_templates = ExportTemplate.objects.restrict(user, 'view').filter(content_type=content_type) - if user.is_staff and user.has_perm('extras.add_exporttemplate'): - add_exporttemplate_link = f"{reverse('extras:exporttemplate_add')}?content_type={content_type.pk}" - else: - export_templates = [] + # Determine if the "all data" export returns CSV or YAML + data_format = 'YAML' if hasattr(content_type.model_class(), 'to_yaml') else 'CSV' + + # Retrieve all export templates for this model + export_templates = ExportTemplate.objects.restrict(user, 'view').filter(content_type=content_type) return { - 'url_params': context['request'].GET, + 'perms': context['perms'], + 'content_type': content_type, + 'url_params': context['request'].GET.urlencode() if context['request'].GET else '', 'export_templates': export_templates, - 'add_exporttemplate_link': add_exporttemplate_link, + 'data_format': data_format, }