mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #8530: Indicate CSV or YAML as format for "all data" export
This commit is contained in:
@ -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
|
||||
|
||||
|
@ -1,31 +1,31 @@
|
||||
<div class="dropdown">
|
||||
<button type="button" class="btn btn-sm btn-purple dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="mdi mdi-download"></i> Export
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
<li><a class="dropdown-item" href="?{% if url_params %}{{ url_params.urlencode }}&{% endif %}export=table">Current View</a></li>
|
||||
<li><a class="dropdown-item" href="?{% if url_params %}{{ url_params.urlencode }}&{% endif %}export">All Data</a></li>
|
||||
{% if export_templates %}
|
||||
<button type="button" class="btn btn-sm btn-purple dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="mdi mdi-download"></i> Export
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
<li><a class="dropdown-item" href="?{% if url_params %}{{ url_params }}&{% endif %}export=table">Current View</a></li>
|
||||
<li><a class="dropdown-item" href="?{% if url_params %}{{ url_params }}&{% endif %}export">All Data ({{ data_format }})</a></li>
|
||||
{% if export_templates %}
|
||||
<li>
|
||||
<hr class="dropdown-divider">
|
||||
</li>
|
||||
{% for et in export_templates %}
|
||||
<li>
|
||||
<hr class="dropdown-divider">
|
||||
</li>
|
||||
{% for et in export_templates %}
|
||||
<li>
|
||||
<a class="dropdown-item"
|
||||
href="?{% if url_params %}{{ url_params.urlencode }}&{% endif %}export={{ et.name }}"{% if et.description %}
|
||||
title="{{ et.description }}"{% endif %}>
|
||||
<a class="dropdown-item" href="?{% if url_params %}{{ url_params }}&{% endif %}export={{ et.name }}"
|
||||
{% if et.description %} title="{{ et.description }}"{% endif %}
|
||||
>
|
||||
{{ et.name }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if add_exporttemplate_link %}
|
||||
<li>
|
||||
<hr class="dropdown-divider">
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ add_exporttemplate_link }}">Add export template...</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if perms.extras.add_exporttemplate %}
|
||||
<li>
|
||||
<hr class="dropdown-divider">
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{% url 'extras:exporttemplate_add' %}?content_type={{ content_type.pk }}">Add export template...</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -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,
|
||||
}
|
||||
|
Reference in New Issue
Block a user