Compensation action
* adds compensation action to compensation detail view * adds adding/removing logic for compensation action * adds bootstrap style to select fields in forms * refactors UnitEnum into UnitChoices using models.TextChoices (Django 3.x) * adds translations
This commit is contained in:
+49
-2
@@ -5,8 +5,8 @@ from django.http import HttpRequest, Http404
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.forms import NewPaymentForm, NewStateModalForm, NewDeadlineModalForm
|
||||
from compensation.models import Compensation, EcoAccount, Payment, CompensationState
|
||||
from compensation.forms import NewPaymentForm, NewStateModalForm, NewDeadlineModalForm, NewActionModalForm
|
||||
from compensation.models import Compensation, EcoAccount, Payment, CompensationState, CompensationAction
|
||||
from compensation.tables import CompensationTable, EcoAccountTable
|
||||
from intervention.models import Intervention
|
||||
from konova.contexts import BaseContext
|
||||
@@ -300,6 +300,25 @@ def state_new_view(request: HttpRequest, id: str):
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def action_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new actions for a compensation
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id to which the new state will be related
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
form = NewActionModalForm(request.POST or None, instance=comp, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Action added")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def deadline_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new states for a compensation
|
||||
@@ -321,9 +340,37 @@ def deadline_new_view(request: HttpRequest, id: str):
|
||||
|
||||
@login_required
|
||||
def state_remove_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for removing a compensation state
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
state = get_object_or_404(CompensationState, id=id)
|
||||
form = RemoveModalForm(request.POST or None, instance=state, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("State removed")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def action_remove_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for removing a compensation action
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The action's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
action = get_object_or_404(CompensationAction, id=id)
|
||||
form = RemoveModalForm(request.POST or None, instance=action, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Action removed")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user