Skip to content

Commit

Permalink
Preserve page size selection when changing filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikael-Lenander authored and etanttila committed May 15, 2024
1 parent 45bc34c commit 25554d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion feedback/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ def filter(self, qs, value):
return qs.order_by(value)


class PaginateByFilter(django_filters.filters.Filter):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs, widget=forms.HiddenInput)

def filter(self, queryset, value):
# This filter doesn't modify the queryset (no filtering)
return queryset


class FeedbackFilterForm(forms.Form):
"""Add 00:00 times to timestamp inputs"""
template_name = "manage/filter_form.html"
Expand Down Expand Up @@ -272,7 +281,7 @@ class FeedbackFilter(django_filters.FilterSet):
order_by = OrderingFilter(label=_("Sort"),
choices=ORDER_BY_CHOICE,
initial=ORDER_BY_DEFAULT)

paginate_by = PaginateByFilter()

class Meta:
model = Feedback
Expand Down Expand Up @@ -319,6 +328,7 @@ def form(self):
form.fields['tags'].set_queryset(feedbacktags)
studenttags = StudentTag.objects.filter(course=course).all()
form.fields['student_tags'].set_queryset(studenttags)
form.fields['paginate_by'].initial = self.data.get('paginate_by', None)
return form

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions feedback/templates/manage/filter_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<div id="order-filter-pane">
{% include "manage/_filter_field.html" with field=form.order_by %}
</div>
{% include "manage/_filter_field.html" with field=form.paginate_by hide_label=True %}
{% else %}
<div></div>
{% endif %}
Expand Down

0 comments on commit 25554d3

Please sign in to comment.