mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Replace 'default format' export with 'all data'
This commit is contained in:
parent
3ec6194a47
commit
578885225f
@ -16,7 +16,7 @@ from django.utils.safestring import mark_safe
|
||||
from django.views.generic import View
|
||||
from django_tables2.export import TableExport
|
||||
|
||||
from extras.models import CustomField, ExportTemplate
|
||||
from extras.models import ExportTemplate
|
||||
from utilities.error_handlers import handle_protectederror
|
||||
from utilities.exceptions import AbortTransaction
|
||||
from utilities.forms import (
|
||||
@ -24,7 +24,7 @@ from utilities.forms import (
|
||||
)
|
||||
from utilities.permissions import get_permission_for_model
|
||||
from utilities.tables import paginate_table
|
||||
from utilities.utils import csv_format, normalize_querydict, prepare_cloned_fields
|
||||
from utilities.utils import normalize_querydict, prepare_cloned_fields
|
||||
from utilities.views import GetReturnURLMixin, ObjectPermissionRequiredMixin
|
||||
|
||||
|
||||
@ -105,8 +105,7 @@ class ObjectListView(ObjectPermissionRequiredMixin, View):
|
||||
Export all table data in CSV format.
|
||||
|
||||
:param table: The Table instance to export
|
||||
:param columns: A list of specific columns to include. If not specified, the default view
|
||||
will be exported.
|
||||
:param columns: A list of specific columns to include. If not specified, all columns will be exported.
|
||||
"""
|
||||
exclude_columns = {'pk'}
|
||||
if columns:
|
||||
@ -114,10 +113,6 @@ class ObjectListView(ObjectPermissionRequiredMixin, View):
|
||||
exclude_columns.update({
|
||||
col for col in all_columns if col not in columns
|
||||
})
|
||||
else:
|
||||
exclude_columns.update({
|
||||
name for name, _ in table.available_columns
|
||||
})
|
||||
exporter = TableExport(
|
||||
export_format=TableExport.CSV,
|
||||
table=table,
|
||||
@ -171,9 +166,10 @@ class ObjectListView(ObjectPermissionRequiredMixin, View):
|
||||
|
||||
# Handle table-based exports (current view or static CSV-based)
|
||||
if request.GET.get('export') == 'table':
|
||||
return self.export_table(table)
|
||||
columns = [name for name, _ in table.selected_columns]
|
||||
return self.export_table(table, columns)
|
||||
elif 'export' in request.GET:
|
||||
return self.export_table(table, model.csv_headers)
|
||||
return self.export_table(table)
|
||||
|
||||
# Paginate the objects table
|
||||
paginate_table(table, request)
|
||||
|
@ -4,7 +4,7 @@
|
||||
</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">Default Format</a></li>
|
||||
<li><a class="dropdown-item" href="?{% if url_params %}{{ url_params.urlencode }}&{% endif %}export">All Data</a></li>
|
||||
{% if export_templates %}
|
||||
<li>
|
||||
<hr class="dropdown-divider">
|
||||
|
Loading…
Reference in New Issue
Block a user