|
1 | | -from django.shortcuts import render |
2 | 1 | import django_filters.rest_framework |
3 | 2 | from rest_framework.generics import ListAPIView, RetrieveAPIView |
4 | 3 | from rest_framework.permissions import IsAuthenticatedOrReadOnly |
5 | 4 | from rest_framework_gis.pagination import GeoJsonPagination |
6 | 5 | from rest_framework_gis.filters import InBBoxFilter |
| 6 | +from drf_excel.mixins import XLSXFileMixin |
| 7 | +from drf_excel.renderers import XLSXRenderer |
| 8 | + |
7 | 9 |
|
8 | 10 | from vbos.datasets.filters import ( |
9 | 11 | RasterDatasetFilter, |
@@ -122,12 +124,16 @@ class TabularDatasetDetailView(RetrieveAPIView): |
122 | 124 | class TabularDatasetDataView(ListAPIView): |
123 | 125 | filterset_class = TabularItemFilter |
124 | 126 | permission_classes = [IsAuthenticatedOrReadOnly] |
| 127 | + serializer_class = TabularItemSerializer |
125 | 128 |
|
126 | 129 | def get_queryset(self): |
127 | 130 | return TabularItem.objects.filter(dataset=self.kwargs.get("pk")) |
128 | 131 |
|
129 | | - def get_serializer_class(self): |
130 | | - # Use different serializer for Excel format |
131 | | - if self.request.query_params.get("format") == "xlsx": |
132 | | - return TabularItemExcelSerializer |
133 | | - return TabularItemSerializer |
| 132 | + |
| 133 | +class TabularDatasetXSLXDataView(XLSXFileMixin, TabularDatasetDataView): |
| 134 | + serializer_class = TabularItemExcelSerializer |
| 135 | + renderer_classes = (XLSXRenderer,) |
| 136 | + pagination_class = None |
| 137 | + |
| 138 | + def get_filename(self, request, *args, **kwargs): |
| 139 | + return f"vbos-mis-tabular-{kwargs.get('pk')}.xlsx" |
0 commit comments