Fixes + enhancements
* minor fixes and enhancements
This commit is contained in:
parent
fbb7b66249
commit
492110882b
@ -10,6 +10,7 @@ from django.utils.timezone import make_aware
|
||||
from konova.models import Geometry
|
||||
from konova.settings import DEFAULT_GROUP
|
||||
from user.models import User, UserActionLogEntry, UserAction, Team
|
||||
from konova.tasks import celery_update_parcels
|
||||
|
||||
|
||||
class BaseMigrater:
|
||||
@ -62,7 +63,7 @@ class BaseMigrater:
|
||||
geom = instance.geometry or Geometry()
|
||||
geom.geom = db_result_geom
|
||||
geom.save()
|
||||
# celery_update_parcels.delay(geom.id)
|
||||
celery_update_parcels.delay(geom.id)
|
||||
|
||||
instance.geometry = geom
|
||||
return instance
|
||||
@ -143,9 +144,10 @@ class BaseMigrater:
|
||||
)
|
||||
fetch_results = tmp_cursor.fetchall()
|
||||
|
||||
instance.log.all().delete()
|
||||
migrated_identifier = "(migriert)"
|
||||
instance.log.filter(comment__contains=migrated_identifier).delete()
|
||||
for result in fetch_results:
|
||||
comment = result[0]
|
||||
comment = f"{result[0]} {migrated_identifier}"
|
||||
timestamp = make_aware(result[1])
|
||||
user_name = result[2]
|
||||
user = self._get_migrate_user(user_name)
|
||||
@ -172,11 +174,11 @@ class BaseMigrater:
|
||||
first_entry = instance.log.order_by("timestamp").first()
|
||||
last_entry = instance.log.order_by("-timestamp").first()
|
||||
|
||||
if first_entry is not None:
|
||||
if first_entry is not None and instance.created is None:
|
||||
instance.created = UserActionLogEntry.get_created_action(first_entry.user)
|
||||
instance.created.timestamp = first_entry.timestamp
|
||||
instance.created.save()
|
||||
if last_entry is not None:
|
||||
if last_entry is not None and instance.modified != last_entry:
|
||||
instance.modified = last_entry
|
||||
|
||||
tmp_cursor.close()
|
||||
|
@ -1,6 +1,6 @@
|
||||
import datetime
|
||||
|
||||
from django.contrib.auth.models import Group
|
||||
from django.contrib.gis.gdal import GDALException
|
||||
from django.contrib.gis.geos import MultiPolygon, Polygon
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db import transaction
|
||||
@ -13,8 +13,8 @@ from compensation.utils.quality import EcoAccountQualityChecker
|
||||
from intervention.models import Responsibility, Handler, Intervention, Legal
|
||||
from konova.management.commands.kspMigrater.compensation_migrater import CompensationMigrater
|
||||
from konova.models import Geometry
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP, DEFAULT_SRID
|
||||
from user.models import User, UserActionLogEntry
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
class EcoAccountMigrater(CompensationMigrater):
|
||||
@ -104,7 +104,7 @@ class EcoAccountMigrater(CompensationMigrater):
|
||||
if db_result_geom is not None:
|
||||
deductions_db_result_geom = MultiPolygon.from_ewkt(deduction_db_results[0][0])
|
||||
else:
|
||||
deductions_db_result_geom = MultiPolygon(srid=DEFAULT_SRID)
|
||||
deductions_db_result_geom = MultiPolygon(srid=DEFAULT_SRID_RLP)
|
||||
|
||||
tmp_cursor.execute(
|
||||
'select '
|
||||
@ -121,7 +121,7 @@ class EcoAccountMigrater(CompensationMigrater):
|
||||
|
||||
db_result_geom = account_db_result_geom.union(deductions_db_result_geom)
|
||||
if isinstance(db_result_geom, Polygon):
|
||||
db_result_geom = MultiPolygon(db_result_geom, srid=DEFAULT_SRID)
|
||||
db_result_geom = MultiPolygon(db_result_geom, srid=DEFAULT_SRID_RLP)
|
||||
instance.geometry = instance.geometry or Geometry()
|
||||
try:
|
||||
# Calculate area by transforming
|
||||
@ -146,6 +146,8 @@ class EcoAccountMigrater(CompensationMigrater):
|
||||
instance.geometry.save()
|
||||
except TypeError:
|
||||
raise TypeError(f"{identifier}, {db_result_geom}")
|
||||
except GDALException as e:
|
||||
raise GDALException(f"{identifier}, {e}")
|
||||
tmp_cursor.close()
|
||||
return instance
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from django.contrib.auth.models import Group
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_REGISTRATION_OFFICE_ID
|
||||
@ -84,6 +84,8 @@ class UserMigrater(BaseMigrater):
|
||||
except ObjectDoesNotExist:
|
||||
# organisation code might not be valid anymore
|
||||
continue
|
||||
except MultipleObjectsReturned as e:
|
||||
raise MultipleObjectsReturned(f"{_org}: {e}")
|
||||
if company_team is not None and len(user_teams) == 0:
|
||||
# Only team is the company team
|
||||
company_team.users.add(user)
|
||||
|
Loading…
Reference in New Issue
Block a user