#86 Edit document

* adds support for editing of documents
* adds buttons for intervention
This commit is contained in:
2022-02-10 10:21:18 +01:00
parent 9915e6a450
commit a385420c57
14 changed files with 247 additions and 175 deletions

View File

@@ -19,7 +19,7 @@ from django.utils.translation import gettext_lazy as _
from compensation.models import EcoAccount, EcoAccountDeduction
from intervention.inputs import TextToClipboardInput
from intervention.models import Intervention, InterventionDocument, RevocationDocument
from konova.forms import BaseModalForm, NewDocumentForm, RemoveModalForm
from konova.forms import BaseModalForm, NewDocumentModalForm, RemoveModalForm
from konova.utils.general import format_german_float
from konova.utils.user_checks import is_default_group_only
@@ -170,32 +170,6 @@ class NewRevocationModalForm(BaseModalForm):
"enctype": "multipart/form-data", # important for file upload
}
def is_valid(self):
super_valid = super().is_valid()
_file = self.cleaned_data.get("file", None)
if isinstance(_file, FieldFile):
# FieldFile declares that no new file has been uploaded and we do not need to check on the file again
return super_valid
mime_type_valid = self.document_model.is_mime_type_valid(_file)
if not mime_type_valid:
self.add_error(
"file",
FILE_TYPE_UNSUPPORTED
)
file_size_valid = self.document_model.is_file_size_valid(_file)
if not file_size_valid:
self.add_error(
"file",
FILE_SIZE_TOO_LARGE
)
file_valid = mime_type_valid and file_size_valid
return super_valid and file_valid
def save(self):
revocation = self.instance.add_revocation(self)
self.instance.mark_as_edited(self.user, self.request, edit_comment=REVOCATION_ADDED)
@@ -543,5 +517,5 @@ class RemoveEcoAccountDeductionModalForm(RemoveModalForm):
self.deduction.delete()
class NewInterventionDocumentForm(NewDocumentForm):
class NewInterventionDocumentModalForm(NewDocumentModalForm):
document_model = InterventionDocument

View File

@@ -27,7 +27,10 @@
<th scope="col">
{% trans 'Title' %}
</th>
<th class="w-50" scope="col">
<th scope="col">
{% trans 'Created on' %}
</th>
<th scope="col">
{% trans 'Comment' %}
</th>
{% if is_default_member and has_access %}
@@ -43,18 +46,26 @@
{% for doc in obj.documents.all %}
<tr>
<td>
<a href="{% url 'intervention:get-doc' doc.id %}">
<a href="{% url 'intervention:get-doc' obj.id doc.id %}">
{{ doc.title }}
</a>
</td>
<td>
<div class="scroll-150">
{{ doc.date_of_creation }}
</div>
</td>
<td>
<div class="scroll-150">
{{ doc.comment }}
</div>
</td>
<td>
<td class="align-middle float-right">
{% if is_default_member and has_access %}
<button data-form-url="{% url 'intervention:remove-doc' doc.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove document' %}">
<button data-form-url="{% url 'intervention:edit-doc' obj.id doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit document' %}">
{% fa5_icon 'edit' %}
</button>
<button data-form-url="{% url 'intervention:remove-doc' obj.id doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove document' %}">
{% fa5_icon 'trash' %}
</button>
{% endif %}

View File

@@ -10,7 +10,7 @@ from django.urls import path
from intervention.views import index_view, new_view, detail_view, edit_view, remove_view, new_document_view, share_view, \
create_share_view, remove_revocation_view, new_revocation_view, check_view, log_view, new_deduction_view, \
record_view, remove_document_view, get_document_view, get_revocation_view, new_id_view, report_view, \
remove_deduction_view, remove_compensation_view, edit_deduction_view, edit_revocation_view
remove_deduction_view, remove_compensation_view, edit_deduction_view, edit_revocation_view, edit_document_view
app_name = "intervention"
urlpatterns = [
@@ -32,8 +32,9 @@ urlpatterns = [
# Documents
path('<id>/document/new/', new_document_view, name='new-doc'),
path('document/<doc_id>', get_document_view, name='get-doc'),
path('document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
path('<id>/document/<doc_id>/edit/', edit_document_view, name='edit-doc'),
# Deductions
path('<id>/deduction/new', new_deduction_view, name='new-deduction'),

View File

@@ -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):