#139 Parcel filter improved
* improves frontend filtering for district, municipal, ..., so keys can be used for a lookup as well
This commit is contained in:
parent
8af0e41e2d
commit
6e76a3fdce
@ -145,26 +145,22 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
|
|||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def _filter_parcel_reference(self, queryset, name, value, filter_value) -> QuerySet:
|
def _filter_parcel_reference(self, queryset, filter_q) -> QuerySet:
|
||||||
""" Filters the parcel entries by a given filter_value.
|
""" Filters the parcel entries by a given filter_value.
|
||||||
|
|
||||||
filter_value may already include further filter annotations like 'xy__icontains'
|
filter_value may already include further filter annotations like 'xy__icontains'
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
queryset ():
|
queryset (QuerySet): The queryset
|
||||||
name ():
|
filter_q (Q): The Q-style filter expression
|
||||||
value ():
|
|
||||||
filter_value ():
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
_filter = {
|
|
||||||
filter_value: value
|
|
||||||
}
|
|
||||||
matching_parcels = Parcel.objects.filter(
|
matching_parcels = Parcel.objects.filter(
|
||||||
**_filter
|
filter_q
|
||||||
)
|
)
|
||||||
|
|
||||||
related_geoms = matching_parcels.values(
|
related_geoms = matching_parcels.values(
|
||||||
"geometries"
|
"geometries"
|
||||||
).distinct()
|
).distinct()
|
||||||
@ -185,8 +181,9 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
matching_districts = District.objects.filter(
|
matching_districts = District.objects.filter(
|
||||||
name__icontains=value
|
Q(name__icontains=value) |
|
||||||
)
|
Q(key__icontains=value)
|
||||||
|
).distinct()
|
||||||
matching_parcels = Parcel.objects.filter(
|
matching_parcels = Parcel.objects.filter(
|
||||||
district__in=matching_districts
|
district__in=matching_districts
|
||||||
)
|
)
|
||||||
@ -209,7 +206,10 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
queryset = self._filter_parcel_reference(queryset, name, value, "parcel_group__name__icontains")
|
queryset = self._filter_parcel_reference(
|
||||||
|
queryset,
|
||||||
|
Q(parcel_group__name__icontains=value) | Q(parcel_group__key__icontains=value),
|
||||||
|
)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def filter_parcel(self, queryset, name, value) -> QuerySet:
|
def filter_parcel(self, queryset, name, value) -> QuerySet:
|
||||||
@ -224,7 +224,10 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
value = value.replace("-", "")
|
value = value.replace("-", "")
|
||||||
queryset = self._filter_parcel_reference(queryset, name, value, "flr")
|
queryset = self._filter_parcel_reference(
|
||||||
|
queryset,
|
||||||
|
Q(flr=value),
|
||||||
|
)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def filter_parcel_counter(self, queryset, name, value) -> QuerySet:
|
def filter_parcel_counter(self, queryset, name, value) -> QuerySet:
|
||||||
@ -239,7 +242,10 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
value = value.replace("-", "")
|
value = value.replace("-", "")
|
||||||
queryset = self._filter_parcel_reference(queryset, name, value, "flrstck_zhlr")
|
queryset = self._filter_parcel_reference(
|
||||||
|
queryset,
|
||||||
|
Q(flrstck_zhlr=value)
|
||||||
|
)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def filter_parcel_number(self, queryset, name, value) -> QuerySet:
|
def filter_parcel_number(self, queryset, name, value) -> QuerySet:
|
||||||
@ -254,7 +260,10 @@ class GeoReferencedTableFilterMixin(django_filters.FilterSet):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
value = value.replace("-", "")
|
value = value.replace("-", "")
|
||||||
queryset = self._filter_parcel_reference(queryset, name, value, "flrstck_nnr")
|
queryset = self._filter_parcel_reference(
|
||||||
|
queryset,
|
||||||
|
Q(flrstck_nnr=value),
|
||||||
|
)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user