-
Notifications
You must be signed in to change notification settings - Fork 427
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
Separate table class definition and instantiation in MultiTableMixin
#876
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR, I added some comments, can you have a look?
django_tables2/views.py
Outdated
raise ImproperlyConfigured( | ||
"You must either specify {0}.tables or override {0}.get_tables_classes()".format( | ||
type(self).__name__ | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the currently supported python versions, we can use fstrings:
raise ImproperlyConfigured( | |
"You must either specify {0}.tables or override {0}.get_tables_classes()".format( | |
type(self).__name__ | |
) | |
) | |
view = type(self).__name__ | |
raise ImproperlyConfigured( | |
f"You must either specify {view}.tables or override {view}.get_tables_classes()" | |
) |
django_tables2/views.py
Outdated
|
||
if len(data) != len(self.tables): | ||
if len(data) != len(tables): | ||
klass = type(self).__name__ | ||
raise ImproperlyConfigured("len({}.tables_data) != len({}.tables)".format(klass, klass)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also apply the fstring form to this error message?
tests/test_views.py
Outdated
class View(tables.MultiTableMixin, TemplateView): | ||
template_name = "multiple.html" | ||
|
||
def get_tables_classes(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is implicit in checking the get_tables_classes
method is called. I think it would be an improvement if we somehow make it explicit, either by returning something we check, or checking if the method is indeed called.
MultiTableMixin
This adds a
get_tables_classes()
method toMultiTableMixin
that is called fromget_tables()
in place of always referring to the tables attribute - this makes it easier to define multiple dynamics custom table table classes in the view - like one can forSingleTableMixin
.Also added a test to test the new method.
fixes: #875