#86 Edit document
* adds support for editing of documents * adds buttons for intervention
This commit is contained in:
@@ -6,19 +6,19 @@ from django.shortcuts import render
|
||||
|
||||
from intervention.forms.forms import NewInterventionForm, EditInterventionForm
|
||||
from intervention.forms.modalForms import ShareModalForm, NewRevocationModalForm, \
|
||||
CheckModalForm, NewDeductionModalForm, NewInterventionDocumentForm, RemoveEcoAccountDeductionModalForm, \
|
||||
CheckModalForm, NewDeductionModalForm, NewInterventionDocumentModalForm, RemoveEcoAccountDeductionModalForm, \
|
||||
RemoveRevocationModalForm, EditEcoAccountDeductionModalForm, EditRevocationModalForm
|
||||
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, RemoveModalForm, RecordModalForm
|
||||
from konova.forms import SimpleGeomForm, RemoveModalForm, RecordModalForm, EditDocumentModalForm
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.documents import remove_document, get_document
|
||||
from konova.utils.generators import generate_qr_code
|
||||
from konova.utils.message_templates import INTERVENTION_INVALID, FORM_INVALID, IDENTIFIER_REPLACED, \
|
||||
CHECKED_RECORDED_RESET, DEDUCTION_REMOVED, DEDUCTION_ADDED, REVOCATION_ADDED, REVOCATION_REMOVED, \
|
||||
COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED, DEDUCTION_EDITED, REVOCATION_EDITED
|
||||
COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED, DEDUCTION_EDITED, REVOCATION_EDITED, DOCUMENT_EDITED
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ def new_document_view(request: HttpRequest, id: str):
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
form = NewInterventionDocumentForm(request.POST or None, request.FILES or None, instance=intervention, request=request)
|
||||
form = NewInterventionDocumentModalForm(request.POST or None, request.FILES or None, instance=intervention, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DOCUMENT_ADDED,
|
||||
@@ -164,18 +164,21 @@ def get_revocation_view(request: HttpRequest, doc_id: str):
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def get_document_view(request: HttpRequest, doc_id: str):
|
||||
@shared_access_required(Intervention, "id")
|
||||
def get_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||
""" Returns the document as downloadable file
|
||||
|
||||
Wraps the generic document fetcher function from konova.utils.
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The intervention id
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
doc = get_object_or_404(InterventionDocument, id=doc_id)
|
||||
user = request.user
|
||||
instance = doc.instance
|
||||
@@ -191,18 +194,21 @@ def get_document_view(request: HttpRequest, doc_id: str):
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def remove_document_view(request: HttpRequest, doc_id: str):
|
||||
@shared_access_required(Intervention, "id")
|
||||
def remove_document_view(request: HttpRequest, id: str, 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
|
||||
id (str): The intervention id
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
doc = get_object_or_404(InterventionDocument, id=doc_id)
|
||||
return remove_document(
|
||||
request,
|
||||
@@ -210,6 +216,32 @@ def remove_document_view(request: HttpRequest, doc_id: str):
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Intervention, "id")
|
||||
def edit_document_view(request: HttpRequest, id: str, 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
|
||||
id (str): The intervention id
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
doc = get_object_or_404(InterventionDocument, id=doc_id)
|
||||
form = EditDocumentModalForm(request.POST or None, request.FILES or None, instance=intervention, document=doc, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
DOCUMENT_EDITED,
|
||||
redirect_url=reverse("intervention:detail", args=(intervention.id,)) + "#related_data"
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@any_group_check
|
||||
def detail_view(request: HttpRequest, id: str):
|
||||
|
||||
Reference in New Issue
Block a user