diff --git a/intervention/filters.py b/intervention/filters.py index dfef2ac0..5e704a32 100644 --- a/intervention/filters.py +++ b/intervention/filters.py @@ -11,20 +11,26 @@ from django.contrib.auth.models import User from django.db.models import QuerySet, Q from django.utils.translation import gettext_lazy as _ + +from intervention.forms import DummyFilterInput from intervention.models import Intervention class InterventionTableFilter(django_filters.FilterSet): - q = django_filters.Filter( - method='_filter_by_keyword', - widget=forms.HiddenInput(), # use search bar in template, we only need the filter logic in here! - ) sa = django_filters.BooleanFilter( method='_filter_show_all', label=_("Show unshared"), label_suffix=_(""), widget=forms.CheckboxInput() ) + q = django_filters.Filter( + method='_filter_by_keyword', + # Since we use a custom search bar in the template, we need to 'render' this filter + # as 'anonymous' HiddenInput (no id, no name). This way our custom search bar's id and name won't be + # overwritten with these id and name (which would be equal) + # This way we can use the simple filter method mapping for a parameter without using a predefined widget! + widget=DummyFilterInput(), + ) sr = django_filters.BooleanFilter( method='_filter_show_recorded', label=_("Show recorded"), diff --git a/intervention/forms.py b/intervention/forms.py index aa663cf0..98bfb7ff 100644 --- a/intervention/forms.py +++ b/intervention/forms.py @@ -218,3 +218,13 @@ class OpenInterventionForm(EditInterventionForm): # Disable all form fields for field in self.fields: self.disable_form_field(field) + + +class DummyFilterInput(forms.HiddenInput): + """ A dummy input widget + + Does not render anything. Can be used to keep filter logic using django_filter without having a pre defined + filter widget being rendered to the template. + + """ + template_name = "intervention/dummy-filter-input.html" \ No newline at end of file diff --git a/intervention/templates/intervention/dummy-filter-input.html b/intervention/templates/intervention/dummy-filter-input.html new file mode 100644 index 00000000..ba59200b --- /dev/null +++ b/intervention/templates/intervention/dummy-filter-input.html @@ -0,0 +1,5 @@ +{% comment %} + This is an empty template. + It's used to dismiss a default widget for a django_filter filter and to use a predefined input directly in the + template without losing the comfort of matching the filter methods declared in the filter +{% endcomment %} \ No newline at end of file diff --git a/templates/generic_index.html b/templates/generic_index.html index 491f0cd3..90185489 100644 --- a/templates/generic_index.html +++ b/templates/generic_index.html @@ -1,5 +1,94 @@ {% extends 'base.html' %} +{% load django_tables2 %} +{% load i18n static fontawesome_5 %} + {% block body %} - {% include 'table.html' %} +