Skip to content

Commit

Permalink
feat(generic): add export support to list views
Browse files Browse the repository at this point in the history
  • Loading branch information
gythaogg committed Jan 28, 2025
1 parent 0e18700 commit 0840c5e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apis_core/generic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from django_tables2 import SingleTableMixin
from django_tables2.columns import library
from django_tables2.tables import table_factory
from django_tables2.export.views import ExportMixin

from datetime import datetime

from apis_core.apis_metainfo.models import Uri
from apis_core.utils.helpers import create_object_from_uri, get_importer_for_model
Expand Down Expand Up @@ -100,6 +103,7 @@ def get_permission_required(self):
class List(
GenericModelMixin,
PermissionRequiredMixin,
ExportMixin,
SingleTableMixin,
FilterView,
):
Expand All @@ -123,6 +127,11 @@ def get_table_class(self):
table_class = first_member_match(table_modules, GenericTable)
return table_factory(self.model, table_class)

def get_export_filename(self, extension):
now = datetime.now()
filename = f"{self.get_table_class().__name__}_{now.strftime('%Y-%m-%d_%H-%M-%S')}.{extension}"
return filename

def get_table_kwargs(self):
kwargs = super().get_table_kwargs()

Expand Down

0 comments on commit 0840c5e

Please sign in to comment.