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 django.urls import path
|
||||||
|
|
||||||
from compensation.views.compensation.document import edit_document_view, new_document_view, remove_document_view, \
|
from compensation.views.compensation.document import EditCompensationDocumentView, NewCompensationDocumentView, \
|
||||||
get_document_view
|
GetCompensationDocumentView, RemoveCompensationDocumentView
|
||||||
from compensation.views.compensation.resubmission import CompensationResubmissionView
|
from compensation.views.compensation.resubmission import CompensationResubmissionView
|
||||||
from compensation.views.compensation.report import report_view
|
from compensation.views.compensation.report import report_view
|
||||||
from compensation.views.compensation.deadline import deadline_new_view, deadline_edit_view, deadline_remove_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'),
|
path('<id>/resub', CompensationResubmissionView.as_view(), name='resubmission-create'),
|
||||||
|
|
||||||
# Documents
|
# Documents
|
||||||
path('<id>/document/new/', new_document_view, name='new-doc'),
|
path('<id>/document/new/', NewCompensationDocumentView.as_view(), name='new-doc'),
|
||||||
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
path('<id>/document/<doc_id>', GetCompensationDocumentView.as_view(), name='get-doc'),
|
||||||
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
path('<id>/document/<doc_id>/remove/', RemoveCompensationDocumentView.as_view(), name='remove-doc'),
|
||||||
path('<id>/document/<doc_id>/edit/', edit_document_view, name='edit-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.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.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.share import share_view, create_share_view
|
||||||
from compensation.views.eco_account.document import get_document_view, new_document_view, remove_document_view, \
|
from compensation.views.eco_account.document import GetEcoAccountDocumentView, NewEcoAccountDocumentView, \
|
||||||
edit_document_view
|
EditEcoAccountDocumentView, RemoveEcoAccountDocumentView
|
||||||
from compensation.views.eco_account.deduction import deduction_edit_view, deduction_remove_view, new_deduction_view
|
from compensation.views.eco_account.deduction import deduction_edit_view, deduction_remove_view, new_deduction_view
|
||||||
|
|
||||||
app_name = "acc"
|
app_name = "acc"
|
||||||
@ -51,10 +51,10 @@ urlpatterns = [
|
|||||||
path('<id>/share', create_share_view, name='share-create'),
|
path('<id>/share', create_share_view, name='share-create'),
|
||||||
|
|
||||||
# Documents
|
# Documents
|
||||||
path('<id>/document/new/', new_document_view, name='new-doc'),
|
path('<id>/document/new/', NewEcoAccountDocumentView.as_view(), name='new-doc'),
|
||||||
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
path('<id>/document/<doc_id>', GetEcoAccountDocumentView.as_view(), name='get-doc'),
|
||||||
path('<id>/document/<doc_id>/edit', edit_document_view, name='edit-doc'),
|
path('<id>/document/<doc_id>/edit', EditEcoAccountDocumentView.as_view(), name='edit-doc'),
|
||||||
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
path('<id>/document/<doc_id>/remove/', RemoveEcoAccountDocumentView.as_view(), name='remove-doc'),
|
||||||
|
|
||||||
# Eco-account deductions
|
# Eco-account deductions
|
||||||
path('<id>/deduction/<deduction_id>/remove', deduction_remove_view, name='remove-deduction'),
|
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.contrib.auth.decorators import login_required
|
||||||
from django.http import HttpRequest
|
from django.utils.decorators import method_decorator
|
||||||
from django.shortcuts import get_object_or_404
|
|
||||||
from django.urls import reverse
|
|
||||||
|
|
||||||
from compensation.forms.modals.document import NewCompensationDocumentModalForm
|
from compensation.forms.modals.document import NewCompensationDocumentModalForm
|
||||||
from compensation.models import Compensation, CompensationDocument
|
from compensation.models import Compensation, CompensationDocument
|
||||||
from konova.decorators import shared_access_required, default_group_required
|
from konova.decorators import shared_access_required, default_group_required
|
||||||
from konova.forms.modals import EditDocumentModalForm
|
from konova.forms.modals import EditDocumentModalForm
|
||||||
from konova.utils.documents import remove_document, get_document
|
from konova.views.document import AbstractNewDocumentView, AbstractGetDocumentView, AbstractRemoveDocumentView, \
|
||||||
from konova.utils.message_templates import DOCUMENT_EDITED, DOCUMENT_ADDED
|
AbstractEditDocumentView
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class NewCompensationDocumentView(AbstractNewDocumentView):
|
||||||
@default_group_required
|
model = Compensation
|
||||||
@shared_access_required(Compensation, "id")
|
form = NewCompensationDocumentModalForm
|
||||||
def new_document_view(request: HttpRequest, id: str):
|
redirect_url = "compensation:detail"
|
||||||
""" Renders a form for uploading new documents
|
|
||||||
|
|
||||||
Args:
|
@method_decorator(login_required)
|
||||||
request (HttpRequest): The incoming request
|
@method_decorator(default_group_required)
|
||||||
id (str): The compensation's id to which the new document will be related
|
@method_decorator(shared_access_required(Compensation, "id"))
|
||||||
Returns:
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
"""
|
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class GetCompensationDocumentView(AbstractGetDocumentView):
|
||||||
@default_group_required
|
model = Compensation
|
||||||
@shared_access_required(Compensation, "id")
|
document_model = CompensationDocument
|
||||||
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.
|
@method_decorator(login_required)
|
||||||
|
@method_decorator(default_group_required)
|
||||||
Args:
|
@method_decorator(shared_access_required(Compensation, "id"))
|
||||||
request (HttpRequest): The incoming request
|
def dispatch(self, request, *args, **kwargs):
|
||||||
id (str): The compensation id
|
return super().dispatch(request, *args, **kwargs)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class RemoveCompensationDocumentView(AbstractRemoveDocumentView):
|
||||||
@default_group_required
|
model = Compensation
|
||||||
@shared_access_required(Compensation, "id")
|
document_model = CompensationDocument
|
||||||
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.
|
@method_decorator(login_required)
|
||||||
|
@method_decorator(default_group_required)
|
||||||
Args:
|
@method_decorator(shared_access_required(Compensation, "id"))
|
||||||
request (HttpRequest): The incoming request
|
def dispatch(self, request, *args, **kwargs):
|
||||||
id (str): The compensation id
|
return super().dispatch(request, *args, **kwargs)
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class EditCompensationDocumentView(AbstractEditDocumentView):
|
||||||
@default_group_required
|
model = Compensation
|
||||||
@shared_access_required(Compensation, "id")
|
document_model = CompensationDocument
|
||||||
def edit_document_view(request: HttpRequest, id: str, doc_id: str):
|
form = EditDocumentModalForm
|
||||||
""" Removes the document from the database and file system
|
redirect_url = "compensation:detail"
|
||||||
|
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@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.http import HttpRequest
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
|
||||||
from compensation.forms.modals.document import NewEcoAccountDocumentModalForm
|
from compensation.forms.modals.document import NewEcoAccountDocumentModalForm
|
||||||
from compensation.models import EcoAccount, EcoAccountDocument
|
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.forms.modals import EditDocumentModalForm
|
||||||
from konova.utils.documents import remove_document, get_document
|
from konova.utils.documents import remove_document, get_document
|
||||||
from konova.utils.message_templates import DOCUMENT_EDITED, DOCUMENT_ADDED
|
from konova.utils.message_templates import DOCUMENT_EDITED, DOCUMENT_ADDED
|
||||||
|
from konova.views.document import AbstractNewDocumentView, AbstractGetDocumentView, AbstractRemoveDocumentView, \
|
||||||
|
AbstractEditDocumentView
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class NewEcoAccountDocumentView(AbstractNewDocumentView):
|
||||||
@default_group_required
|
model = EcoAccount
|
||||||
@shared_access_required(EcoAccount, "id")
|
form = NewEcoAccountDocumentModalForm
|
||||||
def new_document_view(request: HttpRequest, id: str):
|
redirect_url = "compensation:acc:detail"
|
||||||
""" Renders a form for uploading new documents
|
|
||||||
|
|
||||||
Args:
|
@method_decorator(login_required)
|
||||||
request (HttpRequest): The incoming request
|
@method_decorator(default_group_required)
|
||||||
id (str): The account's id to which the new document will be related
|
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||||
Returns:
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
"""
|
|
||||||
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",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class GetEcoAccountDocumentView(AbstractGetDocumentView):
|
||||||
@default_group_required
|
model = EcoAccount
|
||||||
@shared_access_required(EcoAccount, "id")
|
document_model = EcoAccountDocument
|
||||||
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.
|
@method_decorator(login_required)
|
||||||
|
@method_decorator(default_group_required)
|
||||||
Args:
|
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||||
request (HttpRequest): The incoming request
|
def dispatch(self, request, *args, **kwargs):
|
||||||
id (str): The account id
|
return super().dispatch(request, *args, **kwargs)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class RemoveEcoAccountDocumentView(AbstractRemoveDocumentView):
|
||||||
@default_group_required
|
model = EcoAccount
|
||||||
@shared_access_required(EcoAccount, "id")
|
document_model = EcoAccountDocument
|
||||||
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.
|
@method_decorator(login_required)
|
||||||
|
@method_decorator(default_group_required)
|
||||||
Args:
|
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||||
request (HttpRequest): The incoming request
|
def dispatch(self, request, *args, **kwargs):
|
||||||
id (str): The account id
|
return super().dispatch(request, *args, **kwargs)
|
||||||
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
|
class EditEcoAccountDocumentView(AbstractEditDocumentView):
|
||||||
@default_group_required
|
model = EcoAccount
|
||||||
@shared_access_required(EcoAccount, "id")
|
document_model = EcoAccountDocument
|
||||||
def remove_document_view(request: HttpRequest, id: str, doc_id: str):
|
form = EditDocumentModalForm
|
||||||
""" Removes the document from the database and file system
|
redirect_url = "compensation:acc:detail"
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@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.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.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.ema import index_view, new_view, new_id_view, detail_view, edit_view, remove_view
|
||||||
from ema.views.log import EmaLogView
|
from ema.views.log import EmaLogView
|
||||||
from ema.views.record import EmaRecordView
|
from ema.views.record import EmaRecordView
|
||||||
@ -47,9 +47,9 @@ urlpatterns = [
|
|||||||
path('<id>/share', create_share_view, name='share-create'),
|
path('<id>/share', create_share_view, name='share-create'),
|
||||||
|
|
||||||
# Documents
|
# Documents
|
||||||
path('<id>/document/new/', document_new_view, name='new-doc'),
|
path('<id>/document/new/', NewEmaDocumentView.as_view(), name='new-doc'),
|
||||||
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
path('<id>/document/<doc_id>', GetEmaDocumentView.as_view(), name='get-doc'),
|
||||||
path('<id>/document/<doc_id>/edit/', edit_document_view, name='edit-doc'),
|
path('<id>/document/<doc_id>/edit/', EditEmaDocumentView.as_view(), name='edit-doc'),
|
||||||
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-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.contrib.auth.decorators import login_required
|
||||||
from django.http import HttpRequest
|
from django.utils.decorators import method_decorator
|
||||||
from django.shortcuts import get_object_or_404
|
|
||||||
from django.urls import reverse
|
|
||||||
|
|
||||||
from ema.forms import NewEmaDocumentModalForm
|
from ema.forms import NewEmaDocumentModalForm
|
||||||
from ema.models import Ema, EmaDocument
|
from ema.models import Ema, EmaDocument
|
||||||
from konova.decorators import shared_access_required, conservation_office_group_required
|
from konova.decorators import shared_access_required, conservation_office_group_required
|
||||||
from konova.forms.modals import EditDocumentModalForm
|
from konova.forms.modals import EditDocumentModalForm
|
||||||
from konova.utils.documents import get_document, remove_document
|
from konova.views.document import AbstractEditDocumentView, AbstractRemoveDocumentView, AbstractGetDocumentView, \
|
||||||
from konova.utils.message_templates import DOCUMENT_ADDED, DOCUMENT_EDITED
|
AbstractNewDocumentView
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class NewEmaDocumentView(AbstractNewDocumentView):
|
||||||
@conservation_office_group_required
|
model = Ema
|
||||||
@shared_access_required(Ema, "id")
|
form = NewEmaDocumentModalForm
|
||||||
def document_new_view(request: HttpRequest, id: str):
|
redirect_url = "ema:detail"
|
||||||
""" Renders a form for uploading new documents
|
|
||||||
|
|
||||||
Args:
|
@method_decorator(login_required)
|
||||||
request (HttpRequest): The incoming request
|
@method_decorator(conservation_office_group_required)
|
||||||
id (str): The EMA's id to which the new document will be related
|
@method_decorator(shared_access_required(Ema, "id"))
|
||||||
Returns:
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
"""
|
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class GetEmaDocumentView(AbstractGetDocumentView):
|
||||||
@conservation_office_group_required
|
model = Ema
|
||||||
@shared_access_required(Ema, "id")
|
document_model = EmaDocument
|
||||||
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.
|
@method_decorator(login_required)
|
||||||
|
@method_decorator(conservation_office_group_required)
|
||||||
Args:
|
@method_decorator(shared_access_required(Ema, "id"))
|
||||||
request (HttpRequest): The incoming request
|
def dispatch(self, request, *args, **kwargs):
|
||||||
id (str): The EMA id
|
return super().dispatch(request, *args, **kwargs)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class RemoveEmaDocumentView(AbstractRemoveDocumentView):
|
||||||
@conservation_office_group_required
|
model = Ema
|
||||||
@shared_access_required(Ema, "id")
|
document_model = EmaDocument
|
||||||
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.
|
@method_decorator(login_required)
|
||||||
|
@method_decorator(conservation_office_group_required)
|
||||||
Args:
|
@method_decorator(shared_access_required(Ema, "id"))
|
||||||
request (HttpRequest): The incoming request
|
def dispatch(self, request, *args, **kwargs):
|
||||||
id (str): The EMA id
|
return super().dispatch(request, *args, **kwargs)
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class EditEmaDocumentView(AbstractEditDocumentView):
|
||||||
@conservation_office_group_required
|
model = Ema
|
||||||
@shared_access_required(Ema, "id")
|
document_model = EmaDocument
|
||||||
def remove_document_view(request: HttpRequest, id:str, doc_id: str):
|
form = EditDocumentModalForm
|
||||||
""" Removes the document from the database and file system
|
redirect_url = "ema:detail"
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@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.check import check_view
|
||||||
from intervention.views.compensation import remove_compensation_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.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.intervention import index_view, new_view, new_id_view, detail_view, edit_view, remove_view
|
||||||
from intervention.views.log import InterventionLogView
|
from intervention.views.log import InterventionLogView
|
||||||
from intervention.views.record import InterventionRecordView
|
from intervention.views.record import InterventionRecordView
|
||||||
@ -41,10 +42,10 @@ urlpatterns = [
|
|||||||
path('<id>/compensation/<comp_id>/remove', remove_compensation_view, name='remove-compensation'),
|
path('<id>/compensation/<comp_id>/remove', remove_compensation_view, name='remove-compensation'),
|
||||||
|
|
||||||
# Documents
|
# Documents
|
||||||
path('<id>/document/new/', new_document_view, name='new-doc'),
|
path('<id>/document/new/', NewInterventionDocumentView.as_view(), name='new-doc'),
|
||||||
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
path('<id>/document/<doc_id>', GetInterventionDocumentView.as_view(), name='get-doc'),
|
||||||
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
path('<id>/document/<doc_id>/remove/', RemoveInterventionDocumentView.as_view(), name='remove-doc'),
|
||||||
path('<id>/document/<doc_id>/edit/', edit_document_view, name='edit-doc'),
|
path('<id>/document/<doc_id>/edit/', EditInterventionDocumentView.as_view(), name='edit-doc'),
|
||||||
|
|
||||||
# Deductions
|
# Deductions
|
||||||
path('<id>/deduction/new', new_deduction_view, name='new-deduction'),
|
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.contrib.auth.decorators import login_required
|
||||||
from django.http import HttpRequest
|
from django.utils.decorators import method_decorator
|
||||||
from django.shortcuts import get_object_or_404
|
|
||||||
from django.urls import reverse
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
from intervention.forms.modals.document import NewInterventionDocumentModalForm
|
from intervention.forms.modals.document import NewInterventionDocumentModalForm
|
||||||
from intervention.models import Intervention, InterventionDocument
|
from intervention.models import Intervention, InterventionDocument
|
||||||
from konova.decorators import default_group_required, shared_access_required
|
from konova.decorators import default_group_required, shared_access_required
|
||||||
from konova.forms.modals import EditDocumentModalForm
|
from konova.forms.modals import EditDocumentModalForm
|
||||||
from konova.utils.documents import get_document, remove_document
|
from konova.views.document import AbstractNewDocumentView, AbstractGetDocumentView, AbstractRemoveDocumentView, \
|
||||||
from konova.utils.message_templates import DOCUMENT_ADDED, DOCUMENT_EDITED
|
AbstractEditDocumentView
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class NewInterventionDocumentView(AbstractNewDocumentView):
|
||||||
@default_group_required
|
model = Intervention
|
||||||
@shared_access_required(Intervention, "id")
|
form = NewInterventionDocumentModalForm
|
||||||
def new_document_view(request: HttpRequest, id: str):
|
redirect_url = "intervention:detail"
|
||||||
""" Renders a form for uploading new documents
|
|
||||||
|
|
||||||
Args:
|
@method_decorator(login_required)
|
||||||
request (HttpRequest): The incoming request
|
@method_decorator(default_group_required)
|
||||||
id (str): The intervention's id to which the new document will be related
|
@method_decorator(shared_access_required(Intervention, "id"))
|
||||||
Returns:
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
"""
|
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class GetInterventionDocumentView(AbstractGetDocumentView):
|
||||||
@default_group_required
|
model = Intervention
|
||||||
@shared_access_required(Intervention, "id")
|
document_model = InterventionDocument
|
||||||
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.
|
@method_decorator(login_required)
|
||||||
|
@method_decorator(default_group_required)
|
||||||
Args:
|
@method_decorator(shared_access_required(Intervention, "id"))
|
||||||
request (HttpRequest): The incoming request
|
def dispatch(self, request, *args, **kwargs):
|
||||||
id (str): The intervention id
|
return super().dispatch(request, *args, **kwargs)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class RemoveInterventionDocumentView(AbstractRemoveDocumentView):
|
||||||
@default_group_required
|
model = Intervention
|
||||||
@shared_access_required(Intervention, "id")
|
document_model = InterventionDocument
|
||||||
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.
|
@method_decorator(login_required)
|
||||||
|
@method_decorator(default_group_required)
|
||||||
Args:
|
@method_decorator(shared_access_required(Intervention, "id"))
|
||||||
request (HttpRequest): The incoming request
|
def dispatch(self, request, *args, **kwargs):
|
||||||
id (str): The intervention id
|
return super().dispatch(request, *args, **kwargs)
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class EditInterventionDocumentView(AbstractEditDocumentView):
|
||||||
@default_group_required
|
model = Intervention
|
||||||
@shared_access_required(Intervention, "id")
|
document_model = InterventionDocument
|
||||||
def edit_document_view(request: HttpRequest, id: str, doc_id: str):
|
form = EditDocumentModalForm
|
||||||
""" Removes the document from the database and file system
|
redirect_url = "intervention:detail"
|
||||||
|
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@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