#18 File upload in certain folders
* refactors documents and file upload to be distributed into different subfolders, depending on the type of document (InterventionDocument, RevocationDocument, ...) * refactors Document model into AbstractDocument * subclasses RevocationDocument, InterventionDocument, COmpensationDocument, EmaDocument and EcoAccountDocument from AbstractDocument to provide proper functionality for each * adds new specialized routes for each new document type (opening, removing) * drops generic get and remove routes for documents
This commit is contained in:
+10
-12
@@ -15,9 +15,8 @@ from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.models import EcoAccountDeduction, EcoAccount
|
||||
from intervention.models import Intervention, Revocation
|
||||
from intervention.models import Intervention, Revocation, RevocationDocument
|
||||
from konova.forms import BaseForm, BaseModalForm
|
||||
from konova.models import Document
|
||||
from konova.settings import DEFAULT_LAT, DEFAULT_LON, DEFAULT_ZOOM, ZB_GROUP, ETS_GROUP
|
||||
from konova.utils.messenger import Messenger
|
||||
from konova.utils.user_checks import in_group
|
||||
@@ -372,19 +371,9 @@ class NewRevocationForm(BaseModalForm):
|
||||
user=self.user,
|
||||
action=UserAction.EDITED
|
||||
)
|
||||
if self.cleaned_data["file"]:
|
||||
document = Document.objects.create(
|
||||
title="revocation_of_{}".format(self.instance.identifier),
|
||||
date_of_creation=self.cleaned_data["date"],
|
||||
comment=self.cleaned_data["comment"],
|
||||
file=self.cleaned_data["file"],
|
||||
)
|
||||
else:
|
||||
document = None
|
||||
revocation = Revocation.objects.create(
|
||||
date=self.cleaned_data["date"],
|
||||
comment=self.cleaned_data["comment"],
|
||||
document=document,
|
||||
created=created_action,
|
||||
)
|
||||
self.instance.modified = edited_action
|
||||
@@ -392,6 +381,15 @@ class NewRevocationForm(BaseModalForm):
|
||||
self.instance.log.add(edited_action)
|
||||
self.instance.legal.revocation = revocation
|
||||
self.instance.legal.save()
|
||||
|
||||
if self.cleaned_data["file"]:
|
||||
RevocationDocument.objects.create(
|
||||
title="revocation_of_{}".format(self.instance.identifier),
|
||||
date_of_creation=self.cleaned_data["date"],
|
||||
comment=self.cleaned_data["comment"],
|
||||
file=self.cleaned_data["file"],
|
||||
instance=revocation
|
||||
)
|
||||
return revocation
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user