Skip to content

Commit

Permalink
Add a get_columns method to change column list dynamically.
Browse files Browse the repository at this point in the history
  • Loading branch information
submarcos committed May 21, 2024
1 parent 0a2e826 commit 8b2cc1c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ CHANGELOG
8.8.1+dev (XXXX-XX-XX)
-----------------------

**Improvements**

- Add a get_columns method to change column list dynamically.


8.8.1 (2024-05-07)
-------------------
Expand Down
3 changes: 3 additions & 0 deletions mapentity/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def __init__(self, *args, **kwargs):
self.columns.remove('id')
self.columns.insert(0, 'id')

def get_columns(self):
return self.columns

@view_permission_required()
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
Expand Down
6 changes: 3 additions & 3 deletions mapentity/views/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def dispatch(self, request, *args, **kwargs):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['filterform'] = self._filterform # From FilterListMixin
context['columns'] = self.columns # From BaseListView
context['columns'] = self.get_columns() # From BaseListView
context['unorderable_columns'] = self.unorderable_columns # From BaseListView
context['searchable_columns'] = self.searchable_columns # From BaseListView
context['create_label'] = self.get_model().get_create_label()
Expand Down Expand Up @@ -131,14 +131,14 @@ def csv_view(self, request, context, **kwargs):
serializer = mapentity_serializers.CSVSerializer()
response = HttpResponse(content_type='text/csv')
serializer.serialize(queryset=self.get_queryset(), stream=response,
model=self.get_model(), fields=self.columns, ensure_ascii=True)
model=self.get_model(), fields=self.get_columns(), ensure_ascii=True)
return response

def shape_view(self, request, context, **kwargs):
serializer = mapentity_serializers.ZipShapeSerializer()
response = HttpResponse(content_type='application/zip')
serializer.serialize(queryset=self.get_queryset(), model=self.get_model(),
stream=response, fields=self.columns)
stream=response, fields=self.get_columns())
response['Content-length'] = str(len(response.content))
return response

Expand Down

0 comments on commit 8b2cc1c

Please sign in to comment.