Compare commits

..

5 Commits

Author SHA1 Message Date
be0d261e81 Merge pull request '# 439 Wartungskommando Nachverschneidung' (#440) from 439_Wartungskommando_Nachverschneidung into master
Reviewed-on: #440
2024-10-25 14:24:18 +02:00
62e1b046c3 # 439 Wartungskommando Nachverschneidung
* refactors command update_all_parcels into recalculate_parcels
* fixes bug in command generate_report
2024-10-25 14:23:21 +02:00
669a12410f Merge pull request 'missing_migrations' (#437) from missing_migrations into master
Reviewed-on: #437
2024-08-26 18:57:10 +02:00
dd77e6c16e Merge branch 'refs/heads/master' into missing_migrations 2024-08-26 18:53:11 +02:00
33774ce557 # Migrations
* adds missing migrations
* renames variables shadowing in-builts
2024-08-26 18:51:58 +02:00
6 changed files with 76 additions and 20 deletions

View File

@@ -0,0 +1,25 @@
# Generated by Django 5.0.8 on 2024-08-26 16:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('codelist', '0002_migrate_975_to_288'),
]
operations = [
migrations.AlterField(
model_name='konovacode',
name='long_name',
field=models.CharField(blank=True, default="", max_length=1000),
preserve_default=False,
),
migrations.AlterField(
model_name='konovacode',
name='short_name',
field=models.CharField(blank=True, default="", help_text='Short version of long name', max_length=500),
preserve_default=False,
),
]

View File

@@ -0,0 +1,19 @@
# Generated by Django 5.0.8 on 2024-08-26 16:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('codelist', '0003_alter_konovacode_long_name_and_more'),
('compensation', '0015_alter_compensation_after_states_and_more'),
]
operations = [
migrations.AlterField(
model_name='compensationstate',
name='biotope_type_details',
field=models.ManyToManyField(blank=True, limit_choices_to={'code_lists__in': [288], 'is_archived': False, 'is_selectable': True}, related_name='+', to='codelist.konovacode'),
),
]

View File

@@ -6,11 +6,11 @@ Created on: 26.10.22
""" """
import zipfile import zipfile
from datetime import datetime
from io import BytesIO from io import BytesIO
from django.core.mail import EmailMessage from django.core.mail import EmailMessage
from django.utils import timezone from django.utils import timezone
from django.utils.datetime_safe import datetime
from analysis.utils.excel.excel import TempExcelFile from analysis.utils.excel.excel import TempExcelFile
from analysis.utils.report import TimespanReport from analysis.utils.report import TimespanReport

View File

@@ -8,27 +8,46 @@ Created on: 04.01.22
import datetime import datetime
from django.contrib.gis.db.models.functions import Area from django.contrib.gis.db.models.functions import Area
from django.utils.timezone import now
from konova.management.commands.setup import BaseKonovaCommand from konova.management.commands.setup import BaseKonovaCommand
from konova.models import Geometry, Parcel, District from konova.models import Geometry, Parcel, District
class Command(BaseKonovaCommand): class Command(BaseKonovaCommand):
help = "Checks the database' sanity and removes unused entries" help = "Recalculates parcels for entries with geometry but missing parcel information"
def add_arguments(self, parser):
parser.add_argument(
"--force-all",
action="store_true",
default=False,
help="If Attribute set, all entries parcels will be recalculated"
)
def handle(self, *args, **options): def handle(self, *args, **options):
try: try:
self.update_all_parcels() self.recalculate_parcels(options)
except KeyboardInterrupt: except KeyboardInterrupt:
self._break_line() self._break_line()
exit(-1) exit(-1)
def update_all_parcels(self): def recalculate_parcels(self, options: dict):
num_parcels_before = Parcel.objects.count() force_all = options.get("force_all", False)
num_districts_before = District.objects.count()
if force_all:
geometry_objects = Geometry.objects.all()
else:
_today = now().date()
_date_threshold = _today - datetime.timedelta(days=1)
geometry_objects = Geometry.objects.filter(
parcel_update_start__date__lte=_date_threshold,
parcel_update_end__isnull=True
)
self._write_warning("=== Update parcels and districts ===") self._write_warning("=== Update parcels and districts ===")
# Order geometries by size to process smaller once at first # Order geometries by size to process smaller once at first
geometries = Geometry.objects.all().exclude( geometries = geometry_objects.exclude(
geom=None geom=None
).annotate(area=Area("geom")).order_by( ).annotate(area=Area("geom")).order_by(
'area' 'area'
@@ -43,12 +62,5 @@ class Command(BaseKonovaCommand):
i += 1 i += 1
self._write_warning(f"--- {i}/{num_geoms} processed") self._write_warning(f"--- {i}/{num_geoms} processed")
num_parcels_after = Parcel.objects.count()
num_districts_after = District.objects.count()
if num_parcels_after != num_parcels_before:
self._write_error(f"Parcels have changed: {num_parcels_before} to {num_parcels_after} entries. You should run the sanitize command.")
if num_districts_after != num_districts_before:
self._write_error(f"Districts have changed: {num_districts_before} to {num_districts_after} entries. You should run the sanitize command.")
self._write_success("Updating parcels done!") self._write_success("Updating parcels done!")
self._break_line() self._break_line()

View File

@@ -55,11 +55,11 @@ class ParcelFetcher:
content = json.loads(response.content.decode("utf-8")) content = json.loads(response.content.decode("utf-8"))
except JSONDecodeError: except JSONDecodeError:
content = {} content = {}
next = content.get("next", None) _next = content.get("next", None)
fetched_parcels = content.get("results", []) fetched_parcels = content.get("results", [])
self.results += fetched_parcels self.results += fetched_parcels
if next: if _next:
self.get_parcels(next) self.get_parcels(_next)
return self.results return self.results

View File

@@ -35,9 +35,9 @@ class PropagateUserView(View):
def post(self, request: HttpRequest, *args, **kwargs): def post(self, request: HttpRequest, *args, **kwargs):
# Decrypt # Decrypt
encrypted_body = request.body encrypted_body = request.body
hash = hashlib.md5() _hash = hashlib.md5()
hash.update(OAUTH_CLIENT_ID.encode("utf-8")) _hash.update(OAUTH_CLIENT_ID.encode("utf-8"))
key = base64.urlsafe_b64encode(hash.hexdigest().encode("utf-8")) key = base64.urlsafe_b64encode(_hash.hexdigest().encode("utf-8"))
fernet = Fernet(key) fernet = Fernet(key)
body = fernet.decrypt(encrypted_body).decode("utf-8") body = fernet.decrypt(encrypted_body).decode("utf-8")
body = json.loads(body) body = json.loads(body)