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

Separate table class definition and instantiation in MultiTableMixin #876

Closed
wants to merge 0 commits into from

Conversation

gb119
Copy link

@gb119 gb119 commented Dec 3, 2022

This adds a get_tables_classes() method to MultiTableMixin that is called from get_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 for SingleTableMixin.

Also added a test to test the new method.

fixes: #875

Copy link
Owner

@jieter jieter left a 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?

Comment on lines 197 to 201
raise ImproperlyConfigured(
"You must either specify {0}.tables or override {0}.get_tables_classes()".format(
type(self).__name__
)
)
Copy link
Owner

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:

Suggested change
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()"
)


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))
Copy link
Owner

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?

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

def get_tables_classes(self):
Copy link
Owner

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.

@jieter jieter changed the title Separate table class definition and instantiation in MultiTableMixin (issue #875) Separate table class definition and instantiation in MultiTableMixin Dec 26, 2022
@gb119 gb119 closed this Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Differences between SingleTableMixin and MultiTableMixin?
2 participants