#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:
@@ -6,12 +6,13 @@ from django.shortcuts import render, get_object_or_404
|
||||
|
||||
from intervention.forms import NewInterventionForm, EditInterventionForm, ShareInterventionForm, NewRevocationForm, \
|
||||
RunCheckForm, NewDeductionForm
|
||||
from intervention.models import Intervention, Revocation
|
||||
from intervention.models import Intervention, Revocation, InterventionDocument, RevocationDocument
|
||||
from intervention.tables import InterventionTable
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import *
|
||||
from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm, RecordModalForm
|
||||
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT
|
||||
from konova.utils.documents import remove_document, get_document
|
||||
from konova.utils.message_templates import FORM_INVALID, INTERVENTION_INVALID
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
@@ -94,6 +95,60 @@ def new_document_view(request: HttpRequest, id: str):
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def get_revocation_view(request: HttpRequest, doc_id: str):
|
||||
""" Returns the revocation document as downloadable file
|
||||
|
||||
Wraps the generic document fetcher function from konova.utils.
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
doc = get_object_or_404(RevocationDocument, id=doc_id)
|
||||
return get_document(doc)
|
||||
|
||||
|
||||
@login_required
|
||||
def get_document_view(request: HttpRequest, doc_id: str):
|
||||
""" Returns the document as downloadable file
|
||||
|
||||
Wraps the generic document fetcher function from konova.utils.
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
doc = get_object_or_404(InterventionDocument, id=doc_id)
|
||||
return get_document(doc)
|
||||
|
||||
|
||||
@login_required
|
||||
def remove_document_view(request: HttpRequest, doc_id: str):
|
||||
""" Removes the document from the database and file system
|
||||
|
||||
Wraps the generic functionality from konova.utils.
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
doc = get_object_or_404(InterventionDocument, id=doc_id)
|
||||
return remove_document(
|
||||
request,
|
||||
doc
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@any_group_check
|
||||
def open_view(request: HttpRequest, id: str):
|
||||
|
||||
Reference in New Issue
Block a user