#49 Extends sanitize db command
* extends sanitize db command to remove unrelated parcels and district from the database * fixes bug where single parcel wfs match would lead to unexpected behaviour * adds admin interface for parcels and districts * adds updating of parcels in case of SimpleGeomForm saving
This commit is contained in:
parent
632fb0f48a
commit
ecb67809da
@ -7,7 +7,7 @@ Created on: 22.07.21
|
||||
"""
|
||||
from django.contrib import admin
|
||||
|
||||
from konova.models import Geometry, Deadline, GeometryConflict
|
||||
from konova.models import Geometry, Deadline, GeometryConflict, Parcel, District
|
||||
|
||||
|
||||
class GeometryAdmin(admin.ModelAdmin):
|
||||
@ -17,6 +17,25 @@ class GeometryAdmin(admin.ModelAdmin):
|
||||
]
|
||||
|
||||
|
||||
class ParcelAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"flr",
|
||||
"flrstck_nnr",
|
||||
"flrstck_zhlr",
|
||||
"updated_on",
|
||||
]
|
||||
|
||||
|
||||
class DistrictAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"gmrkng",
|
||||
"gmnd",
|
||||
"krs",
|
||||
]
|
||||
|
||||
|
||||
class GeometryConflictAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"conflicting_geometry",
|
||||
@ -52,5 +71,7 @@ class BaseObjectAdmin(admin.ModelAdmin):
|
||||
|
||||
|
||||
admin.site.register(Geometry, GeometryAdmin)
|
||||
admin.site.register(Parcel, ParcelAdmin)
|
||||
admin.site.register(District, DistrictAdmin)
|
||||
admin.site.register(GeometryConflict, GeometryConflictAdmin)
|
||||
admin.site.register(Deadline, DeadlineAdmin)
|
||||
|
@ -287,6 +287,7 @@ class SimpleGeomForm(BaseForm):
|
||||
geometry = self.instance.geometry
|
||||
geometry.geom = self.cleaned_data.get("geom", MultiPolygon(srid=DEFAULT_SRID))
|
||||
geometry.modified = action
|
||||
geometry.update_parcels()
|
||||
geometry.save()
|
||||
except LookupError:
|
||||
# No geometry or linked instance holding a geometry exist --> create a new one!
|
||||
|
@ -9,7 +9,7 @@ from compensation.models import CompensationState, Compensation, EcoAccount, Com
|
||||
from ema.models import Ema
|
||||
from intervention.models import Intervention
|
||||
from konova.management.commands.setup import BaseKonovaCommand
|
||||
from konova.models import Deadline, Geometry
|
||||
from konova.models import Deadline, Geometry, Parcel, District
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ class Command(BaseKonovaCommand):
|
||||
self.sanitize_actions()
|
||||
self.sanitize_deadlines()
|
||||
self.sanitize_geometries()
|
||||
self.sanitize_parcels_and_districts()
|
||||
except KeyboardInterrupt:
|
||||
self._break_line()
|
||||
exit(-1)
|
||||
@ -266,3 +267,34 @@ class Command(BaseKonovaCommand):
|
||||
self._write_success("No unused states found.")
|
||||
self._break_line()
|
||||
|
||||
def sanitize_parcels_and_districts(self):
|
||||
""" Removes unattached parcels and districts
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self._write_warning("=== Sanitize parcels and districts ===")
|
||||
unrelated_parcels = Parcel.objects.filter(
|
||||
geometries=None,
|
||||
)
|
||||
num_unrelated_parcels = unrelated_parcels.count()
|
||||
if num_unrelated_parcels > 0:
|
||||
self._write_error(f"Found {num_unrelated_parcels} unrelated parcel entries. Delete now...")
|
||||
unrelated_parcels.delete()
|
||||
self._write_success("Unrelated parcels deleted.")
|
||||
else:
|
||||
self._write_success("No unrelated parcels found.")
|
||||
|
||||
unrelated_districts = District.objects.filter(
|
||||
parcels=None,
|
||||
)
|
||||
num_unrelated_districts = unrelated_districts.count()
|
||||
if num_unrelated_districts > 0:
|
||||
self._write_error(f"Found {num_unrelated_districts} unrelated district entries. Delete now...")
|
||||
unrelated_districts.delete()
|
||||
self._write_success("Unrelated districts deleted.")
|
||||
else:
|
||||
self._write_success("No unrelated districts found.")
|
||||
|
||||
self._break_line()
|
||||
|
||||
|
@ -158,10 +158,16 @@ class ParcelWFSFetcher(AbstractWFSFetcher):
|
||||
"wfs:FeatureCollection",
|
||||
{},
|
||||
)
|
||||
features += collection.get(
|
||||
|
||||
members = collection.get(
|
||||
"wfs:member",
|
||||
[],
|
||||
)
|
||||
if len(members) > 1:
|
||||
features += members
|
||||
else:
|
||||
features += [members]
|
||||
|
||||
if collection.get("@next", None) is not None:
|
||||
start_index += self.count
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user