Intervention check
* adds functionality for check button * adds highlighting of important data on detail view for intervention * adds deleting logic to BaseObject model and BaseResource model * adds RunCheckForm * adds check_validity() method to Intervention class * fixes wrong success msg for adding documents * adds/updates translations
This commit is contained in:
+35
-30
@@ -9,6 +9,7 @@ from django.contrib.auth.models import User
|
||||
from django.contrib.gis.db import models
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.timezone import now
|
||||
|
||||
from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE
|
||||
@@ -133,36 +134,6 @@ class Intervention(BaseObject):
|
||||
def __str__(self):
|
||||
return "{} ({})".format(self.identifier, self.title)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
""" Custom delete functionality
|
||||
|
||||
Does not delete from database but sets a timestamp for being deleted on and which user deleted the object
|
||||
|
||||
Args:
|
||||
*args ():
|
||||
**kwargs ():
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
_now = timezone.now()
|
||||
_user = kwargs.get("user", None)
|
||||
|
||||
with transaction.atomic():
|
||||
# "Delete" related compensations as well
|
||||
coms = self.compensations.all()
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=_user,
|
||||
timestamp=_now,
|
||||
action=UserAction.DELETED
|
||||
)
|
||||
for com in coms:
|
||||
com.deleted = action
|
||||
com.save()
|
||||
|
||||
self.deleted = action
|
||||
self.save()
|
||||
|
||||
@staticmethod
|
||||
def _generate_new_identifier() -> str:
|
||||
""" Generates a new identifier for the intervention object
|
||||
@@ -234,3 +205,37 @@ class Intervention(BaseObject):
|
||||
|
||||
"""
|
||||
return self.users.filter(username=user.username).exists()
|
||||
|
||||
def check_validity(self) -> (bool, dict):
|
||||
""" Validity check
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ret_msgs = {}
|
||||
missing_str = _("Missing")
|
||||
not_missing_str = _("Exists")
|
||||
|
||||
# Check responsible data
|
||||
if self.responsible:
|
||||
if self.responsible.registration_file_number is None or len(self.responsible.registration_file_number) == 0:
|
||||
ret_msgs["Registration office file number"] = missing_str
|
||||
if self.responsible.conservation_file_number is None or len(self.responsible.conservation_file_number) == 0:
|
||||
ret_msgs["Conversation office file number"] = missing_str
|
||||
else:
|
||||
ret_msgs["responsible"] = missing_str
|
||||
|
||||
# Check revocation
|
||||
if self.legal.revocation:
|
||||
ret_msgs["Revocation"] = not_missing_str
|
||||
|
||||
if self.legal:
|
||||
if self.legal.registration_date is None:
|
||||
ret_msgs["Registration date"] = missing_str
|
||||
if self.legal.binding_date is None:
|
||||
ret_msgs["Binding on"] = missing_str
|
||||
else:
|
||||
ret_msgs["legal"] = missing_str
|
||||
|
||||
ret_result = len(ret_msgs) == 0
|
||||
return ret_result, ret_msgs
|
||||
Reference in New Issue
Block a user