Compare commits
No commits in common. "09402611dc72a21384c7531574c672794ca58de3" and "7b35591f5d69612996af4c8b0fc31f607b7c0890" have entirely different histories.
09402611dc
...
7b35591f5d
@ -7,16 +7,13 @@ Created on: 24.08.21
|
|||||||
"""
|
"""
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from compensation.views.compensation.document import EditCompensationDocumentView, NewCompensationDocumentView, \
|
from compensation.views.compensation.document import edit_document_view, new_document_view, remove_document_view, \
|
||||||
GetCompensationDocumentView, RemoveCompensationDocumentView
|
get_document_view
|
||||||
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 NewCompensationDeadlineView, EditCompensationDeadlineView, \
|
from compensation.views.compensation.deadline import deadline_new_view, deadline_edit_view, deadline_remove_view
|
||||||
RemoveCompensationDeadlineView
|
from compensation.views.compensation.action import action_edit_view, action_new_view, action_remove_view
|
||||||
from compensation.views.compensation.action import NewCompensationActionView, EditCompensationActionView, \
|
from compensation.views.compensation.state import state_new_view, state_remove_view, state_edit_view
|
||||||
RemoveCompensationActionView
|
|
||||||
from compensation.views.compensation.state import NewCompensationStateView, EditCompensationStateView, \
|
|
||||||
RemoveCompensationStateView
|
|
||||||
from compensation.views.compensation.compensation import index_view, new_view, new_id_view, detail_view, edit_view, \
|
from compensation.views.compensation.compensation import index_view, new_view, new_id_view, detail_view, edit_view, \
|
||||||
remove_view
|
remove_view
|
||||||
from compensation.views.compensation.log import CompensationLogView
|
from compensation.views.compensation.log import CompensationLogView
|
||||||
@ -32,24 +29,24 @@ urlpatterns = [
|
|||||||
path('<id>/edit', edit_view, name='edit'),
|
path('<id>/edit', edit_view, name='edit'),
|
||||||
path('<id>/remove', remove_view, name='remove'),
|
path('<id>/remove', remove_view, name='remove'),
|
||||||
|
|
||||||
path('<id>/state/new', NewCompensationStateView.as_view(), name='new-state'),
|
path('<id>/state/new', state_new_view, name='new-state'),
|
||||||
path('<id>/state/<state_id>/edit', EditCompensationStateView.as_view(), name='state-edit'),
|
path('<id>/state/<state_id>/edit', state_edit_view, name='state-edit'),
|
||||||
path('<id>/state/<state_id>/remove', RemoveCompensationStateView.as_view(), name='state-remove'),
|
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
|
||||||
|
|
||||||
path('<id>/action/new', NewCompensationActionView.as_view(), name='new-action'),
|
path('<id>/action/new', action_new_view, name='new-action'),
|
||||||
path('<id>/action/<action_id>/edit', EditCompensationActionView.as_view(), name='action-edit'),
|
path('<id>/action/<action_id>/edit', action_edit_view, name='action-edit'),
|
||||||
path('<id>/action/<action_id>/remove', RemoveCompensationActionView.as_view(), name='action-remove'),
|
path('<id>/action/<action_id>/remove', action_remove_view, name='action-remove'),
|
||||||
|
|
||||||
path('<id>/deadline/new', NewCompensationDeadlineView.as_view(), name="new-deadline"),
|
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
|
||||||
path('<id>/deadline/<deadline_id>/edit', EditCompensationDeadlineView.as_view(), name='deadline-edit'),
|
path('<id>/deadline/<deadline_id>/edit', deadline_edit_view, name='deadline-edit'),
|
||||||
path('<id>/deadline/<deadline_id>/remove', RemoveCompensationDeadlineView.as_view(), name='deadline-remove'),
|
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
|
||||||
path('<id>/report', report_view, name='report'),
|
path('<id>/report', report_view, name='report'),
|
||||||
path('<id>/resub', CompensationResubmissionView.as_view(), name='resubmission-create'),
|
path('<id>/resub', CompensationResubmissionView.as_view(), name='resubmission-create'),
|
||||||
|
|
||||||
# Documents
|
# Documents
|
||||||
path('<id>/document/new/', NewCompensationDocumentView.as_view(), name='new-doc'),
|
path('<id>/document/new/', new_document_view, name='new-doc'),
|
||||||
path('<id>/document/<doc_id>', GetCompensationDocumentView.as_view(), name='get-doc'),
|
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
||||||
path('<id>/document/<doc_id>/remove/', RemoveCompensationDocumentView.as_view(), name='remove-doc'),
|
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
||||||
path('<id>/document/<doc_id>/edit/', EditCompensationDocumentView.as_view(), name='edit-doc'),
|
path('<id>/document/<doc_id>/edit/', edit_document_view, name='edit-doc'),
|
||||||
|
|
||||||
]
|
]
|
@ -14,17 +14,13 @@ from compensation.views.eco_account.log import EcoAccountLogView
|
|||||||
from compensation.views.eco_account.record import EcoAccountRecordView
|
from compensation.views.eco_account.record import EcoAccountRecordView
|
||||||
from compensation.views.eco_account.report import report_view
|
from compensation.views.eco_account.report import report_view
|
||||||
from compensation.views.eco_account.resubmission import EcoAccountResubmissionView
|
from compensation.views.eco_account.resubmission import EcoAccountResubmissionView
|
||||||
from compensation.views.eco_account.state import NewEcoAccountStateView, EditEcoAccountStateView, \
|
from compensation.views.eco_account.state import state_new_view, state_remove_view, state_edit_view
|
||||||
RemoveEcoAccountStateView
|
from compensation.views.eco_account.action import action_edit_view, action_new_view, action_remove_view
|
||||||
from compensation.views.eco_account.action import NewEcoAccountActionView, EditEcoAccountActionView, \
|
from compensation.views.eco_account.deadline import deadline_new_view, deadline_edit_view, deadline_remove_view
|
||||||
RemoveEcoAccountActionView
|
|
||||||
from compensation.views.eco_account.deadline import NewEcoAccountDeadlineView, EditEcoAccountDeadlineView, \
|
|
||||||
RemoveEcoAccountDeadlineView
|
|
||||||
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 GetEcoAccountDocumentView, NewEcoAccountDocumentView, \
|
from compensation.views.eco_account.document import get_document_view, new_document_view, remove_document_view, \
|
||||||
EditEcoAccountDocumentView, RemoveEcoAccountDocumentView
|
edit_document_view
|
||||||
from compensation.views.eco_account.deduction import NewEcoAccountDeductionView, EditEcoAccountDeductionView, \
|
from compensation.views.eco_account.deduction import deduction_edit_view, deduction_remove_view, new_deduction_view
|
||||||
RemoveEcoAccountDeductionView
|
|
||||||
|
|
||||||
app_name = "acc"
|
app_name = "acc"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@ -39,31 +35,31 @@ urlpatterns = [
|
|||||||
path('<id>/remove', remove_view, name='remove'),
|
path('<id>/remove', remove_view, name='remove'),
|
||||||
path('<id>/resub', EcoAccountResubmissionView.as_view(), name='resubmission-create'),
|
path('<id>/resub', EcoAccountResubmissionView.as_view(), name='resubmission-create'),
|
||||||
|
|
||||||
path('<id>/state/new', NewEcoAccountStateView.as_view(), name='new-state'),
|
path('<id>/state/new', state_new_view, name='new-state'),
|
||||||
path('<id>/state/<state_id>/edit', EditEcoAccountStateView.as_view(), name='state-edit'),
|
path('<id>/state/<state_id>/edit', state_edit_view, name='state-edit'),
|
||||||
path('<id>/state/<state_id>/remove', RemoveEcoAccountStateView.as_view(), name='state-remove'),
|
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
|
||||||
|
|
||||||
path('<id>/action/new', NewEcoAccountActionView.as_view(), name='new-action'),
|
path('<id>/action/new', action_new_view, name='new-action'),
|
||||||
path('<id>/action/<action_id>/edit', EditEcoAccountActionView.as_view(), name='action-edit'),
|
path('<id>/action/<action_id>/edit', action_edit_view, name='action-edit'),
|
||||||
path('<id>/action/<action_id>/remove', RemoveEcoAccountActionView.as_view(), name='action-remove'),
|
path('<id>/action/<action_id>/remove', action_remove_view, name='action-remove'),
|
||||||
|
|
||||||
path('<id>/deadline/new', NewEcoAccountDeadlineView.as_view(), name="new-deadline"),
|
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
|
||||||
path('<id>/deadline/<deadline_id>/edit', EditEcoAccountDeadlineView.as_view(), name='deadline-edit'),
|
path('<id>/deadline/<deadline_id>/edit', deadline_edit_view, name='deadline-edit'),
|
||||||
path('<id>/deadline/<deadline_id>/remove', RemoveEcoAccountDeadlineView.as_view(), name='deadline-remove'),
|
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
|
||||||
|
|
||||||
path('<id>/share/<token>', share_view, name='share'),
|
path('<id>/share/<token>', share_view, name='share'),
|
||||||
path('<id>/share', create_share_view, name='share-create'),
|
path('<id>/share', create_share_view, name='share-create'),
|
||||||
|
|
||||||
# Documents
|
# Documents
|
||||||
path('<id>/document/new/', NewEcoAccountDocumentView.as_view(), name='new-doc'),
|
path('<id>/document/new/', new_document_view, name='new-doc'),
|
||||||
path('<id>/document/<doc_id>', GetEcoAccountDocumentView.as_view(), name='get-doc'),
|
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
||||||
path('<id>/document/<doc_id>/edit', EditEcoAccountDocumentView.as_view(), name='edit-doc'),
|
path('<id>/document/<doc_id>/edit', edit_document_view, name='edit-doc'),
|
||||||
path('<id>/document/<doc_id>/remove/', RemoveEcoAccountDocumentView.as_view(), name='remove-doc'),
|
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
||||||
|
|
||||||
# Eco-account deductions
|
# Eco-account deductions
|
||||||
path('<id>/deduction/<deduction_id>/remove', RemoveEcoAccountDeductionView.as_view(), name='remove-deduction'),
|
path('<id>/deduction/<deduction_id>/remove', deduction_remove_view, name='remove-deduction'),
|
||||||
path('<id>/deduction/<deduction_id>/edit', EditEcoAccountDeductionView.as_view(), name='edit-deduction'),
|
path('<id>/deduction/<deduction_id>/edit', deduction_edit_view, name='edit-deduction'),
|
||||||
path('<id>/deduct/new', NewEcoAccountDeductionView.as_view(), name='new-deduction'),
|
path('<id>/deduct/new', new_deduction_view, name='new-deduction'),
|
||||||
|
|
||||||
# Autocomplete
|
# Autocomplete
|
||||||
path("atcmplt/eco-accounts", EcoAccountAutocomplete.as_view(), name="autocomplete"),
|
path("atcmplt/eco-accounts", EcoAccountAutocomplete.as_view(), name="autocomplete"),
|
||||||
|
@ -9,7 +9,6 @@ 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.compensation_action import RemoveCompensationActionModalForm, \
|
from compensation.forms.modals.compensation_action import RemoveCompensationActionModalForm, \
|
||||||
EditCompensationActionModalForm, NewCompensationActionModalForm
|
EditCompensationActionModalForm, NewCompensationActionModalForm
|
||||||
@ -17,38 +16,74 @@ from compensation.models import Compensation, CompensationAction
|
|||||||
from konova.decorators import shared_access_required, default_group_required
|
from konova.decorators import shared_access_required, default_group_required
|
||||||
from konova.utils.message_templates import COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_EDITED, \
|
from konova.utils.message_templates import COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_EDITED, \
|
||||||
COMPENSATION_ACTION_ADDED
|
COMPENSATION_ACTION_ADDED
|
||||||
from konova.views.action import AbstractNewCompensationActionView, AbstractEditCompensationActionView, \
|
|
||||||
AbstractRemoveCompensationActionView
|
|
||||||
|
|
||||||
|
|
||||||
class NewCompensationActionView(AbstractNewCompensationActionView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
redirect_url = "compensation:detail"
|
@shared_access_required(Compensation, "id")
|
||||||
|
def action_new_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for adding new actions for a compensation
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Compensation, "id"))
|
id (str): The compensation's id to which the new state will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
form = NewCompensationActionModalForm(request.POST or None, instance=comp, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_ACTION_ADDED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditCompensationActionView(AbstractEditCompensationActionView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
redirect_url = "compensation:detail"
|
@shared_access_required(Compensation, "id")
|
||||||
|
def action_edit_view(request: HttpRequest, id: str, action_id: str):
|
||||||
|
""" Renders a form for editing actions for a compensation
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Compensation, "id"))
|
id (str): The compensation's id
|
||||||
def dispatch(self, request, *args, **kwargs):
|
action_id (str): The action's id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
action = get_object_or_404(CompensationAction, id=action_id)
|
||||||
|
form = EditCompensationActionModalForm(request.POST or None, instance=comp, action=action, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_ACTION_EDITED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoveCompensationActionView(AbstractRemoveCompensationActionView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
redirect_url = "compensation:detail"
|
@shared_access_required(Compensation, "id")
|
||||||
|
def action_remove_view(request: HttpRequest, id: str, action_id: str):
|
||||||
|
""" Renders a form for removing a compensation action
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
id (str): The action's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
action = get_object_or_404(CompensationAction, id=action_id)
|
||||||
|
form = RemoveCompensationActionModalForm(request.POST or None, instance=comp, action=action, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_ACTION_REMOVED,
|
||||||
|
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)
|
|
||||||
|
@ -6,41 +6,84 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.http import HttpRequest
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from compensation.forms.modals.deadline import EditDeadlineModalForm, NewDeadlineModalForm
|
||||||
from compensation.models import Compensation
|
from compensation.models import Compensation
|
||||||
from konova.decorators import shared_access_required, default_group_required
|
from konova.decorators import shared_access_required, default_group_required
|
||||||
from konova.views.deadline import AbstractRemoveDeadlineView, AbstractEditDeadlineView, AbstractNewDeadlineView
|
from konova.forms.modals import RemoveDeadlineModalForm
|
||||||
|
from konova.models import Deadline
|
||||||
|
from konova.utils.message_templates import DEADLINE_REMOVED, DEADLINE_EDITED, DEADLINE_ADDED
|
||||||
|
|
||||||
|
|
||||||
class NewCompensationDeadlineView(AbstractNewDeadlineView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
redirect_url = "compensation:detail"
|
@shared_access_required(Compensation, "id")
|
||||||
|
def deadline_new_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for adding new states for a compensation
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Compensation, "id"))
|
id (str): The compensation's id to which the new state will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
form = NewDeadlineModalForm(request.POST or None, instance=comp, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_ADDED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditCompensationDeadlineView(AbstractEditDeadlineView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
redirect_url = "compensation:detail"
|
@shared_access_required(Compensation, "id")
|
||||||
|
def deadline_edit_view(request: HttpRequest, id: str, deadline_id: str):
|
||||||
|
""" Renders a form for editing deadlines from a compensation
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Compensation, "id"))
|
id (str): The compensation's id
|
||||||
def dispatch(self, request, *args, **kwargs):
|
deadline_id (str): The deadline's id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||||
|
form = EditDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_EDITED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoveCompensationDeadlineView(AbstractRemoveDeadlineView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
redirect_url = "compensation:detail"
|
@shared_access_required(Compensation, "id")
|
||||||
|
def deadline_remove_view(request: HttpRequest, id: str, deadline_id: str):
|
||||||
|
""" Renders a form for removing deadlines from a compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
deadline_id (str): The deadline's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||||
|
form = RemoveDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_REMOVED,
|
||||||
|
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)
|
|
||||||
|
@ -6,58 +6,106 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.http import HttpRequest
|
||||||
|
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.views.document import AbstractNewDocumentView, AbstractGetDocumentView, AbstractRemoveDocumentView, \
|
from konova.utils.documents import remove_document, get_document
|
||||||
AbstractEditDocumentView
|
from konova.utils.message_templates import DOCUMENT_EDITED, DOCUMENT_ADDED
|
||||||
|
|
||||||
|
|
||||||
class NewCompensationDocumentView(AbstractNewDocumentView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
form = NewCompensationDocumentModalForm
|
@shared_access_required(Compensation, "id")
|
||||||
redirect_url = "compensation:detail"
|
def new_document_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for uploading new documents
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Compensation, "id"))
|
id (str): The compensation's id to which the new document will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
Returns:
|
||||||
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GetCompensationDocumentView(AbstractGetDocumentView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
document_model = CompensationDocument
|
@shared_access_required(Compensation, "id")
|
||||||
|
def get_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||||
|
""" Returns the document as downloadable file
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Wraps the generic document fetcher function from konova.utils.
|
||||||
@method_decorator(default_group_required)
|
|
||||||
@method_decorator(shared_access_required(Compensation, "id"))
|
Args:
|
||||||
def dispatch(self, request, *args, **kwargs):
|
request (HttpRequest): The incoming request
|
||||||
return super().dispatch(request, *args, **kwargs)
|
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)
|
||||||
|
|
||||||
|
|
||||||
class RemoveCompensationDocumentView(AbstractRemoveDocumentView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
document_model = CompensationDocument
|
@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
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Wraps the generic functionality from konova.utils.
|
||||||
@method_decorator(default_group_required)
|
|
||||||
@method_decorator(shared_access_required(Compensation, "id"))
|
Args:
|
||||||
def dispatch(self, request, *args, **kwargs):
|
request (HttpRequest): The incoming request
|
||||||
return super().dispatch(request, *args, **kwargs)
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditCompensationDocumentView(AbstractEditDocumentView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
document_model = CompensationDocument
|
@shared_access_required(Compensation, "id")
|
||||||
form = EditDocumentModalForm
|
def edit_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||||
redirect_url = "compensation:detail"
|
""" 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"
|
||||||
|
)
|
||||||
|
|
||||||
@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)
|
|
||||||
|
@ -6,42 +6,84 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.http import HttpRequest
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
from compensation.models import Compensation
|
from compensation.forms.modals.state import EditCompensationStateModalForm, RemoveCompensationStateModalForm, \
|
||||||
|
NewCompensationStateModalForm
|
||||||
|
from compensation.models import Compensation, CompensationState
|
||||||
from konova.decorators import shared_access_required, default_group_required
|
from konova.decorators import shared_access_required, default_group_required
|
||||||
from konova.views.state import AbstractNewCompensationStateView, AbstractEditCompensationStateView, \
|
from konova.utils.message_templates import COMPENSATION_STATE_EDITED, COMPENSATION_STATE_REMOVED, \
|
||||||
AbstractRemoveCompensationStateView
|
COMPENSATION_STATE_ADDED
|
||||||
|
|
||||||
|
|
||||||
class NewCompensationStateView(AbstractNewCompensationStateView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
redirect_url = "compensation:detail"
|
@shared_access_required(Compensation, "id")
|
||||||
|
def state_new_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for adding new states for a compensation
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Compensation, "id"))
|
id (str): The compensation's id to which the new state will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
form = NewCompensationStateModalForm(request.POST or None, instance=comp, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_STATE_ADDED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditCompensationStateView(AbstractEditCompensationStateView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
redirect_url = "compensation:detail"
|
@shared_access_required(Compensation, "id")
|
||||||
|
def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
||||||
|
""" Renders a form for removing a compensation state
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Compensation, "id"))
|
id (str): The compensation's id
|
||||||
def dispatch(self, request, *args, **kwargs):
|
state_id (str): The state's id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
state = get_object_or_404(CompensationState, id=state_id)
|
||||||
|
form = RemoveCompensationStateModalForm(request.POST or None, instance=comp, state=state, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_STATE_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoveCompensationStateView(AbstractRemoveCompensationStateView):
|
@login_required
|
||||||
model = Compensation
|
@default_group_required
|
||||||
redirect_url = "compensation:detail"
|
@shared_access_required(Compensation, "id")
|
||||||
|
def state_edit_view(request: HttpRequest, id: str, state_id: str):
|
||||||
|
""" Renders a form for editing a compensation state
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
state_id (str): The state's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
state = get_object_or_404(CompensationState, id=state_id)
|
||||||
|
form = EditCompensationStateModalForm(request.POST or None, instance=comp, state=state, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_STATE_EDITED,
|
||||||
|
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)
|
|
||||||
|
@ -6,42 +6,84 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.http import HttpRequest
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
from compensation.models import EcoAccount
|
from compensation.forms.modals.compensation_action import EditCompensationActionModalForm, \
|
||||||
|
RemoveCompensationActionModalForm, NewCompensationActionModalForm
|
||||||
|
from compensation.models import EcoAccount, CompensationAction
|
||||||
from konova.decorators import shared_access_required, default_group_required
|
from konova.decorators import shared_access_required, default_group_required
|
||||||
from konova.views.action import AbstractNewCompensationActionView, AbstractEditCompensationActionView, \
|
from konova.utils.message_templates import COMPENSATION_ACTION_EDITED, COMPENSATION_ACTION_REMOVED, \
|
||||||
AbstractRemoveCompensationActionView
|
COMPENSATION_ACTION_ADDED
|
||||||
|
|
||||||
|
|
||||||
class NewEcoAccountActionView(AbstractNewCompensationActionView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
redirect_url = "compensation:acc:detail"
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def action_new_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for adding new actions for an eco account
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
id (str): The account's id to which the new state will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
form = NewCompensationActionModalForm(request.POST or None, instance=acc, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_ACTION_ADDED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditEcoAccountActionView(AbstractEditCompensationActionView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
redirect_url = "compensation:acc:detail"
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def action_remove_view(request: HttpRequest, id: str, action_id: str):
|
||||||
|
""" Renders a form for removing a compensation action
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
id (str): The compensation's id
|
||||||
def dispatch(self, request, *args, **kwargs):
|
id (str): The action's id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
action = get_object_or_404(CompensationAction, id=action_id)
|
||||||
|
form = RemoveCompensationActionModalForm(request.POST or None, instance=acc, action=action, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_ACTION_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoveEcoAccountActionView(AbstractRemoveCompensationActionView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
redirect_url = "compensation:acc:detail"
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def action_edit_view(request: HttpRequest, id: str, action_id: str):
|
||||||
|
""" Renders a form for editing a compensation action
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
id (str): The action's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
action = get_object_or_404(CompensationAction, id=action_id)
|
||||||
|
form = EditCompensationActionModalForm(request.POST or None, instance=acc, action=action, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_ACTION_EDITED,
|
||||||
|
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)
|
|
||||||
|
@ -6,41 +6,84 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.http import HttpRequest
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from compensation.forms.modals.deadline import NewDeadlineModalForm, EditDeadlineModalForm
|
||||||
from compensation.models import EcoAccount
|
from compensation.models import EcoAccount
|
||||||
from konova.decorators import shared_access_required, default_group_required
|
from konova.decorators import shared_access_required, default_group_required
|
||||||
from konova.views.deadline import AbstractNewDeadlineView, AbstractEditDeadlineView, AbstractRemoveDeadlineView
|
from konova.forms.modals import RemoveDeadlineModalForm
|
||||||
|
from konova.models import Deadline
|
||||||
|
from konova.utils.message_templates import DEADLINE_ADDED, DEADLINE_REMOVED, DEADLINE_EDITED
|
||||||
|
|
||||||
|
|
||||||
class NewEcoAccountDeadlineView(AbstractNewDeadlineView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
redirect_url = "compensation:acc:detail"
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def deadline_edit_view(request: HttpRequest, id: str, deadline_id: str):
|
||||||
|
""" Renders a form for editing deadlines from a compensation
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
id (str): The compensation's id
|
||||||
def dispatch(self, request, *args, **kwargs):
|
deadline_id (str): The deadline's id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(EcoAccount, id=id)
|
||||||
|
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||||
|
form = EditDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_EDITED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditEcoAccountDeadlineView(AbstractEditDeadlineView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
redirect_url = "compensation:acc:detail"
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def deadline_remove_view(request: HttpRequest, id: str, deadline_id: str):
|
||||||
|
""" Renders a form for removing deadlines from a compensation
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
id (str): The compensation's id
|
||||||
def dispatch(self, request, *args, **kwargs):
|
deadline_id (str): The deadline's id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(EcoAccount, id=id)
|
||||||
|
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||||
|
form = RemoveDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoveEcoAccountDeadlineView(AbstractRemoveDeadlineView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
redirect_url = "compensation:acc:detail"
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def deadline_new_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for adding new states for an eco account
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The account's id to which the new state will be related
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
form = NewDeadlineModalForm(request.POST or None, instance=acc, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_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)
|
|
||||||
|
@ -6,50 +6,96 @@ 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 Http404
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.utils.decorators import method_decorator
|
from django.http import HttpRequest, Http404
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
from compensation.models import EcoAccount
|
from compensation.models import EcoAccount
|
||||||
|
from intervention.forms.modals.deduction import EditEcoAccountDeductionModalForm, RemoveEcoAccountDeductionModalForm, \
|
||||||
|
NewEcoAccountDeductionModalForm
|
||||||
from konova.decorators import default_group_required
|
from konova.decorators import default_group_required
|
||||||
from konova.views.deduction import AbstractNewDeductionView, AbstractEditDeductionView, AbstractRemoveDeductionView
|
from konova.utils.message_templates import DEDUCTION_EDITED, DEDUCTION_REMOVED, DEDUCTION_ADDED
|
||||||
|
|
||||||
|
|
||||||
class NewEcoAccountDeductionView(AbstractNewDeductionView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
redirect_url = "compensation:acc:detail"
|
def new_deduction_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a modal form view for creating deductions
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): THe incoming request
|
||||||
def dispatch(self, request, *args, **kwargs):
|
id (str): The eco account's id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
|
||||||
def _custom_check(self, obj):
|
Returns:
|
||||||
if not obj.recorded:
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
if not acc.recorded:
|
||||||
raise Http404()
|
raise Http404()
|
||||||
|
form = NewEcoAccountDeductionModalForm(request.POST or None, instance=acc, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEDUCTION_ADDED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditEcoAccountDeductionView(AbstractEditDeductionView):
|
@login_required
|
||||||
def _custom_check(self, obj):
|
@default_group_required
|
||||||
pass
|
def deduction_remove_view(request: HttpRequest, id: str, deduction_id: str):
|
||||||
|
""" Renders a modal view for removing deductions
|
||||||
|
|
||||||
model = EcoAccount
|
Args:
|
||||||
redirect_url = "compensation:acc:detail"
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The eco account's id
|
||||||
|
deduction_id (str): The deduction's id
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Returns:
|
||||||
@method_decorator(default_group_required)
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
"""
|
||||||
return super().dispatch(request, *args, **kwargs)
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
try:
|
||||||
|
eco_deduction = acc.deductions.get(id=deduction_id)
|
||||||
|
if not eco_deduction.intervention.is_shared_with(request.user):
|
||||||
|
raise ObjectDoesNotExist()
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
raise Http404("Unknown deduction")
|
||||||
|
|
||||||
|
form = RemoveEcoAccountDeductionModalForm(request.POST or None, instance=acc, deduction=eco_deduction, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request=request,
|
||||||
|
msg_success=DEDUCTION_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoveEcoAccountDeductionView(AbstractRemoveDeductionView):
|
@login_required
|
||||||
def _custom_check(self, obj):
|
@default_group_required
|
||||||
pass
|
def deduction_edit_view(request: HttpRequest, id: str, deduction_id: str):
|
||||||
|
""" Renders a modal view for editing deductions
|
||||||
|
|
||||||
model = EcoAccount
|
Args:
|
||||||
redirect_url = "compensation:acc:detail"
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The eco account's id
|
||||||
|
deduction_id (str): The deduction's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
try:
|
||||||
|
eco_deduction = acc.deductions.get(id=deduction_id)
|
||||||
|
if not eco_deduction.intervention.is_shared_with(request.user):
|
||||||
|
raise ObjectDoesNotExist
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
raise Http404("Unknown deduction")
|
||||||
|
|
||||||
|
form = EditEcoAccountDeductionModalForm(request.POST or None, instance=acc, deduction=eco_deduction, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request=request,
|
||||||
|
msg_success=DEDUCTION_EDITED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
@method_decorator(login_required)
|
|
||||||
@method_decorator(default_group_required)
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ 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
|
||||||
@ -17,52 +16,96 @@ 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
|
|
||||||
|
|
||||||
|
|
||||||
class NewEcoAccountDocumentView(AbstractNewDocumentView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
form = NewEcoAccountDocumentModalForm
|
@shared_access_required(EcoAccount, "id")
|
||||||
redirect_url = "compensation:acc:detail"
|
def new_document_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for uploading new documents
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
id (str): The account's id to which the new document will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
Returns:
|
||||||
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",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GetEcoAccountDocumentView(AbstractGetDocumentView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
document_model = EcoAccountDocument
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def get_document_view(request: HttpRequest, id:str, doc_id: str):
|
||||||
|
""" Returns the document as downloadable file
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Wraps the generic document fetcher function from konova.utils.
|
||||||
@method_decorator(default_group_required)
|
|
||||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
Args:
|
||||||
def dispatch(self, request, *args, **kwargs):
|
request (HttpRequest): The incoming request
|
||||||
return super().dispatch(request, *args, **kwargs)
|
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)
|
||||||
|
|
||||||
|
|
||||||
class RemoveEcoAccountDocumentView(AbstractRemoveDocumentView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
document_model = EcoAccountDocument
|
@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
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Wraps the generic functionality from konova.utils.
|
||||||
@method_decorator(default_group_required)
|
|
||||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
Args:
|
||||||
def dispatch(self, request, *args, **kwargs):
|
request (HttpRequest): The incoming request
|
||||||
return super().dispatch(request, *args, **kwargs)
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditEcoAccountDocumentView(AbstractEditDocumentView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
document_model = EcoAccountDocument
|
@shared_access_required(EcoAccount, "id")
|
||||||
form = EditDocumentModalForm
|
def remove_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||||
redirect_url = "compensation:acc:detail"
|
""" 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
|
||||||
|
)
|
||||||
|
|
||||||
@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)
|
|
||||||
|
@ -6,42 +6,83 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.http import HttpRequest
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
from compensation.models import EcoAccount
|
from compensation.forms.modals.state import EditCompensationStateModalForm, RemoveCompensationStateModalForm, \
|
||||||
|
NewCompensationStateModalForm
|
||||||
|
from compensation.models import EcoAccount, CompensationState
|
||||||
from konova.decorators import shared_access_required, default_group_required
|
from konova.decorators import shared_access_required, default_group_required
|
||||||
from konova.views.state import AbstractNewCompensationStateView, AbstractEditCompensationStateView, \
|
from konova.utils.message_templates import COMPENSATION_STATE_EDITED, COMPENSATION_STATE_REMOVED, \
|
||||||
AbstractRemoveCompensationStateView
|
COMPENSATION_STATE_ADDED
|
||||||
|
|
||||||
|
|
||||||
class NewEcoAccountStateView(AbstractNewCompensationStateView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
redirect_url = "compensation:acc:detail"
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def state_new_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for adding new states for an eco account
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
id (str): The account's id to which the new state will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
form = NewCompensationStateModalForm(request.POST or None, instance=acc, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_STATE_ADDED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
||||||
|
""" Renders a form for removing a compensation state
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
state_id (str): The state's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
state = get_object_or_404(CompensationState, id=state_id)
|
||||||
|
form = RemoveCompensationStateModalForm(request.POST or None, instance=acc, state=state, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_STATE_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditEcoAccountStateView(AbstractEditCompensationStateView):
|
@login_required
|
||||||
model = EcoAccount
|
@default_group_required
|
||||||
redirect_url = "compensation:acc:detail"
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def state_edit_view(request: HttpRequest, id: str, state_id: str):
|
||||||
|
""" Renders a form for editing a compensation state
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
id (str): The compensation's id
|
||||||
def dispatch(self, request, *args, **kwargs):
|
state_id (str): The state's id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
class RemoveEcoAccountStateView(AbstractRemoveCompensationStateView):
|
"""
|
||||||
model = EcoAccount
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
redirect_url = "compensation:acc:detail"
|
state = get_object_or_404(CompensationState, id=state_id)
|
||||||
|
form = EditCompensationStateModalForm(request.POST or None, instance=acc, state=state, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_STATE_EDITED,
|
||||||
|
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)
|
|
||||||
|
34
ema/urls.py
34
ema/urls.py
@ -7,16 +7,16 @@ Created on: 19.08.21
|
|||||||
"""
|
"""
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from ema.views.action import NewEmaActionView, EditEmaActionView, RemoveEmaActionView
|
from ema.views.action import action_new_view, action_edit_view, action_remove_view
|
||||||
from ema.views.deadline import NewEmaDeadlineView, EditEmaDeadlineView, RemoveEmaDeadlineView
|
from ema.views.deadline import deadline_new_view, deadline_edit_view, deadline_remove_view
|
||||||
from ema.views.document import NewEmaDocumentView, EditEmaDocumentView, RemoveEmaDocumentView, GetEmaDocumentView
|
from ema.views.document import document_new_view, get_document_view, remove_document_view, edit_document_view
|
||||||
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
|
||||||
from ema.views.report import report_view
|
from ema.views.report import report_view
|
||||||
from ema.views.resubmission import EmaResubmissionView
|
from ema.views.resubmission import EmaResubmissionView
|
||||||
from ema.views.share import share_view, create_share_view
|
from ema.views.share import share_view, create_share_view
|
||||||
from ema.views.state import NewEmaStateView, EditEmaStateView, RemoveEmaStateView
|
from ema.views.state import state_new_view, state_remove_view, state_edit_view
|
||||||
|
|
||||||
app_name = "ema"
|
app_name = "ema"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@ -31,25 +31,25 @@ urlpatterns = [
|
|||||||
path('<id>/report', report_view, name='report'),
|
path('<id>/report', report_view, name='report'),
|
||||||
path('<id>/resub', EmaResubmissionView.as_view(), name='resubmission-create'),
|
path('<id>/resub', EmaResubmissionView.as_view(), name='resubmission-create'),
|
||||||
|
|
||||||
path('<id>/state/new', NewEmaStateView.as_view(), name='new-state'),
|
path('<id>/state/new', state_new_view, name='new-state'),
|
||||||
path('<id>/state/<state_id>/remove', RemoveEmaStateView.as_view(), name='state-remove'),
|
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
|
||||||
path('<id>/state/<state_id>/edit', EditEmaStateView.as_view(), name='state-edit'),
|
path('<id>/state/<state_id>/edit', state_edit_view, name='state-edit'),
|
||||||
|
|
||||||
path('<id>/action/new', NewEmaActionView.as_view(), name='new-action'),
|
path('<id>/action/new', action_new_view, name='new-action'),
|
||||||
path('<id>/action/<action_id>/edit', EditEmaActionView.as_view(), name='action-edit'),
|
path('<id>/action/<action_id>/edit', action_edit_view, name='action-edit'),
|
||||||
path('<id>/action/<action_id>/remove', RemoveEmaActionView.as_view(), name='action-remove'),
|
path('<id>/action/<action_id>/remove', action_remove_view, name='action-remove'),
|
||||||
|
|
||||||
path('<id>/deadline/new', NewEmaDeadlineView.as_view(), name="new-deadline"),
|
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
|
||||||
path('<id>/deadline/<deadline_id>/edit', EditEmaDeadlineView.as_view(), name='deadline-edit'),
|
path('<id>/deadline/<deadline_id>/edit', deadline_edit_view, name='deadline-edit'),
|
||||||
path('<id>/deadline/<deadline_id>/remove', RemoveEmaDeadlineView.as_view(), name='deadline-remove'),
|
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
|
||||||
|
|
||||||
path('<id>/share/<token>', share_view, name='share'),
|
path('<id>/share/<token>', share_view, name='share'),
|
||||||
path('<id>/share', create_share_view, name='share-create'),
|
path('<id>/share', create_share_view, name='share-create'),
|
||||||
|
|
||||||
# Documents
|
# Documents
|
||||||
path('<id>/document/new/', NewEmaDocumentView.as_view(), name='new-doc'),
|
path('<id>/document/new/', document_new_view, name='new-doc'),
|
||||||
path('<id>/document/<doc_id>', GetEmaDocumentView.as_view(), name='get-doc'),
|
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
||||||
path('<id>/document/<doc_id>/edit/', EditEmaDocumentView.as_view(), name='edit-doc'),
|
path('<id>/document/<doc_id>/edit/', edit_document_view, name='edit-doc'),
|
||||||
path('<id>/document/<doc_id>/remove/', RemoveEmaDocumentView.as_view(), name='remove-doc'),
|
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
||||||
|
|
||||||
]
|
]
|
@ -6,42 +6,84 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.http import HttpRequest
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from compensation.forms.modals.compensation_action import RemoveCompensationActionModalForm, \
|
||||||
|
EditCompensationActionModalForm, NewCompensationActionModalForm
|
||||||
|
from compensation.models import CompensationAction
|
||||||
from ema.models import Ema
|
from ema.models import Ema
|
||||||
from konova.decorators import shared_access_required, conservation_office_group_required
|
from konova.decorators import shared_access_required, conservation_office_group_required
|
||||||
from konova.views.action import AbstractNewCompensationActionView, AbstractEditCompensationActionView, \
|
from konova.utils.message_templates import COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_EDITED, \
|
||||||
AbstractRemoveCompensationActionView
|
COMPENSATION_ACTION_ADDED
|
||||||
|
|
||||||
|
|
||||||
class NewEmaActionView(AbstractNewCompensationActionView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
redirect_url = "ema:detail"
|
@shared_access_required(Ema, "id")
|
||||||
|
def action_new_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for adding new actions for an EMA
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(conservation_office_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Ema, "id"))
|
id (str): The EMA's id to which the new state will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
ema = get_object_or_404(Ema, id=id)
|
||||||
|
form = NewCompensationActionModalForm(request.POST or None, instance=ema, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_ACTION_ADDED,
|
||||||
|
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditEmaActionView(AbstractEditCompensationActionView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
redirect_url = "ema:detail"
|
@shared_access_required(Ema, "id")
|
||||||
|
def action_edit_view(request: HttpRequest, id: str, action_id: str):
|
||||||
|
""" Renders a form for editing an actions for an EMA
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(conservation_office_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Ema, "id"))
|
id (str): The EMA's id
|
||||||
def dispatch(self, request, *args, **kwargs):
|
action_id (str): The action id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
ema = get_object_or_404(Ema, id=id)
|
||||||
|
action = get_object_or_404(CompensationAction, id=action_id)
|
||||||
|
form = EditCompensationActionModalForm(request.POST or None, instance=ema, action=action, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_ACTION_EDITED,
|
||||||
|
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoveEmaActionView(AbstractRemoveCompensationActionView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
redirect_url = "ema:detail"
|
@shared_access_required(Ema, "id")
|
||||||
|
def action_remove_view(request: HttpRequest, id: str, action_id: str):
|
||||||
|
""" Renders a form for removing an EMA action
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(conservation_office_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Ema, "id"))
|
id (str): The ema id
|
||||||
def dispatch(self, request, *args, **kwargs):
|
id (str): The action's id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
ema = get_object_or_404(Ema, id=id)
|
||||||
|
action = get_object_or_404(CompensationAction, id=action_id)
|
||||||
|
form = RemoveCompensationActionModalForm(request.POST or None, instance=ema, action=action, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_ACTION_REMOVED,
|
||||||
|
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
@ -6,42 +6,85 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.http import HttpRequest
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from compensation.forms.modals.deadline import EditDeadlineModalForm, NewDeadlineModalForm
|
||||||
from ema.models import Ema
|
from ema.models import Ema
|
||||||
from konova.decorators import shared_access_required, conservation_office_group_required
|
from konova.decorators import shared_access_required, conservation_office_group_required
|
||||||
from konova.views.deadline import AbstractNewDeadlineView, AbstractRemoveDeadlineView, AbstractEditDeadlineView
|
from konova.forms.modals import RemoveDeadlineModalForm
|
||||||
|
from konova.models import Deadline
|
||||||
|
from konova.utils.message_templates import DEADLINE_REMOVED, DEADLINE_EDITED, DEADLINE_ADDED
|
||||||
|
|
||||||
|
|
||||||
class NewEmaDeadlineView(AbstractNewDeadlineView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
redirect_url = "ema:detail"
|
@shared_access_required(Ema, "id")
|
||||||
|
def deadline_new_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for adding new states for an EMA
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(conservation_office_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Ema, "id"))
|
id (str): The EMA's id to which the new state will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
ema = get_object_or_404(Ema, id=id)
|
||||||
|
form = NewDeadlineModalForm(request.POST or None, instance=ema, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_ADDED,
|
||||||
|
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditEmaDeadlineView(AbstractEditDeadlineView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
redirect_url = "ema:detail"
|
@shared_access_required(Ema, "id")
|
||||||
|
def deadline_edit_view(request: HttpRequest, id: str, deadline_id: str):
|
||||||
|
""" Renders a form for editing deadlines from a compensation
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(conservation_office_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Ema, "id"))
|
id (str): The compensation's id
|
||||||
def dispatch(self, request, *args, **kwargs):
|
deadline_id (str): The deadline's id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
ema = get_object_or_404(Ema, id=id)
|
||||||
|
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||||
|
form = EditDeadlineModalForm(request.POST or None, instance=ema, deadline=deadline, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_EDITED,
|
||||||
|
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoveEmaDeadlineView(AbstractRemoveDeadlineView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
redirect_url = "ema:detail"
|
@shared_access_required(Ema, "id")
|
||||||
|
def deadline_remove_view(request: HttpRequest, id: str, deadline_id: str):
|
||||||
|
""" Renders a form for removing deadlines from a compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
deadline_id (str): The deadline's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
ema = get_object_or_404(Ema, id=id)
|
||||||
|
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||||
|
form = RemoveDeadlineModalForm(request.POST or None, instance=ema, deadline=deadline, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_REMOVED,
|
||||||
|
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)
|
|
||||||
|
|
||||||
|
@ -6,58 +6,106 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.http import HttpRequest
|
||||||
|
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.views.document import AbstractEditDocumentView, AbstractRemoveDocumentView, AbstractGetDocumentView, \
|
from konova.utils.documents import get_document, remove_document
|
||||||
AbstractNewDocumentView
|
from konova.utils.message_templates import DOCUMENT_ADDED, DOCUMENT_EDITED
|
||||||
|
|
||||||
|
|
||||||
class NewEmaDocumentView(AbstractNewDocumentView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
form = NewEmaDocumentModalForm
|
@shared_access_required(Ema, "id")
|
||||||
redirect_url = "ema:detail"
|
def document_new_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for uploading new documents
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(conservation_office_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Ema, "id"))
|
id (str): The EMA's id to which the new document will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
Returns:
|
||||||
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GetEmaDocumentView(AbstractGetDocumentView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
document_model = EmaDocument
|
@shared_access_required(Ema, "id")
|
||||||
|
def get_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||||
|
""" Returns the document as downloadable file
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Wraps the generic document fetcher function from konova.utils.
|
||||||
@method_decorator(conservation_office_group_required)
|
|
||||||
@method_decorator(shared_access_required(Ema, "id"))
|
Args:
|
||||||
def dispatch(self, request, *args, **kwargs):
|
request (HttpRequest): The incoming request
|
||||||
return super().dispatch(request, *args, **kwargs)
|
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)
|
||||||
|
|
||||||
|
|
||||||
class RemoveEmaDocumentView(AbstractRemoveDocumentView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
document_model = EmaDocument
|
@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
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Wraps the generic functionality from konova.utils.
|
||||||
@method_decorator(conservation_office_group_required)
|
|
||||||
@method_decorator(shared_access_required(Ema, "id"))
|
Args:
|
||||||
def dispatch(self, request, *args, **kwargs):
|
request (HttpRequest): The incoming request
|
||||||
return super().dispatch(request, *args, **kwargs)
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditEmaDocumentView(AbstractEditDocumentView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
document_model = EmaDocument
|
@shared_access_required(Ema, "id")
|
||||||
form = EditDocumentModalForm
|
def remove_document_view(request: HttpRequest, id:str, doc_id: str):
|
||||||
redirect_url = "ema:detail"
|
""" 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
|
||||||
|
)
|
||||||
|
|
||||||
@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)
|
|
||||||
|
@ -6,42 +6,85 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.http import HttpRequest
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from compensation.forms.modals.state import NewCompensationStateModalForm, RemoveCompensationStateModalForm, \
|
||||||
|
EditCompensationStateModalForm
|
||||||
|
from compensation.models import CompensationState
|
||||||
from ema.models import Ema
|
from ema.models import Ema
|
||||||
from konova.decorators import conservation_office_group_required, shared_access_required
|
from konova.decorators import conservation_office_group_required, shared_access_required
|
||||||
from konova.views.state import AbstractNewCompensationStateView, AbstractEditCompensationStateView, \
|
from konova.utils.message_templates import COMPENSATION_STATE_ADDED, COMPENSATION_STATE_REMOVED, \
|
||||||
AbstractRemoveCompensationStateView
|
COMPENSATION_STATE_EDITED
|
||||||
|
|
||||||
|
|
||||||
class NewEmaStateView(AbstractNewCompensationStateView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
redirect_url = "ema:detail"
|
@shared_access_required(Ema, "id")
|
||||||
|
def state_new_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for adding new states for an EMA
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(conservation_office_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Ema, "id"))
|
id (str): The EMA's id to which the new state will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
ema = get_object_or_404(Ema, id=id)
|
||||||
|
form = NewCompensationStateModalForm(request.POST or None, instance=ema, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_STATE_ADDED,
|
||||||
|
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditEmaStateView(AbstractEditCompensationStateView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
redirect_url = "ema:detail"
|
@shared_access_required(Ema, "id")
|
||||||
|
def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
||||||
|
""" Renders a form for removing an EMA state
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(conservation_office_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Ema, "id"))
|
id (str): The ema id
|
||||||
def dispatch(self, request, *args, **kwargs):
|
state_id (str): The state's id
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
ema = get_object_or_404(Ema, id=id)
|
||||||
|
state = get_object_or_404(CompensationState, id=state_id)
|
||||||
|
form = RemoveCompensationStateModalForm(request.POST or None, instance=ema, state=state, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_STATE_REMOVED,
|
||||||
|
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoveEmaStateView(AbstractRemoveCompensationStateView):
|
@login_required
|
||||||
model = Ema
|
@conservation_office_group_required
|
||||||
redirect_url = "ema:detail"
|
@shared_access_required(Ema, "id")
|
||||||
|
def state_edit_view(request: HttpRequest, id: str, state_id: str):
|
||||||
|
""" Renders a form for editing an EMA state
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The ema id
|
||||||
|
state_id (str): The state's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
ema = get_object_or_404(Ema, id=id)
|
||||||
|
state = get_object_or_404(CompensationState, id=state_id)
|
||||||
|
form = EditCompensationStateModalForm(request.POST or None, instance=ema, state=state, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_STATE_EDITED,
|
||||||
|
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)
|
|
||||||
|
@ -10,10 +10,8 @@ from django.urls import path
|
|||||||
from intervention.autocomplete.intervention import InterventionAutocomplete
|
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 NewInterventionDeductionView, EditInterventionDeductionView, \
|
from intervention.views.deduction import new_deduction_view, edit_deduction_view, remove_deduction_view
|
||||||
RemoveInterventionDeductionView
|
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
|
||||||
@ -43,15 +41,15 @@ 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/', NewInterventionDocumentView.as_view(), name='new-doc'),
|
path('<id>/document/new/', new_document_view, name='new-doc'),
|
||||||
path('<id>/document/<doc_id>', GetInterventionDocumentView.as_view(), name='get-doc'),
|
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
||||||
path('<id>/document/<doc_id>/remove/', RemoveInterventionDocumentView.as_view(), name='remove-doc'),
|
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
||||||
path('<id>/document/<doc_id>/edit/', EditInterventionDocumentView.as_view(), name='edit-doc'),
|
path('<id>/document/<doc_id>/edit/', edit_document_view, name='edit-doc'),
|
||||||
|
|
||||||
# Deductions
|
# Deductions
|
||||||
path('<id>/deduction/new', NewInterventionDeductionView.as_view(), name='new-deduction'),
|
path('<id>/deduction/new', new_deduction_view, name='new-deduction'),
|
||||||
path('<id>/deduction/<deduction_id>/edit', EditInterventionDeductionView.as_view(), name='edit-deduction'),
|
path('<id>/deduction/<deduction_id>/edit', edit_deduction_view, name='edit-deduction'),
|
||||||
path('<id>/deduction/<deduction_id>/remove', RemoveInterventionDeductionView.as_view(), name='remove-deduction'),
|
path('<id>/deduction/<deduction_id>/remove', remove_deduction_view, name='remove-deduction'),
|
||||||
|
|
||||||
# Revocation routes
|
# Revocation routes
|
||||||
path('<id>/revocation/new', new_revocation_view, name='new-revocation'),
|
path('<id>/revocation/new', new_revocation_view, name='new-revocation'),
|
||||||
|
@ -6,50 +6,92 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
from django.http import HttpRequest, Http404
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from intervention.forms.modals.deduction import NewEcoAccountDeductionModalForm, RemoveEcoAccountDeductionModalForm, \
|
||||||
|
EditEcoAccountDeductionModalForm
|
||||||
from intervention.models import Intervention
|
from intervention.models import Intervention
|
||||||
from konova.decorators import default_group_required, shared_access_required
|
from konova.decorators import default_group_required, shared_access_required
|
||||||
from konova.views.deduction import AbstractNewDeductionView, AbstractEditDeductionView, AbstractRemoveDeductionView
|
from konova.utils.message_templates import DEDUCTION_ADDED, DEDUCTION_REMOVED, DEDUCTION_EDITED
|
||||||
|
|
||||||
|
|
||||||
class NewInterventionDeductionView(AbstractNewDeductionView):
|
@login_required
|
||||||
def _custom_check(self, obj):
|
@default_group_required
|
||||||
pass
|
@shared_access_required(Intervention, "id")
|
||||||
|
def new_deduction_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a modal form view for creating deductions
|
||||||
|
|
||||||
model = Intervention
|
Args:
|
||||||
redirect_url = "intervention:detail"
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The intervention's id which shall benefit from this deduction
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Returns:
|
||||||
@method_decorator(default_group_required)
|
|
||||||
@method_decorator(shared_access_required(Intervention, "id"))
|
"""
|
||||||
def dispatch(self, request, *args, **kwargs):
|
intervention = get_object_or_404(Intervention, id=id)
|
||||||
return super().dispatch(request, *args, **kwargs)
|
form = NewEcoAccountDeductionModalForm(request.POST or None, instance=intervention, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEDUCTION_ADDED,
|
||||||
|
redirect_url=reverse("intervention:detail", args=(id,)) + "#related_data",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditInterventionDeductionView(AbstractEditDeductionView):
|
@login_required
|
||||||
def _custom_check(self, obj):
|
@default_group_required
|
||||||
pass
|
@shared_access_required(Intervention, "id")
|
||||||
|
def remove_deduction_view(request: HttpRequest, id: str, deduction_id: str):
|
||||||
|
""" Renders a modal view for removing deductions
|
||||||
|
|
||||||
model = Intervention
|
Args:
|
||||||
redirect_url = "intervention:detail"
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The intervention's id
|
||||||
|
deduction_id (str): The deduction's id
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Returns:
|
||||||
@method_decorator(default_group_required)
|
|
||||||
@method_decorator(shared_access_required(Intervention, "id"))
|
"""
|
||||||
def dispatch(self, request, *args, **kwargs):
|
intervention = get_object_or_404(Intervention, id=id)
|
||||||
return super().dispatch(request, *args, **kwargs)
|
try:
|
||||||
|
eco_deduction = intervention.deductions.get(id=deduction_id)
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
raise Http404("Unknown deduction")
|
||||||
|
|
||||||
|
form = RemoveEcoAccountDeductionModalForm(request.POST or None, instance=intervention, deduction=eco_deduction, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request=request,
|
||||||
|
msg_success=DEDUCTION_REMOVED,
|
||||||
|
redirect_url=reverse("intervention:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoveInterventionDeductionView(AbstractRemoveDeductionView):
|
@login_required
|
||||||
def _custom_check(self, obj):
|
@default_group_required
|
||||||
pass
|
@shared_access_required(Intervention, "id")
|
||||||
|
def edit_deduction_view(request: HttpRequest, id: str, deduction_id: str):
|
||||||
|
""" Renders a modal view for removing deductions
|
||||||
|
|
||||||
model = Intervention
|
Args:
|
||||||
redirect_url = "intervention:detail"
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The intervention's id
|
||||||
|
deduction_id (str): The deduction's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
intervention = get_object_or_404(Intervention, id=id)
|
||||||
|
try:
|
||||||
|
eco_deduction = intervention.deductions.get(id=deduction_id)
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
raise Http404("Unknown deduction")
|
||||||
|
|
||||||
|
form = EditEcoAccountDeductionModalForm(request.POST or None, instance=intervention, deduction=eco_deduction, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request=request,
|
||||||
|
msg_success=DEDUCTION_EDITED,
|
||||||
|
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)
|
|
||||||
|
@ -6,58 +6,107 @@ Created on: 19.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
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 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.views.document import AbstractNewDocumentView, AbstractGetDocumentView, AbstractRemoveDocumentView, \
|
from konova.utils.documents import get_document, remove_document
|
||||||
AbstractEditDocumentView
|
from konova.utils.message_templates import DOCUMENT_ADDED, DOCUMENT_EDITED
|
||||||
|
|
||||||
|
|
||||||
class NewInterventionDocumentView(AbstractNewDocumentView):
|
@login_required
|
||||||
model = Intervention
|
@default_group_required
|
||||||
form = NewInterventionDocumentModalForm
|
@shared_access_required(Intervention, "id")
|
||||||
redirect_url = "intervention:detail"
|
def new_document_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders a form for uploading new documents
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Args:
|
||||||
@method_decorator(default_group_required)
|
request (HttpRequest): The incoming request
|
||||||
@method_decorator(shared_access_required(Intervention, "id"))
|
id (str): The intervention's id to which the new document will be related
|
||||||
def dispatch(self, request, *args, **kwargs):
|
Returns:
|
||||||
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GetInterventionDocumentView(AbstractGetDocumentView):
|
@login_required
|
||||||
model = Intervention
|
@default_group_required
|
||||||
document_model = InterventionDocument
|
@shared_access_required(Intervention, "id")
|
||||||
|
def get_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||||
|
""" Returns the document as downloadable file
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Wraps the generic document fetcher function from konova.utils.
|
||||||
@method_decorator(default_group_required)
|
|
||||||
@method_decorator(shared_access_required(Intervention, "id"))
|
Args:
|
||||||
def dispatch(self, request, *args, **kwargs):
|
request (HttpRequest): The incoming request
|
||||||
return super().dispatch(request, *args, **kwargs)
|
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)
|
||||||
|
|
||||||
|
|
||||||
class RemoveInterventionDocumentView(AbstractRemoveDocumentView):
|
@login_required
|
||||||
model = Intervention
|
@default_group_required
|
||||||
document_model = InterventionDocument
|
@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
|
||||||
|
|
||||||
@method_decorator(login_required)
|
Wraps the generic functionality from konova.utils.
|
||||||
@method_decorator(default_group_required)
|
|
||||||
@method_decorator(shared_access_required(Intervention, "id"))
|
Args:
|
||||||
def dispatch(self, request, *args, **kwargs):
|
request (HttpRequest): The incoming request
|
||||||
return super().dispatch(request, *args, **kwargs)
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditInterventionDocumentView(AbstractEditDocumentView):
|
@login_required
|
||||||
model = Intervention
|
@default_group_required
|
||||||
document_model = InterventionDocument
|
@shared_access_required(Intervention, "id")
|
||||||
form = EditDocumentModalForm
|
def edit_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||||
redirect_url = "intervention:detail"
|
""" 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"
|
||||||
|
)
|
||||||
|
|
||||||
@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)
|
|
||||||
|
@ -51,7 +51,6 @@ COMPENSATION_ACTION_REMOVED = _("Action removed")
|
|||||||
DEDUCTION_ADDED = _("Deduction added")
|
DEDUCTION_ADDED = _("Deduction added")
|
||||||
DEDUCTION_EDITED = _("Deduction edited")
|
DEDUCTION_EDITED = _("Deduction edited")
|
||||||
DEDUCTION_REMOVED = _("Deduction removed")
|
DEDUCTION_REMOVED = _("Deduction removed")
|
||||||
DEDUCTION_UNKNOWN = _("Unknown deduction")
|
|
||||||
|
|
||||||
# DEADLINE
|
# DEADLINE
|
||||||
DEADLINE_ADDED = _("Deadline added")
|
DEADLINE_ADDED = _("Deadline added")
|
||||||
|
@ -1,108 +0,0 @@
|
|||||||
"""
|
|
||||||
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 compensation.forms.modals.compensation_action import NewCompensationActionModalForm, \
|
|
||||||
EditCompensationActionModalForm, RemoveCompensationActionModalForm
|
|
||||||
from compensation.models import CompensationAction
|
|
||||||
from konova.utils.message_templates import COMPENSATION_STATE_ADDED, COMPENSATION_STATE_EDITED, \
|
|
||||||
COMPENSATION_STATE_REMOVED
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractCompensationActionView(View):
|
|
||||||
model = None
|
|
||||||
redirect_url = None
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractNewCompensationActionView(AbstractCompensationActionView):
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str):
|
|
||||||
""" Renders a form for adding new actions
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The object's id to which the new action will be related
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
form = NewCompensationActionModalForm(request.POST or None, instance=obj, request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request,
|
|
||||||
msg_success=COMPENSATION_STATE_ADDED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str):
|
|
||||||
return self.get(request, id)
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractEditCompensationActionView(AbstractCompensationActionView):
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str, action_id: str):
|
|
||||||
""" Renders a form for editing a action
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The object id
|
|
||||||
action_id (str): The action's id
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
action = get_object_or_404(CompensationAction, id=action_id)
|
|
||||||
form = EditCompensationActionModalForm(request.POST or None, instance=obj, action=action, request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request,
|
|
||||||
msg_success=COMPENSATION_STATE_EDITED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str, action_id: str):
|
|
||||||
return self.get(request, id, action_id)
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractRemoveCompensationActionView(AbstractCompensationActionView):
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str, action_id: str):
|
|
||||||
""" Renders a form for removing aaction
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The object id
|
|
||||||
action_id (str): The action's id
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
action = get_object_or_404(CompensationAction, id=action_id)
|
|
||||||
form = RemoveCompensationActionModalForm(request.POST or None, instance=obj, action=action, request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request,
|
|
||||||
msg_success=COMPENSATION_STATE_REMOVED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str, action_id: str):
|
|
||||||
return self.get(request, id, action_id)
|
|
||||||
|
|
||||||
|
|
@ -1,106 +0,0 @@
|
|||||||
"""
|
|
||||||
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 compensation.forms.modals.deadline import NewDeadlineModalForm, EditDeadlineModalForm
|
|
||||||
from konova.forms.modals import RemoveDeadlineModalForm
|
|
||||||
from konova.models import Deadline
|
|
||||||
from konova.utils.message_templates import DEADLINE_ADDED, DEADLINE_EDITED, DEADLINE_REMOVED
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractNewDeadlineView(View):
|
|
||||||
model = None
|
|
||||||
redirect_url = None
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str):
|
|
||||||
""" Renders a form for adding new deadlines
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The account's id to which the new state will be related
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
form = NewDeadlineModalForm(request.POST or None, instance=obj, request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request,
|
|
||||||
msg_success=DEADLINE_ADDED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str):
|
|
||||||
return self.get(request, id)
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractEditDeadlineView(View):
|
|
||||||
model = None
|
|
||||||
redirect_url = None
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str, deadline_id: str):
|
|
||||||
""" Renders a form for editing deadlines
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The compensation's id
|
|
||||||
deadline_id (str): The deadline's id
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
deadline = get_object_or_404(Deadline, id=deadline_id)
|
|
||||||
form = EditDeadlineModalForm(request.POST or None, instance=obj, deadline=deadline, request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request,
|
|
||||||
msg_success=DEADLINE_EDITED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str, deadline_id: str):
|
|
||||||
return self.get(request, id, deadline_id)
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractRemoveDeadlineView(View):
|
|
||||||
model = None
|
|
||||||
redirect_url = None
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str, deadline_id: str):
|
|
||||||
""" Renders a form for removing deadlines
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The compensation's id
|
|
||||||
deadline_id (str): The deadline's id
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
deadline = get_object_or_404(Deadline, id=deadline_id)
|
|
||||||
form = RemoveDeadlineModalForm(request.POST or None, instance=obj, deadline=deadline, request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request,
|
|
||||||
msg_success=DEADLINE_REMOVED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str, deadline_id: str):
|
|
||||||
return self.get(request, id, deadline_id)
|
|
@ -1,135 +0,0 @@
|
|||||||
"""
|
|
||||||
Author: Michel Peltriaux
|
|
||||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
||||||
Contact: ksp-servicestelle@sgdnord.rlp.de
|
|
||||||
Created on: 22.08.22
|
|
||||||
|
|
||||||
"""
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
|
||||||
from django.http import Http404
|
|
||||||
from django.shortcuts import get_object_or_404
|
|
||||||
from django.urls import reverse
|
|
||||||
from django.views import View
|
|
||||||
|
|
||||||
from intervention.forms.modals.deduction import NewEcoAccountDeductionModalForm, EditEcoAccountDeductionModalForm, \
|
|
||||||
RemoveEcoAccountDeductionModalForm
|
|
||||||
from konova.utils.message_templates import DEDUCTION_ADDED, DEDUCTION_EDITED, DEDUCTION_REMOVED, DEDUCTION_UNKNOWN
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractDeductionView(View):
|
|
||||||
model = None
|
|
||||||
redirect_url = None
|
|
||||||
|
|
||||||
def _custom_check(self, obj):
|
|
||||||
"""
|
|
||||||
Can be used by inheriting classes to provide custom checks before further processing
|
|
||||||
|
|
||||||
"""
|
|
||||||
raise NotImplementedError("Must be implemented in subclasses")
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractNewDeductionView(AbstractDeductionView):
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str):
|
|
||||||
""" Renders a modal form view for creating deductions
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The obj's id which shall benefit from this deduction
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
self._custom_check(obj)
|
|
||||||
form = NewEcoAccountDeductionModalForm(request.POST or None, instance=obj, request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request,
|
|
||||||
msg_success=DEDUCTION_ADDED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data",
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str):
|
|
||||||
return self.get(request, id)
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractEditDeductionView(AbstractDeductionView):
|
|
||||||
|
|
||||||
def _custom_check(self, obj):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str, deduction_id: str):
|
|
||||||
""" Renders a modal view for editing deductions
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The object's id
|
|
||||||
deduction_id (str): The deduction's id
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
self._custom_check(obj)
|
|
||||||
try:
|
|
||||||
eco_deduction = obj.deductions.get(id=deduction_id)
|
|
||||||
if not eco_deduction.intervention.is_shared_with(request.user):
|
|
||||||
raise ObjectDoesNotExist
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
raise Http404(DEDUCTION_UNKNOWN)
|
|
||||||
|
|
||||||
form = EditEcoAccountDeductionModalForm(request.POST or None, instance=obj, deduction=eco_deduction,
|
|
||||||
request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request=request,
|
|
||||||
msg_success=DEDUCTION_EDITED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str, deduction_id: str):
|
|
||||||
return self.get(request, id, deduction_id)
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractRemoveDeductionView(AbstractDeductionView):
|
|
||||||
|
|
||||||
def _custom_check(self, obj):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str, deduction_id: str):
|
|
||||||
""" Renders a modal view for removing deductions
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The object's id
|
|
||||||
deduction_id (str): The deduction's id
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
self._custom_check(obj)
|
|
||||||
try:
|
|
||||||
eco_deduction = obj.deductions.get(id=deduction_id)
|
|
||||||
if not eco_deduction.intervention.is_shared_with(request.user):
|
|
||||||
raise ObjectDoesNotExist()
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
raise Http404(DEDUCTION_UNKNOWN)
|
|
||||||
form = RemoveEcoAccountDeductionModalForm(request.POST or None, instance=obj, deduction=eco_deduction,
|
|
||||||
request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request=request,
|
|
||||||
msg_success=DEDUCTION_REMOVED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str, deduction_id: str):
|
|
||||||
return self.get(request, id, deduction_id)
|
|
@ -1,138 +0,0 @@
|
|||||||
"""
|
|
||||||
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)
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
|||||||
"""
|
|
||||||
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 compensation.forms.modals.state import NewCompensationStateModalForm, EditCompensationStateModalForm, \
|
|
||||||
RemoveCompensationStateModalForm
|
|
||||||
from compensation.models import CompensationState
|
|
||||||
from konova.utils.message_templates import COMPENSATION_STATE_ADDED, COMPENSATION_STATE_EDITED, \
|
|
||||||
COMPENSATION_STATE_REMOVED
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractCompensationStateView(View):
|
|
||||||
model = None
|
|
||||||
redirect_url = None
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractNewCompensationStateView(AbstractCompensationStateView):
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str):
|
|
||||||
""" Renders a form for adding new states
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The object's id to which the new state will be related
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
form = NewCompensationStateModalForm(request.POST or None, instance=obj, request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request,
|
|
||||||
msg_success=COMPENSATION_STATE_ADDED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str):
|
|
||||||
return self.get(request, id)
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractEditCompensationStateView(AbstractCompensationStateView):
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str, state_id: str):
|
|
||||||
""" Renders a form for editing a state
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The object id
|
|
||||||
state_id (str): The state's id
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
state = get_object_or_404(CompensationState, id=state_id)
|
|
||||||
form = EditCompensationStateModalForm(request.POST or None, instance=obj, state=state, request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request,
|
|
||||||
msg_success=COMPENSATION_STATE_EDITED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str, state_id: str):
|
|
||||||
return self.get(request, id, state_id)
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractRemoveCompensationStateView(AbstractCompensationStateView):
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
def get(self, request, id: str, state_id: str):
|
|
||||||
""" Renders a form for removing astate
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): The object id
|
|
||||||
state_id (str): The state's id
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
state = get_object_or_404(CompensationState, id=state_id)
|
|
||||||
form = RemoveCompensationStateModalForm(request.POST or None, instance=obj, state=state, request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request,
|
|
||||||
msg_success=COMPENSATION_STATE_REMOVED,
|
|
||||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str, state_id: str):
|
|
||||||
return self.get(request, id, state_id)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user