#160 Parcel number to parcel table

* adds number of all underlying parcels into parcel table
* reworks minor code parts of parcel related logic
* fixes bug where under certain circumstances a parcel would have been added twice to a geometry
* removes unused parcel fetching on intervention detail view
This commit is contained in:
2022-05-11 15:52:29 +02:00
parent 21d1fabeec
commit 3535aba30f
7 changed files with 113 additions and 83 deletions

View File

@@ -152,6 +152,7 @@ class Geometry(BaseResource):
underlying_parcels.append(parcel_obj)
# Update the linked parcels
self.parcels.clear()
self.parcels.set(underlying_parcels)
# Set the calculated_on intermediate field, so this related data will be found on lookups
@@ -172,7 +173,6 @@ class Geometry(BaseResource):
Returns:
parcels (QuerySet): The related parcels as queryset
"""
parcels = self.parcels.filter(
parcelintersection__calculated_on__isnull=False,
).prefetch_related(
@@ -184,6 +184,17 @@ class Geometry(BaseResource):
return parcels
def count_underlying_parcels(self):
""" Getter for number of underlying parcels
Returns:
"""
num_parcels = self.parcels.filter(
parcelintersection__calculated_on__isnull=False,
).count()
return num_parcels
class GeometryConflict(UuidModel):
"""

View File

@@ -652,10 +652,21 @@ class GeoReferencedMixin(models.Model):
Returns:
parcels (Iterable): An empty list or a Queryset
"""
result = []
if self.geometry is not None:
return self.geometry.get_underlying_parcels()
else:
return []
result = self.geometry.get_underlying_parcels()
return result
def count_underlying_parcels(self):
""" Getter for number of underlying parcels
Returns:
"""
result = 0
if self.geometry is not None:
result = self.geometry.count_underlying_parcels()
return result
def set_geometry_conflict_message(self, request: HttpRequest):
if self.geometry is None:

View File

@@ -5,6 +5,11 @@
{% trans 'Parcels can not be calculated, since no geometry is given.' %}
</article>
{% else %}
<div>
<h4 class="">
<span class="badge rlp-r">{{num_parcels}}</span>
{% trans 'Parcels found' %}</h4>
</div>
<table id="upper-spatial-table" class="table table-hover">
<thead>
<tr>

View File

@@ -135,12 +135,14 @@ def get_geom_parcels(request: HttpRequest, id: str):
municipals = Municipal.objects.filter(id__in=municipals)
rpp = 100
num_all_parcels = parcels.count()
parcels = parcels[:rpp]
next_page = 1
if len(parcels) < rpp:
next_page = None
context = {
"num_parcels": num_all_parcels,
"parcels": parcels,
"municipals": municipals,
"geom_id": str(id),