#268 Filter multiple parcelgroups

* adds filter support for multiple parcelgroup and district names, separated by ','
This commit is contained in:
mpeltriaux 2022-12-08 10:14:39 +01:00
parent 0f6867605e
commit 63d37183de

View File

@ -19,7 +19,7 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
Specialized on filtering GeoReferenced model types Specialized on filtering GeoReferenced model types
""" """
# Parcel gmrkng # District
di = django_filters.CharFilter( di = django_filters.CharFilter(
method="filter_district", method="filter_district",
label=_(""), label=_(""),
@ -72,7 +72,7 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
), ),
) )
# Parcel counter # Parcel number
pn = django_filters.NumberFilter( pn = django_filters.NumberFilter(
method="filter_parcel_number", method="filter_parcel_number",
label=_(""), label=_(""),
@ -112,7 +112,7 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
return queryset return queryset
def filter_district(self, queryset, name, value) -> QuerySet: def filter_district(self, queryset, name, value) -> QuerySet:
""" Filters queryset depending on value for 'Gemarkung' """ Filters queryset depending on value for 'Kreis'
Args: Args:
queryset (): queryset ():
@ -122,10 +122,13 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
Returns: Returns:
""" """
matching_districts = District.objects.filter( values = value.split(",")
Q(name__icontains=value) | q = Q()
Q(key__icontains=value) for val in values:
).distinct() val = val.strip()
q |= Q(name__icontains=val) | Q(key__icontains=val)
matching_districts = District.objects.filter(q).distinct()
matching_parcels = Parcel.objects.filter( matching_parcels = Parcel.objects.filter(
district__in=matching_districts district__in=matching_districts
) )
@ -148,9 +151,14 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
Returns: Returns:
""" """
values = value.split(",")
q = Q()
for val in values:
val = val.strip()
q |= Q(parcel_group__name__icontains=val) | Q(parcel_group__key__icontains=val)
queryset = self._filter_parcel_reference( queryset = self._filter_parcel_reference(
queryset, queryset,
Q(parcel_group__name__icontains=value) | Q(parcel_group__key__icontains=value), q,
) )
return queryset return queryset