Document views
* replaces function based views for creating, editing, removing and fetching documents with class based views * implemented for all major data types
This commit is contained in:
parent
7b35591f5d
commit
a73046aa02
@ -7,8 +7,8 @@ Created on: 24.08.21
|
||||
"""
|
||||
from django.urls import path
|
||||
|
||||
from compensation.views.compensation.document import edit_document_view, new_document_view, remove_document_view, \
|
||||
get_document_view
|
||||
from compensation.views.compensation.document import EditCompensationDocumentView, NewCompensationDocumentView, \
|
||||
GetCompensationDocumentView, RemoveCompensationDocumentView
|
||||
from compensation.views.compensation.resubmission import CompensationResubmissionView
|
||||
from compensation.views.compensation.report import report_view
|
||||
from compensation.views.compensation.deadline import deadline_new_view, deadline_edit_view, deadline_remove_view
|
||||
@ -44,9 +44,9 @@ urlpatterns = [
|
||||
path('<id>/resub', CompensationResubmissionView.as_view(), name='resubmission-create'),
|
||||
|
||||
# Documents
|
||||
path('<id>/document/new/', new_document_view, name='new-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'),
|
||||
path('<id>/document/new/', NewCompensationDocumentView.as_view(), name='new-doc'),
|
||||
path('<id>/document/<doc_id>', GetCompensationDocumentView.as_view(), name='get-doc'),
|
||||
path('<id>/document/<doc_id>/remove/', RemoveCompensationDocumentView.as_view(), name='remove-doc'),
|
||||
path('<id>/document/<doc_id>/edit/', EditCompensationDocumentView.as_view(), name='edit-doc'),
|
||||
|
||||
]
|
@ -18,8 +18,8 @@ from compensation.views.eco_account.state import state_new_view, state_remove_vi
|
||||
from compensation.views.eco_account.action import action_edit_view, action_new_view, action_remove_view
|
||||
from compensation.views.eco_account.deadline import deadline_new_view, deadline_edit_view, deadline_remove_view
|
||||
from compensation.views.eco_account.share import share_view, create_share_view
|
||||
from compensation.views.eco_account.document import get_document_view, new_document_view, remove_document_view, \
|
||||
edit_document_view
|
||||
from compensation.views.eco_account.document import GetEcoAccountDocumentView, NewEcoAccountDocumentView, \
|
||||
EditEcoAccountDocumentView, RemoveEcoAccountDocumentView
|
||||
from compensation.views.eco_account.deduction import deduction_edit_view, deduction_remove_view, new_deduction_view
|
||||
|
||||
app_name = "acc"
|
||||
@ -51,10 +51,10 @@ urlpatterns = [
|
||||
path('<id>/share', create_share_view, name='share-create'),
|
||||
|
||||
# Documents
|
||||
path('<id>/document/new/', new_document_view, name='new-doc'),
|
||||
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
||||
path('<id>/document/<doc_id>/edit', edit_document_view, name='edit-doc'),
|
||||
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
||||
path('<id>/document/new/', NewEcoAccountDocumentView.as_view(), name='new-doc'),
|
||||
path('<id>/document/<doc_id>', GetEcoAccountDocumentView.as_view(), name='get-doc'),
|
||||
path('<id>/document/<doc_id>/edit', EditEcoAccountDocumentView.as_view(), name='edit-doc'),
|
||||
path('<id>/document/<doc_id>/remove/', RemoveEcoAccountDocumentView.as_view(), name='remove-doc'),
|
||||
|
||||
# Eco-account deductions
|
||||
path('<id>/deduction/<deduction_id>/remove', deduction_remove_view, name='remove-deduction'),
|
||||
|
@ -6,106 +6,58 @@ Created on: 19.08.22
|
||||
|
||||
"""
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
|
||||
from compensation.forms.modals.document import NewCompensationDocumentModalForm
|
||||
from compensation.models import Compensation, CompensationDocument
|
||||
from konova.decorators import shared_access_required, default_group_required
|
||||
from konova.forms.modals import EditDocumentModalForm
|
||||
from konova.utils.documents import remove_document, get_document
|
||||
from konova.utils.message_templates import DOCUMENT_EDITED, DOCUMENT_ADDED
|
||||
from konova.views.document import AbstractNewDocumentView, AbstractGetDocumentView, AbstractRemoveDocumentView, \
|
||||
AbstractEditDocumentView
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Compensation, "id")
|
||||
def new_document_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for uploading new documents
|
||||
class NewCompensationDocumentView(AbstractNewDocumentView):
|
||||
model = Compensation
|
||||
form = NewCompensationDocumentModalForm
|
||||
redirect_url = "compensation:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id to which the new document will be related
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
form = NewCompensationDocumentModalForm(request.POST or None, request.FILES or None, instance=comp, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DOCUMENT_ADDED,
|
||||
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Compensation, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Compensation, "id")
|
||||
def get_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||
""" Returns the document as downloadable file
|
||||
class GetCompensationDocumentView(AbstractGetDocumentView):
|
||||
model = Compensation
|
||||
document_model = CompensationDocument
|
||||
|
||||
Wraps the generic document fetcher function from konova.utils.
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation id
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
doc = get_object_or_404(CompensationDocument, id=doc_id)
|
||||
return get_document(doc)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Compensation, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Compensation, "id")
|
||||
def remove_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||
""" Removes the document from the database and file system
|
||||
class RemoveCompensationDocumentView(AbstractRemoveDocumentView):
|
||||
model = Compensation
|
||||
document_model = CompensationDocument
|
||||
|
||||
Wraps the generic functionality from konova.utils.
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation id
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
doc = get_object_or_404(CompensationDocument, id=doc_id)
|
||||
return remove_document(
|
||||
request,
|
||||
doc
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Compensation, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Compensation, "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 compensation id
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
doc = get_object_or_404(CompensationDocument, id=doc_id)
|
||||
form = EditDocumentModalForm(request.POST or None, request.FILES or None, instance=comp, document=doc, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
DOCUMENT_EDITED,
|
||||
reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
class EditCompensationDocumentView(AbstractEditDocumentView):
|
||||
model = Compensation
|
||||
document_model = CompensationDocument
|
||||
form = EditDocumentModalForm
|
||||
redirect_url = "compensation:detail"
|
||||
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Compensation, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
@ -9,6 +9,7 @@ from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
|
||||
from compensation.forms.modals.document import NewEcoAccountDocumentModalForm
|
||||
from compensation.models import EcoAccount, EcoAccountDocument
|
||||
@ -16,96 +17,52 @@ from konova.decorators import shared_access_required, default_group_required
|
||||
from konova.forms.modals import EditDocumentModalForm
|
||||
from konova.utils.documents import remove_document, get_document
|
||||
from konova.utils.message_templates import DOCUMENT_EDITED, DOCUMENT_ADDED
|
||||
from konova.views.document import AbstractNewDocumentView, AbstractGetDocumentView, AbstractRemoveDocumentView, \
|
||||
AbstractEditDocumentView
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def new_document_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for uploading new documents
|
||||
class NewEcoAccountDocumentView(AbstractNewDocumentView):
|
||||
model = EcoAccount
|
||||
form = NewEcoAccountDocumentModalForm
|
||||
redirect_url = "compensation:acc:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The account's id to which the new document will be related
|
||||
Returns:
|
||||
|
||||
"""
|
||||
acc = get_object_or_404(EcoAccount, id=id)
|
||||
form = NewEcoAccountDocumentModalForm(request.POST or None, request.FILES or None, instance=acc, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DOCUMENT_ADDED,
|
||||
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data",
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def get_document_view(request: HttpRequest, id:str, doc_id: str):
|
||||
""" Returns the document as downloadable file
|
||||
class GetEcoAccountDocumentView(AbstractGetDocumentView):
|
||||
model = EcoAccount
|
||||
document_model = EcoAccountDocument
|
||||
|
||||
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)
|
||||
return get_document(doc)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def edit_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||
""" Removes the document from the database and file system
|
||||
class RemoveEcoAccountDocumentView(AbstractRemoveDocumentView):
|
||||
model = EcoAccount
|
||||
document_model = EcoAccountDocument
|
||||
|
||||
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"
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@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,
|
||||
doc
|
||||
)
|
||||
class EditEcoAccountDocumentView(AbstractEditDocumentView):
|
||||
model = EcoAccount
|
||||
document_model = EcoAccountDocument
|
||||
form = EditDocumentModalForm
|
||||
redirect_url = "compensation:acc:detail"
|
||||
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
10
ema/urls.py
10
ema/urls.py
@ -9,7 +9,7 @@ from django.urls import path
|
||||
|
||||
from ema.views.action import action_new_view, action_edit_view, action_remove_view
|
||||
from ema.views.deadline import deadline_new_view, deadline_edit_view, deadline_remove_view
|
||||
from ema.views.document import document_new_view, get_document_view, remove_document_view, edit_document_view
|
||||
from ema.views.document import NewEmaDocumentView, EditEmaDocumentView, RemoveEmaDocumentView, GetEmaDocumentView
|
||||
from ema.views.ema import index_view, new_view, new_id_view, detail_view, edit_view, remove_view
|
||||
from ema.views.log import EmaLogView
|
||||
from ema.views.record import EmaRecordView
|
||||
@ -47,9 +47,9 @@ urlpatterns = [
|
||||
path('<id>/share', create_share_view, name='share-create'),
|
||||
|
||||
# Documents
|
||||
path('<id>/document/new/', document_new_view, name='new-doc'),
|
||||
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
||||
path('<id>/document/<doc_id>/edit/', edit_document_view, name='edit-doc'),
|
||||
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
||||
path('<id>/document/new/', NewEmaDocumentView.as_view(), name='new-doc'),
|
||||
path('<id>/document/<doc_id>', GetEmaDocumentView.as_view(), name='get-doc'),
|
||||
path('<id>/document/<doc_id>/edit/', EditEmaDocumentView.as_view(), name='edit-doc'),
|
||||
path('<id>/document/<doc_id>/remove/', RemoveEmaDocumentView.as_view(), name='remove-doc'),
|
||||
|
||||
]
|
@ -6,106 +6,58 @@ Created on: 19.08.22
|
||||
|
||||
"""
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
|
||||
from ema.forms import NewEmaDocumentModalForm
|
||||
from ema.models import Ema, EmaDocument
|
||||
from konova.decorators import shared_access_required, conservation_office_group_required
|
||||
from konova.forms.modals import EditDocumentModalForm
|
||||
from konova.utils.documents import get_document, remove_document
|
||||
from konova.utils.message_templates import DOCUMENT_ADDED, DOCUMENT_EDITED
|
||||
from konova.views.document import AbstractEditDocumentView, AbstractRemoveDocumentView, AbstractGetDocumentView, \
|
||||
AbstractNewDocumentView
|
||||
|
||||
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
@shared_access_required(Ema, "id")
|
||||
def document_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for uploading new documents
|
||||
class NewEmaDocumentView(AbstractNewDocumentView):
|
||||
model = Ema
|
||||
form = NewEmaDocumentModalForm
|
||||
redirect_url = "ema:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The EMA's id to which the new document will be related
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
form = NewEmaDocumentModalForm(request.POST or None, request.FILES or None, instance=ema, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DOCUMENT_ADDED,
|
||||
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(conservation_office_group_required)
|
||||
@method_decorator(shared_access_required(Ema, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
@shared_access_required(Ema, "id")
|
||||
def get_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||
""" Returns the document as downloadable file
|
||||
class GetEmaDocumentView(AbstractGetDocumentView):
|
||||
model = Ema
|
||||
document_model = EmaDocument
|
||||
|
||||
Wraps the generic document fetcher function from konova.utils.
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The EMA id
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
doc = get_object_or_404(EmaDocument, id=doc_id)
|
||||
return get_document(doc)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(conservation_office_group_required)
|
||||
@method_decorator(shared_access_required(Ema, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
@shared_access_required(Ema, "id")
|
||||
def edit_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||
""" Removes the document from the database and file system
|
||||
class RemoveEmaDocumentView(AbstractRemoveDocumentView):
|
||||
model = Ema
|
||||
document_model = EmaDocument
|
||||
|
||||
Wraps the generic functionality from konova.utils.
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The EMA id
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
doc = get_object_or_404(EmaDocument, id=doc_id)
|
||||
form = EditDocumentModalForm(request.POST or None, request.FILES or None, instance=ema, document=doc, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
DOCUMENT_EDITED,
|
||||
reverse("ema:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(conservation_office_group_required)
|
||||
@method_decorator(shared_access_required(Ema, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
@shared_access_required(Ema, "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 EMA id
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
doc = get_object_or_404(EmaDocument, id=doc_id)
|
||||
return remove_document(
|
||||
request,
|
||||
doc
|
||||
)
|
||||
class EditEmaDocumentView(AbstractEditDocumentView):
|
||||
model = Ema
|
||||
document_model = EmaDocument
|
||||
form = EditDocumentModalForm
|
||||
redirect_url = "ema:detail"
|
||||
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(conservation_office_group_required)
|
||||
@method_decorator(shared_access_required(Ema, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
@ -11,7 +11,8 @@ from intervention.autocomplete.intervention import InterventionAutocomplete
|
||||
from intervention.views.check import check_view
|
||||
from intervention.views.compensation import remove_compensation_view
|
||||
from intervention.views.deduction import new_deduction_view, edit_deduction_view, remove_deduction_view
|
||||
from intervention.views.document import new_document_view, get_document_view, remove_document_view, edit_document_view
|
||||
from intervention.views.document import NewInterventionDocumentView, GetInterventionDocumentView, \
|
||||
RemoveInterventionDocumentView, EditInterventionDocumentView
|
||||
from intervention.views.intervention import index_view, new_view, new_id_view, detail_view, edit_view, remove_view
|
||||
from intervention.views.log import InterventionLogView
|
||||
from intervention.views.record import InterventionRecordView
|
||||
@ -41,10 +42,10 @@ urlpatterns = [
|
||||
path('<id>/compensation/<comp_id>/remove', remove_compensation_view, name='remove-compensation'),
|
||||
|
||||
# Documents
|
||||
path('<id>/document/new/', new_document_view, name='new-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'),
|
||||
path('<id>/document/new/', NewInterventionDocumentView.as_view(), name='new-doc'),
|
||||
path('<id>/document/<doc_id>', GetInterventionDocumentView.as_view(), name='get-doc'),
|
||||
path('<id>/document/<doc_id>/remove/', RemoveInterventionDocumentView.as_view(), name='remove-doc'),
|
||||
path('<id>/document/<doc_id>/edit/', EditInterventionDocumentView.as_view(), name='edit-doc'),
|
||||
|
||||
# Deductions
|
||||
path('<id>/deduction/new', new_deduction_view, name='new-deduction'),
|
||||
|
@ -6,107 +6,58 @@ Created on: 19.08.22
|
||||
|
||||
"""
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.decorators import method_decorator
|
||||
|
||||
from intervention.forms.modals.document import NewInterventionDocumentModalForm
|
||||
from intervention.models import Intervention, InterventionDocument
|
||||
from konova.decorators import default_group_required, shared_access_required
|
||||
from konova.forms.modals import EditDocumentModalForm
|
||||
from konova.utils.documents import get_document, remove_document
|
||||
from konova.utils.message_templates import DOCUMENT_ADDED, DOCUMENT_EDITED
|
||||
from konova.views.document import AbstractNewDocumentView, AbstractGetDocumentView, AbstractRemoveDocumentView, \
|
||||
AbstractEditDocumentView
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Intervention, "id")
|
||||
def new_document_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for uploading new documents
|
||||
class NewInterventionDocumentView(AbstractNewDocumentView):
|
||||
model = Intervention
|
||||
form = NewInterventionDocumentModalForm
|
||||
redirect_url = "intervention:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The intervention's id to which the new document will be related
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
form = NewInterventionDocumentModalForm(request.POST or None, request.FILES or None, instance=intervention, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DOCUMENT_ADDED,
|
||||
redirect_url=reverse("intervention:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Intervention, "id")
|
||||
def get_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||
""" Returns the document as downloadable file
|
||||
class GetInterventionDocumentView(AbstractGetDocumentView):
|
||||
model = Intervention
|
||||
document_model = InterventionDocument
|
||||
|
||||
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)
|
||||
return get_document(doc)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@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
|
||||
class RemoveInterventionDocumentView(AbstractRemoveDocumentView):
|
||||
model = Intervention
|
||||
document_model = InterventionDocument
|
||||
|
||||
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,
|
||||
doc
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@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"
|
||||
)
|
||||
class EditInterventionDocumentView(AbstractEditDocumentView):
|
||||
model = Intervention
|
||||
document_model = InterventionDocument
|
||||
form = EditDocumentModalForm
|
||||
redirect_url = "intervention:detail"
|
||||
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
138
konova/views/document.py
Normal file
138
konova/views/document.py
Normal file
@ -0,0 +1,138 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||
Created on: 22.08.22
|
||||
|
||||
"""
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.views import View
|
||||
|
||||
from konova.utils.documents import get_document, remove_document
|
||||
from konova.utils.message_templates import DOCUMENT_ADDED, DOCUMENT_EDITED
|
||||
|
||||
|
||||
class AbstractNewDocumentView(View):
|
||||
model = None
|
||||
form = None
|
||||
redirect_url = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def get(self, request, id: str):
|
||||
""" Renders a form for uploading new documents
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The object's id to which the new document will be related
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(self.model, id=id)
|
||||
form = self.form(request.POST or None, request.FILES or None, instance=intervention, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DOCUMENT_ADDED,
|
||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
def post(self, request, id: str):
|
||||
return self.get(request, id)
|
||||
|
||||
|
||||
class AbstractGetDocumentView(View):
|
||||
model = None
|
||||
document_model = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def get(self, request, 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 object id
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
get_object_or_404(self.model, id=id)
|
||||
doc = get_object_or_404(self.document_model, id=doc_id)
|
||||
return get_document(doc)
|
||||
|
||||
def post(self, request, id: str, doc_id: str):
|
||||
return self.get(request, id, doc_id)
|
||||
|
||||
|
||||
class AbstractRemoveDocumentView(View):
|
||||
model = None
|
||||
document_model = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def get(self, request, 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:
|
||||
|
||||
"""
|
||||
get_object_or_404(self.model, id=id)
|
||||
doc = get_object_or_404(self.document_model, id=doc_id)
|
||||
return remove_document(
|
||||
request,
|
||||
doc
|
||||
)
|
||||
|
||||
def post(self, request, id: str, doc_id: str):
|
||||
return self.get(request, id, doc_id)
|
||||
|
||||
|
||||
class AbstractEditDocumentView(View):
|
||||
model = None
|
||||
document_model = None
|
||||
form = None
|
||||
redirect_url = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def get(self, request, id: str, doc_id: str):
|
||||
""" GET handling for editing of existing document
|
||||
|
||||
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:
|
||||
|
||||
"""
|
||||
obj = get_object_or_404(self.model, id=id)
|
||||
doc = get_object_or_404(self.document_model, id=doc_id)
|
||||
form = self.form(request.POST or None, request.FILES or None, instance=obj, document=doc,
|
||||
request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
DOCUMENT_EDITED,
|
||||
redirect_url=reverse(self.redirect_url, args=(obj.id,)) + "#related_data"
|
||||
)
|
||||
|
||||
def post(self, request, id: str, doc_id: str):
|
||||
return self.get(request, id, doc_id)
|
||||
|
Loading…
Reference in New Issue
Block a user