Skip to content

Commit

Permalink
Merge pull request #300 from makinacorpus/dynamic_columns
Browse files Browse the repository at this point in the history
Add a get_columns method to change column list dynamically.
  • Loading branch information
submarcos committed May 21, 2024
2 parents 0a2e826 + 78341b1 commit c5c019e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
schedule:
- cron: '0 2 * * *'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
Expand Down
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
1 change: 1 addition & 0 deletions test_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
'mapentity.middleware.AutoLoginMiddleware',
)


ROOT_URLCONF = 'test_project.urls'

TEMPLATES = [
Expand Down

0 comments on commit c5c019e

Please sign in to comment.