Compare commits
4 Commits
a633663e9d
...
022e4a580b
Author | SHA1 | Date | |
---|---|---|---|
022e4a580b | |||
c7c6eef2e5 | |||
c2fc210868 | |||
2c493d33dc |
@ -11,6 +11,7 @@ import json
|
||||
import pika
|
||||
import xmltodict
|
||||
from django.db.models import Sum
|
||||
from django.utils import formats
|
||||
|
||||
from intervention.settings import EGON_RABBITMQ_HOST, EGON_RABBITMQ_USER, EGON_RABBITMQ_PW, EGON_RABBITMQ_PORT
|
||||
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT
|
||||
@ -92,6 +93,9 @@ class EgonGmlBuilder:
|
||||
)["summed"]
|
||||
return all_payments
|
||||
|
||||
def _float_to_localized_string(self, value: float):
|
||||
return formats.number_format(value, use_l10n=True, decimal_pos=2)
|
||||
|
||||
def _gen_kompensationsArt(self) -> (str, int):
|
||||
comp_type = "Ersatzzahlung"
|
||||
comp_type_code = 774898901
|
||||
@ -191,7 +195,7 @@ class EgonGmlBuilder:
|
||||
"@xlink:href": f"http://register.naturschutz.rlp.de/repository/services/referenzliste/1053/{reg_office.atom_id if reg_office else None}",
|
||||
"#text": reg_office.long_name if reg_office else None
|
||||
},
|
||||
"oneo:ersatzzahlung": self._sum_all_payments(),
|
||||
"oneo:ersatzzahlung": self._float_to_localized_string(self._sum_all_payments()),
|
||||
"oneo:kompensationsart": {
|
||||
"@xlink:href": f"http://register.naturschutz.rlp.de/repository/services/referenzliste/88140/{comp_type_code}",
|
||||
"#text": comp_type
|
||||
|
@ -90,18 +90,22 @@ class BaseMigrater:
|
||||
doc_comment = doc_result[1]
|
||||
doc_date = doc_result[2]
|
||||
try:
|
||||
with open(doc_path, encoding="latin1") as file:
|
||||
with open(doc_path, "rb") as file:
|
||||
file = UploadedFile(file)
|
||||
doc_title = "Migrierte Datei"
|
||||
doc_date = doc_date or "1970-01-01"
|
||||
doc_exists = document_cls.objects.filter(
|
||||
instance=instance,
|
||||
title=doc_title,
|
||||
comment=doc_comment,
|
||||
date_of_creation=doc_date
|
||||
).exists()
|
||||
if doc_exists:
|
||||
continue
|
||||
|
||||
doc_file = self.__find_migrated_file_recursive(
|
||||
document_cls,
|
||||
instance,
|
||||
file.name
|
||||
)
|
||||
|
||||
if doc_file is not None:
|
||||
doc_file.delete()
|
||||
else:
|
||||
print(f"------ Could not find file, that should have been migrated already. Adding new version anyway: {doc_path}")
|
||||
|
||||
doc = document_cls.objects.create(
|
||||
title=doc_title,
|
||||
comment=doc_comment,
|
||||
@ -114,6 +118,21 @@ class BaseMigrater:
|
||||
tmp_cursor.close()
|
||||
return instance
|
||||
|
||||
def __find_migrated_file_recursive(self, document_cls, instance, file_name):
|
||||
file_name_tmp = file_name
|
||||
try:
|
||||
doc_file = document_cls.objects.get(
|
||||
instance=instance,
|
||||
file__icontains=file_name_tmp
|
||||
)
|
||||
return doc_file
|
||||
except ObjectDoesNotExist:
|
||||
file_name_tmp = file_name_tmp[:len(file_name_tmp) - 1]
|
||||
if len(file_name_tmp) > 0:
|
||||
return self.__find_migrated_file_recursive(document_cls, instance, file_name_tmp)
|
||||
else:
|
||||
return None
|
||||
|
||||
def _migrate_log(self, instance, db_result: tuple):
|
||||
identifier = f"'{db_result[0]}'"
|
||||
tmp_cursor = self.db_connection.cursor()
|
||||
|
@ -146,6 +146,7 @@ class InterventionMigrater(BaseMigrater):
|
||||
|
||||
def migrate(self):
|
||||
self.connect_db()
|
||||
el = "'EIV-1380625802430'"
|
||||
cursor = self.db_connection.cursor()
|
||||
cursor.execute(
|
||||
'select '
|
||||
@ -180,7 +181,8 @@ class InterventionMigrater(BaseMigrater):
|
||||
'where '
|
||||
'om."OKL"=7730085 and '
|
||||
'om.archiv=false and '
|
||||
'om.nicht_vollstaendig=0 '
|
||||
'om.nicht_vollstaendig=0 and '
|
||||
f'om."KENNUNG"={el}'
|
||||
)
|
||||
|
||||
all_eivs = cursor.fetchall()
|
||||
@ -196,17 +198,17 @@ class InterventionMigrater(BaseMigrater):
|
||||
intervention = Intervention.objects.get_or_create(
|
||||
identifier=eiv[0]
|
||||
)[0]
|
||||
intervention.title = eiv[1]
|
||||
intervention.comment = eiv_comment
|
||||
intervention = self._migrate_intervention_legal(intervention, eiv)
|
||||
intervention = self._migrate_intervention_responsibility(intervention, eiv)
|
||||
#intervention.title = eiv[1]
|
||||
#intervention.comment = eiv_comment
|
||||
#intervention = self._migrate_intervention_legal(intervention, eiv)
|
||||
#intervention = self._migrate_intervention_responsibility(intervention, eiv)
|
||||
intervention = self._migrate_documents(intervention, InterventionDocument, eiv)
|
||||
intervention = self._migrate_log(intervention, eiv)
|
||||
intervention = self._migrate_revocation(intervention, eiv)
|
||||
#intervention = self._migrate_log(intervention, eiv)
|
||||
#intervention = self._migrate_revocation(intervention, eiv)
|
||||
intervention.save()
|
||||
|
||||
intervention = self._migrate_geometry(intervention, eiv)
|
||||
intervention = self._migrate_intervention_payment(intervention, eiv)
|
||||
#intervention = self._migrate_geometry(intervention, eiv)
|
||||
#intervention = self._migrate_intervention_payment(intervention, eiv)
|
||||
intervention.save()
|
||||
|
||||
num_processed += 1
|
||||
|
@ -20,11 +20,11 @@ class Command(BaseKonovaCommand):
|
||||
try:
|
||||
migraters = [
|
||||
InterventionMigrater(options),
|
||||
CompensationMigrater(options),
|
||||
EmaMigrater(options),
|
||||
EcoAccountMigrater(options),
|
||||
InterventionRecordedMigrater(options),
|
||||
UserMigrater(options),
|
||||
#CompensationMigrater(options),
|
||||
#EmaMigrater(options),
|
||||
#EcoAccountMigrater(options),
|
||||
#InterventionRecordedMigrater(options),
|
||||
#UserMigrater(options),
|
||||
]
|
||||
for migrater in migraters:
|
||||
migrater.migrate()
|
||||
|
Loading…
Reference in New Issue
Block a user