Skip to content

Split view in mixin #3

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion django_tables2_simplefilter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

from .views import FilteredSingleTableView, F
from .views import FilteredSingleTableView, FilteredSingleTableMixin, F

9 changes: 6 additions & 3 deletions django_tables2_simplefilter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def F(field, verbose_name, values_list):
return dict(field=field, verbose_name=verbose_name, values_list=values_list)


class FilteredSingleTableView(SingleTableView):
class FilteredSingleTableMixin(object):
"""
Add filtering options to SingleTableView. Define list of filters in the Table
subclass (not in Table.Meta). Likely not secure.
Expand All @@ -35,7 +35,7 @@ class MyTable(tables.Table):
"""

def get_queryset(self):
q = super(FilteredSingleTableView, self).get_queryset()
q = super(FilteredSingleTableMixin, self).get_queryset()
if hasattr(self.table_class, 'filters'):
h = {}
for f in self.table_class.filters:
Expand All @@ -46,7 +46,7 @@ def get_queryset(self):
return q

def get_context_data(self, **kwargs):
c = super(FilteredSingleTableView, self).get_context_data(**kwargs)
c = super(FilteredSingleTableMixin, self).get_context_data(**kwargs)
if hasattr(self.table_class, 'filters'):
h = []
for f in self.table_class.filters:
Expand All @@ -72,3 +72,6 @@ def get_context_data(self, **kwargs):
c['filters']['base_params'] = base_param_values
return c


class FilteredSingleTableView(FilteredSingleTableMixin, SingleTableView):
pass