diff --git a/compensation/templates/compensation/detail/eco_account/includes/documents.html b/compensation/templates/compensation/detail/eco_account/includes/documents.html index b3895eac..e852842b 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/documents.html +++ b/compensation/templates/compensation/detail/eco_account/includes/documents.html @@ -27,6 +27,9 @@ {% trans 'Title' %} + + {% trans 'Created on' %} + {% trans 'Comment' %} @@ -41,18 +44,24 @@ {% for doc in obj.documents.all %} - + {{ doc.title }} + + {{ doc.date_of_creation }} +
{{ doc.comment }}
- + {% if is_default_member and has_access %} - + {% endif %} diff --git a/compensation/urls/eco_account.py b/compensation/urls/eco_account.py index 0c3a0293..e390d4fb 100644 --- a/compensation/urls/eco_account.py +++ b/compensation/urls/eco_account.py @@ -30,8 +30,9 @@ urlpatterns = [ # Documents path('/document/new/', new_document_view, name='new-doc'), - path('document/', get_document_view, name='get-doc'), - path('document//remove/', remove_document_view, name='remove-doc'), + path('/document/', get_document_view, name='get-doc'), + path('/document//edit', edit_document_view, name='edit-doc'), + path('/document//remove/', remove_document_view, name='remove-doc'), # Eco-account deductions path('/deduction//remove', deduction_remove_view, name='remove-deduction'), diff --git a/compensation/views/eco_account.py b/compensation/views/eco_account.py index d433d551..19959f81 100644 --- a/compensation/views/eco_account.py +++ b/compensation/views/eco_account.py @@ -24,7 +24,8 @@ from intervention.forms.modalForms import NewDeductionModalForm, ShareModalForm, from konova.contexts import BaseContext from konova.decorators import any_group_check, default_group_required, conservation_office_group_required, \ shared_access_required -from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentModalForm, RecordModalForm, RemoveDeadlineModalForm +from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentModalForm, RecordModalForm, \ + RemoveDeadlineModalForm, EditDocumentModalForm from konova.models import Deadline from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER @@ -33,7 +34,7 @@ from konova.utils.generators import generate_qr_code from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \ CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED, DOCUMENT_ADDED, COMPENSATION_STATE_REMOVED, \ COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, DEADLINE_ADDED, DEADLINE_REMOVED, \ - DEDUCTION_EDITED + DEDUCTION_EDITED, DOCUMENT_EDITED from konova.utils.user_checks import in_group @@ -534,46 +535,68 @@ def new_document_view(request: HttpRequest, id: str): @login_required @default_group_required -def get_document_view(request: HttpRequest, doc_id: str): +@shared_access_required(EcoAccount, "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 account id doc_id (str): The document id Returns: """ + acc = get_object_or_404(EcoAccount, id=id) doc = get_object_or_404(EcoAccountDocument, id=doc_id) - user = request.user - instance = doc.instance - # File download only possible if related instance is shared with user - if not instance.users.filter(id=user.id): - messages.info( - request, - DATA_UNSHARED - ) - return redirect("compensation:acc:detail", id=instance.id) return get_document(doc) @login_required @default_group_required @shared_access_required(EcoAccount, "id") -def remove_document_view(request: HttpRequest, doc_id: str): +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 account id doc_id (str): The document id Returns: """ + acc = get_object_or_404(EcoAccount, id=id) + doc = get_object_or_404(EcoAccountDocument, id=doc_id) + form = EditDocumentModalForm(request.POST or None, request.FILES or None, instance=acc, document=doc, request=request) + return form.process_request( + request, + DOCUMENT_EDITED, + reverse("compensation:acc:detail", args=(id,)) + "#related_data" + ) + + +@login_required +@default_group_required +@shared_access_required(EcoAccount, "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 account id + doc_id (str): The document id + + Returns: + + """ + acc = get_object_or_404(EcoAccount, id=id) doc = get_object_or_404(EcoAccountDocument, id=doc_id) return remove_document( request,