#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:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user