Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a get_columns method to change column list dynamically. #300

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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