# 139 Parcel reference improved
* improves frontend layout to display more details on district, municipal and parce group * improves ordering of parcels * refactors parcel related models * improves parcel fetching * extends and simplifies sanitize_db parcel related code
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, Parcel, District
|
||||
from konova.models import Deadline, Geometry, Parcel, District, Municipal, ParcelGroup
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
|
||||
|
||||
@@ -271,13 +271,26 @@ class Command(BaseKonovaCommand):
|
||||
self._write_success("No unused states found.")
|
||||
self._break_line()
|
||||
|
||||
def __sanitize_parcel_sub_type(self, cls):
|
||||
unrelated_entries = cls.objects.filter(
|
||||
parcels=None,
|
||||
)
|
||||
num_unrelated_entries = unrelated_entries.count()
|
||||
cls_name = cls.__name__
|
||||
if num_unrelated_entries > 0:
|
||||
self._write_error(f"Found {num_unrelated_entries} unrelated {cls_name} entries. Delete now...")
|
||||
unrelated_entries.delete()
|
||||
self._write_success(f"Unrelated {cls_name} deleted.")
|
||||
else:
|
||||
self._write_success(f"No unrelated {cls_name} found.")
|
||||
|
||||
def sanitize_parcels_and_districts(self):
|
||||
""" Removes unattached parcels and districts
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self._write_warning("=== Sanitize parcels and districts ===")
|
||||
self._write_warning("=== Sanitize administrative spatial references ===")
|
||||
unrelated_parcels = Parcel.objects.filter(
|
||||
geometries=None,
|
||||
)
|
||||
@@ -289,16 +302,12 @@ class Command(BaseKonovaCommand):
|
||||
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()
|
||||
sub_types = [
|
||||
District,
|
||||
Municipal,
|
||||
ParcelGroup
|
||||
]
|
||||
for sub_type in sub_types:
|
||||
self.__sanitize_parcel_sub_type(sub_type)
|
||||
|
||||
self._break_line()
|
||||
Reference in New Issue
Block a user