mpeltriaux
ed82109af9
* replaces function based views for creating, editing, removing and fetching documents with class based views * implemented for all major data types
69 lines
2.6 KiB
Python
69 lines
2.6 KiB
Python
"""
|
|
Author: Michel Peltriaux
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
|
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 NewEcoAccountDocumentModalForm
|
|
from compensation.models import EcoAccount, EcoAccountDocument
|
|
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
|
|
|
|
|
|
class NewEcoAccountDocumentView(AbstractNewDocumentView):
|
|
model = EcoAccount
|
|
form = NewEcoAccountDocumentModalForm
|
|
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)
|
|
|
|
|
|
class GetEcoAccountDocumentView(AbstractGetDocumentView):
|
|
model = EcoAccount
|
|
document_model = EcoAccountDocument
|
|
|
|
@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)
|
|
|
|
|
|
class RemoveEcoAccountDocumentView(AbstractRemoveDocumentView):
|
|
model = EcoAccount
|
|
document_model = EcoAccountDocument
|
|
|
|
@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)
|
|
|
|
|
|
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)
|