# 61 Filter offices frontend/backend
* adds filters for registration and conservation offices * adds SelectionTableFilter as new holder for these types of filter components
This commit is contained in:
@@ -6,11 +6,14 @@ Created on: 11.01.22
|
||||
|
||||
"""
|
||||
import django_filters
|
||||
from dal_select2.widgets import ModelSelect2
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import QuerySet, Q
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID
|
||||
from intervention.inputs import DummyFilterInput
|
||||
from konova.models import Parcel, District
|
||||
|
||||
@@ -351,6 +354,79 @@ class RecordableTableFilterMixin(django_filters.FilterSet):
|
||||
return queryset
|
||||
|
||||
|
||||
class RegistrationOfficeTableFilterMixin(django_filters.FilterSet):
|
||||
""" A mixin for AbstractTableFilter
|
||||
|
||||
Specialized on filtering for related registration offices
|
||||
|
||||
"""
|
||||
ro = django_filters.ModelChoiceFilter(
|
||||
method="filter_reg_office",
|
||||
label=_(""),
|
||||
label_suffix=_(""),
|
||||
queryset=KonovaCode.objects.filter(
|
||||
is_archived=False,
|
||||
is_leaf=True,
|
||||
code_lists__in=[CODELIST_REGISTRATION_OFFICE_ID],
|
||||
),
|
||||
widget=ModelSelect2(
|
||||
url="codes-registration-office-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Registration office"),
|
||||
"title": _("Search for registration office"),
|
||||
"class": "",
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
def filter_reg_office(self, queryset, name, value):
|
||||
qs = queryset.filter(
|
||||
responsible__registration_office=value
|
||||
)
|
||||
return qs
|
||||
|
||||
|
||||
class ConservationOfficeTableFilterMixin(django_filters.FilterSet):
|
||||
""" A mixin for AbstractTableFilter
|
||||
|
||||
Specialized on filtering for related conservation offices
|
||||
|
||||
"""
|
||||
co = django_filters.ModelChoiceFilter(
|
||||
method="filter_cons_office",
|
||||
label=_(""),
|
||||
label_suffix=_(""),
|
||||
queryset=KonovaCode.objects.filter(
|
||||
is_archived=False,
|
||||
is_leaf=True,
|
||||
code_lists__in=[CODELIST_CONSERVATION_OFFICE_ID],
|
||||
),
|
||||
widget=ModelSelect2(
|
||||
url="codes-conservation-office-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Conservation office"),
|
||||
"title": _("Search for conservation office"),
|
||||
"class": "",
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
def filter_cons_office(self, queryset, name, value):
|
||||
qs = queryset.filter(
|
||||
responsible__conservation_office=value
|
||||
)
|
||||
return qs
|
||||
|
||||
|
||||
class SelectionTableFilter(AbstractTableFilter,
|
||||
RegistrationOfficeTableFilterMixin,
|
||||
ConservationOfficeTableFilterMixin):
|
||||
""" TableFilter holding different filter options for selection related filtering
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class QueryTableFilter(AbstractTableFilter,
|
||||
KeywordTableFilterMixin,
|
||||
FileNumberTableFilterMixin,
|
||||
|
||||
Reference in New Issue
Block a user