Skip to content

Commit

Permalink
Remove MultiTableMixin models attribute - not allowing tests to work.…
Browse files Browse the repository at this point in the history
… Add new test for MultiTableMixin.get_tables_classes
  • Loading branch information
gb119 committed Dec 3, 2022
1 parent 42fe084 commit 43323e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
20 changes: 7 additions & 13 deletions django_tables2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class MultiTableMixin(TableMixinBase):
"""

tables = None
models = None
tables_data = None

table_prefix = "table_{}-"
Expand All @@ -194,19 +193,14 @@ def get_tables_classes(self):
"""
Return the list of classes to use for the tables.
"""
if self.tables is None and self.models is None:
klass = type(self).__name__
raise ImproperlyConfigured("No tables were specified. Define {}.tables".format(klass))

if self.tables:
return self.tables

if self.models:
return [tables.table_factory(self.model) for model in self.models]
if self.tables is None:
raise ImproperlyConfigured(
"You must either specify {0}.tables or override {0}.get_tables_classes()".format(
type(self).__name__
)
)

raise ImproperlyConfigured(
"You must either specify {0}.tables or {0}.models".format(type(self).__name__)
)
return self.tables

def get_tables(self, **kwargs):
"""
Expand Down
15 changes: 14 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,20 @@ def test_with_empty_get_tables_list(self):
class View(tables.MultiTableMixin, TemplateView):
template_name = "multiple.html"

def get_tables(self):
def get_tables(self, **kwargs):
return []

response = View.as_view()(build_request("/"))
response.render()

html = response.rendered_content
self.assertIn("<h1>Multiple tables using MultiTableMixin</h1>", html)

def test_with_empty_get_tables_clases_list(self):
class View(tables.MultiTableMixin, TemplateView):
template_name = "multiple.html"

def get_tables_classes(self):
return []

response = View.as_view()(build_request("/"))
Expand Down

0 comments on commit 43323e8

Please sign in to comment.