#36 Quality checks

* refactors toggling of recorded status into RecordableMixin
This commit is contained in:
mpeltriaux 2021-10-25 17:01:02 +02:00
parent 0e4113249f
commit f6f532effb
5 changed files with 38 additions and 24 deletions

View File

@ -22,7 +22,7 @@ from compensation.managers import CompensationStateManager, EcoAccountDeductionM
from compensation.utils.quality import CompensationQualityChecker, EcoAccountQualityChecker from compensation.utils.quality import CompensationQualityChecker, EcoAccountQualityChecker
from intervention.models import Intervention, ResponsibilityData, LegalData from intervention.models import Intervention, ResponsibilityData, LegalData
from konova.models import BaseObject, BaseResource, Geometry, UuidModel, AbstractDocument, \ from konova.models import BaseObject, BaseResource, Geometry, UuidModel, AbstractDocument, \
generate_document_file_upload_path generate_document_file_upload_path, RecordableMixin
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
from user.models import UserActionLogEntry from user.models import UserActionLogEntry
@ -310,7 +310,7 @@ class CompensationDocument(AbstractDocument):
pass pass
class EcoAccount(AbstractCompensation): class EcoAccount(AbstractCompensation, RecordableMixin):
""" """
An eco account is a kind of 'prepaid' compensation. It can be compared to an account that already has been filled An eco account is a kind of 'prepaid' compensation. It can be compared to an account that already has been filled
with some kind of currency. From this account one is able to deduct currency for current projects. with some kind of currency. From this account one is able to deduct currency for current projects.

View File

@ -7,12 +7,12 @@ from django.db.models import QuerySet
from compensation.models import AbstractCompensation from compensation.models import AbstractCompensation
from ema.managers import EmaManager from ema.managers import EmaManager
from ema.utils.quality import EmaQualityChecker from ema.utils.quality import EmaQualityChecker
from konova.models import AbstractDocument, generate_document_file_upload_path from konova.models import AbstractDocument, generate_document_file_upload_path, RecordableMixin
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
from user.models import UserActionLogEntry from user.models import UserActionLogEntry
class Ema(AbstractCompensation): class Ema(AbstractCompensation, RecordableMixin):
""" """
EMA = Ersatzzahlungsmaßnahme EMA = Ersatzzahlungsmaßnahme
(compensation actions from payments) (compensation actions from payments)

View File

@ -10,7 +10,6 @@ import shutil
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.gis.db import models from django.contrib.gis.db import models
from django.db.models import QuerySet from django.db.models import QuerySet
from django.utils.translation import gettext_lazy as _
from codelist.models import KonovaCode from codelist.models import KonovaCode
from codelist.settings import CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID, CODELIST_LAW_ID, \ from codelist.settings import CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID, CODELIST_LAW_ID, \
@ -18,7 +17,7 @@ from codelist.settings import CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVA
from intervention.managers import InterventionManager from intervention.managers import InterventionManager
from intervention.utils.quality import InterventionQualityChecker from intervention.utils.quality import InterventionQualityChecker
from konova.models import BaseObject, Geometry, UuidModel, BaseResource, AbstractDocument, \ from konova.models import BaseObject, Geometry, UuidModel, BaseResource, AbstractDocument, \
generate_document_file_upload_path generate_document_file_upload_path, RecordableMixin
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE, LANIS_ZOOM_LUT from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE, LANIS_ZOOM_LUT
from konova.utils import generators from konova.utils import generators
from user.models import UserActionLogEntry from user.models import UserActionLogEntry
@ -172,7 +171,7 @@ class LegalData(UuidModel):
revocation = models.OneToOneField(Revocation, null=True, blank=True, help_text="Refers to 'Widerspruch am'", on_delete=models.SET_NULL) revocation = models.OneToOneField(Revocation, null=True, blank=True, help_text="Refers to 'Widerspruch am'", on_delete=models.SET_NULL)
class Intervention(BaseObject): class Intervention(BaseObject, RecordableMixin):
""" """
Interventions are e.g. construction sites where nature used to be. Interventions are e.g. construction sites where nature used to be.
""" """

View File

@ -486,21 +486,5 @@ class RecordModalForm(BaseModalForm):
def save(self): def save(self):
with transaction.atomic(): with transaction.atomic():
if self.cleaned_data["confirm"]: if self.cleaned_data["confirm"]:
if self.instance.recorded: self.instance.toggle_recorded(self.user)
# unrecord!
unrecord_action = UserActionLogEntry.objects.create(
user=self.user,
action=UserAction.UNRECORDED
)
# Do not delete the old .recorded attribute, since it shall stay in the .log list!
self.instance.recorded = None
self.instance.log.add(unrecord_action)
else:
record_action = UserActionLogEntry.objects.create(
user=self.user,
action=UserAction.RECORDED
)
self.instance.recorded = record_action
self.instance.log.add(record_action)
self.instance.save()
return self.instance return self.instance

View File

@ -313,3 +313,34 @@ class Geometry(BaseResource):
""" """
from konova.settings import DEFAULT_SRID from konova.settings import DEFAULT_SRID
geom = MultiPolygonField(null=True, blank=True, srid=DEFAULT_SRID) geom = MultiPolygonField(null=True, blank=True, srid=DEFAULT_SRID)
class RecordableMixin:
""" Mixin to be combined with BaseObject class
Provides functionality related to un/recording of data
"""
def toggle_recorded(self, user: User):
""" Un/Record intervention
Args:
user (User): Performing user
Returns:
"""
if not self.recorded:
action = UserActionLogEntry.objects.create(
user=user,
action=UserAction.RECORDED
)
self.recorded = action
else:
action = UserActionLogEntry.objects.create(
user=user,
action=UserAction.UNRECORDED
)
self.recorded = None
self.save()
self.log.add(action)