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
|
* [#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
|
* [#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
|
* [#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
|
### Bug Fixes
|
||||||
|
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button type="button" class="btn btn-sm btn-purple dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<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
|
<i class="mdi mdi-download"></i> Export
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu dropdown-menu-end">
|
<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 }}&{% 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>
|
<li><a class="dropdown-item" href="?{% if url_params %}{{ url_params }}&{% endif %}export">All Data ({{ data_format }})</a></li>
|
||||||
{% if export_templates %}
|
{% if export_templates %}
|
||||||
|
<li>
|
||||||
|
<hr class="dropdown-divider">
|
||||||
|
</li>
|
||||||
|
{% for et in export_templates %}
|
||||||
<li>
|
<li>
|
||||||
<hr class="dropdown-divider">
|
<a class="dropdown-item" href="?{% if url_params %}{{ url_params }}&{% endif %}export={{ et.name }}"
|
||||||
</li>
|
{% if et.description %} title="{{ et.description }}"{% endif %}
|
||||||
{% 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 %}>
|
|
||||||
{{ et.name }}
|
{{ et.name }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if add_exporttemplate_link %}
|
{% if perms.extras.add_exporttemplate %}
|
||||||
<li>
|
<li>
|
||||||
<hr class="dropdown-divider">
|
<hr class="dropdown-divider">
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a class="dropdown-item" href="{{ add_exporttemplate_link }}">Add export template...</a>
|
<a class="dropdown-item" href="{% url 'extras:exporttemplate_add' %}?content_type={{ content_type.pk }}">Add export template...</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -81,19 +81,19 @@ def import_button(url):
|
|||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('buttons/export.html', takes_context=True)
|
@register.inclusion_tag('buttons/export.html', takes_context=True)
|
||||||
def export_button(context, content_type=None):
|
def export_button(context, content_type):
|
||||||
add_exporttemplate_link = None
|
user = context['request'].user
|
||||||
|
|
||||||
if content_type is not None:
|
# Determine if the "all data" export returns CSV or YAML
|
||||||
user = context['request'].user
|
data_format = 'YAML' if hasattr(content_type.model_class(), 'to_yaml') else 'CSV'
|
||||||
export_templates = ExportTemplate.objects.restrict(user, 'view').filter(content_type=content_type)
|
|
||||||
if user.is_staff and user.has_perm('extras.add_exporttemplate'):
|
# Retrieve all export templates for this model
|
||||||
add_exporttemplate_link = f"{reverse('extras:exporttemplate_add')}?content_type={content_type.pk}"
|
export_templates = ExportTemplate.objects.restrict(user, 'view').filter(content_type=content_type)
|
||||||
else:
|
|
||||||
export_templates = []
|
|
||||||
|
|
||||||
return {
|
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,
|
'export_templates': export_templates,
|
||||||
'add_exporttemplate_link': add_exporttemplate_link,
|
'data_format': data_format,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user