Skip to content

Commit

Permalink
move the definition of the filter table in the get context data in or…
Browse files Browse the repository at this point in the history
…der to not trigger an error if errors are present in the form
  • Loading branch information
Yu-jinKim committed Aug 27, 2024
1 parent 22f368a commit 21cd6c2
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions trendyqc/trend_monitoring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ def _get_context_data(self):
# get the default context data (the one key i need is one called tables)
context = super().get_context_data()

# setup the filter table
filter_table = FilterTable(Filter.objects.all())

# so moving the FilterTable away from the class init "breaks" the
# default pagination for the filter table. I reused the code in the
# django-tables2 code (https://github.com/jieter/django-tables2/blob/master/django_tables2/views.py#L235)
# to resetup the pagination
# i have no idea what this code does tbh
table_counter = count()
filter_table.prefix = (
filter_table.prefix or
self.table_prefix.format(next(table_counter))
)
RequestConfig(
self.request, paginate=self.get_table_pagination(filter_table)
).configure(filter_table)

context["tables"].append(filter_table)

# get all the assays and sort them
assays = sorted({
assay
Expand Down Expand Up @@ -132,25 +151,6 @@ def get(self, request):
"""

context = self._get_context_data()

filter_table = FilterTable(Filter.objects.all())

# so moving the FilterTable away from the class init "breaks" the
# default pagination for the filter table. I reused the code in the
# django-tables2 code (https://github.com/jieter/django-tables2/blob/master/django_tables2/views.py#L235)
# to resetup the pagination
# i have no idea what this code does tbh
table_counter = count()
filter_table.prefix = (
filter_table.prefix or
self.table_prefix.format(next(table_counter))
)
RequestConfig(
self.request, paginate=self.get_table_pagination(filter_table)
).configure(filter_table)

context["tables"].append(filter_table)

request.session.pop("form", None)
return render(request, self.template_name, context)

Expand Down

0 comments on commit 21cd6c2

Please sign in to comment.