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

Pass the request object in the get_table_kwargs of the SingleTableMixin #966

Open
KommuSoft opened this issue Oct 8, 2024 · 0 comments
Open

Comments

@KommuSoft
Copy link

KommuSoft commented Oct 8, 2024

The get_table_kwargs() method allows to pass parameters when constructing a table instance:

def get_table_kwargs(self):
"""
Return the keyword arguments for instantiating the table.
Allows passing customized arguments to the table constructor, for example,
to remove the buttons column, you could define this method in your View::
def get_table_kwargs(self):
return {
'exclude': ('buttons', )
}
"""
return {}

and a Table can work with a request parameter:

def __init__(
self,
data=None,
order_by=None,
orderable=None,
empty_text=None,
exclude=None,
attrs=None,
row_attrs=None,
pinned_row_attrs=None,
sequence=None,
prefix=None,
order_by_field=None,
page_field=None,
per_page_field=None,
template_name=None,
default=None,
request=None,
show_header=None,
show_footer=True,
extra_columns=None,
):

It thus looks straightforward to pass the request, by default, to the Table such that the table can implement logic based on that request.

While the RequestConfig also injects the request object into the Table, that means it is not available at the time the __init__ function is called on the table, and people might try to generate a table without the RequestConfig.

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

No branches or pull requests

1 participant