#86 Revocation edit
* adds support for revocation edit
* revocation document files will be replaced on an edit
This commit is contained in:
@@ -8,6 +8,8 @@ Created on: 15.11.21
|
||||
import shutil
|
||||
|
||||
from django.contrib import messages
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models.fields.files import FieldFile
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
@@ -202,6 +204,41 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
)
|
||||
return revocation
|
||||
|
||||
def edit_revocation(self, form):
|
||||
""" Updates a revocation of the intervention
|
||||
|
||||
Args:
|
||||
form (EditRevocationModalForm): The form holding the data
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
form_data = form.cleaned_data
|
||||
file = form_data.get("file", None)
|
||||
|
||||
revocation = form.revocation
|
||||
revocation.date = form_data.get("date", None)
|
||||
revocation.comment = form_data.get("comment", None)
|
||||
|
||||
with transaction.atomic():
|
||||
try:
|
||||
revocation.document.date_of_creation = revocation.date
|
||||
revocation.document.comment = revocation.comment
|
||||
if not isinstance(file, FieldFile):
|
||||
revocation.document.replace_file(file)
|
||||
revocation.document.save()
|
||||
except ObjectDoesNotExist:
|
||||
revocation.document = RevocationDocument.objects.create(
|
||||
title="revocation_of_{}".format(self.identifier),
|
||||
date_of_creation=revocation.date,
|
||||
comment=revocation.comment,
|
||||
file=file,
|
||||
instance=revocation
|
||||
)
|
||||
revocation.save()
|
||||
|
||||
return revocation
|
||||
|
||||
def remove_revocation(self, form):
|
||||
""" Removes a revocation from the intervention
|
||||
|
||||
|
||||
Reference in New Issue
Block a user