#86 Edit states compensation
* adds support for editing of states * adds buttons and urls for compensation
This commit is contained in:
parent
fe842cb9bc
commit
0c261196a4
@ -21,7 +21,7 @@ from konova.contexts import BaseContext
|
|||||||
from konova.forms import BaseModalForm, NewDocumentModalForm, RemoveModalForm
|
from konova.forms import BaseModalForm, NewDocumentModalForm, RemoveModalForm
|
||||||
from konova.models import DeadlineType
|
from konova.models import DeadlineType
|
||||||
from konova.utils.message_templates import FORM_INVALID, ADDED_COMPENSATION_STATE, ADDED_DEADLINE, \
|
from konova.utils.message_templates import FORM_INVALID, ADDED_COMPENSATION_STATE, ADDED_DEADLINE, \
|
||||||
ADDED_COMPENSATION_ACTION, PAYMENT_EDITED
|
ADDED_COMPENSATION_ACTION, PAYMENT_EDITED, COMPENSATION_STATE_EDITED
|
||||||
|
|
||||||
|
|
||||||
class NewPaymentForm(BaseModalForm):
|
class NewPaymentForm(BaseModalForm):
|
||||||
@ -261,6 +261,29 @@ class NewStateModalForm(BaseModalForm):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
class EditCompensationStateModalForm(NewStateModalForm):
|
||||||
|
state = None
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.state = kwargs.pop("state", None)
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
form_data = {
|
||||||
|
"biotope_type": self.state.biotope_type,
|
||||||
|
"biotope_extra": self.state.biotope_type_details.all(),
|
||||||
|
"surface": self.state.surface,
|
||||||
|
}
|
||||||
|
self.load_initial_data(form_data)
|
||||||
|
|
||||||
|
def save(self, is_before_state: bool = False):
|
||||||
|
state = self.state
|
||||||
|
state.biotope_type = self.cleaned_data.get("biotope_type", None)
|
||||||
|
state.biotope_type_details.set(self.cleaned_data.get("biotope_extra", []))
|
||||||
|
state.surface = self.cleaned_data.get("surface", None)
|
||||||
|
state.save()
|
||||||
|
self.instance.mark_as_edited(self.user, self.request, edit_comment=COMPENSATION_STATE_EDITED)
|
||||||
|
return state
|
||||||
|
|
||||||
|
|
||||||
class RemoveCompensationStateModalForm(RemoveModalForm):
|
class RemoveCompensationStateModalForm(RemoveModalForm):
|
||||||
""" Removing modal form for CompensationState
|
""" Removing modal form for CompensationState
|
||||||
|
|
||||||
|
@ -57,9 +57,12 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ state.surface|floatformat:2 }} m²</td>
|
<td>{{ state.surface|floatformat:2 }} m²</td>
|
||||||
<td>
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button data-form-url="{% url 'compensation:state-remove' obj.id state.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove state' %}">
|
<button data-form-url="{% url 'compensation:state-edit' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit state' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
|
<button data-form-url="{% url 'compensation:state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -57,9 +57,12 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ state.surface|floatformat:2 }} m²</td>
|
<td>{{ state.surface|floatformat:2 }} m²</td>
|
||||||
<td>
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button data-form-url="{% url 'compensation:state-remove' obj.id state.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove state' %}">
|
<button data-form-url="{% url 'compensation:state-edit' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit state' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
|
<button data-form-url="{% url 'compensation:state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -21,6 +21,7 @@ urlpatterns = [
|
|||||||
path('<id>/state/new', state_new_view, name='new-state'),
|
path('<id>/state/new', state_new_view, name='new-state'),
|
||||||
path('<id>/action/new', action_new_view, name='new-action'),
|
path('<id>/action/new', action_new_view, name='new-action'),
|
||||||
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
|
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
|
||||||
|
path('<id>/state/<state_id>/edit', state_edit_view, name='state-edit'),
|
||||||
path('<id>/action/<action_id>/remove', action_remove_view, name='action-remove'),
|
path('<id>/action/<action_id>/remove', action_remove_view, name='action-remove'),
|
||||||
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
|
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
|
||||||
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
|
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
|
||||||
|
@ -6,7 +6,8 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from compensation.forms.forms import NewCompensationForm, EditCompensationForm
|
from compensation.forms.forms import NewCompensationForm, EditCompensationForm
|
||||||
from compensation.forms.modalForms import NewStateModalForm, NewDeadlineModalForm, NewActionModalForm, \
|
from compensation.forms.modalForms import NewStateModalForm, NewDeadlineModalForm, NewActionModalForm, \
|
||||||
NewCompensationDocumentModalForm, RemoveCompensationActionModalForm, RemoveCompensationStateModalForm
|
NewCompensationDocumentModalForm, RemoveCompensationActionModalForm, RemoveCompensationStateModalForm, \
|
||||||
|
EditCompensationStateModalForm
|
||||||
from compensation.models import Compensation, CompensationState, CompensationAction, CompensationDocument
|
from compensation.models import Compensation, CompensationState, CompensationAction, CompensationDocument
|
||||||
from compensation.tables import CompensationTable
|
from compensation.tables import CompensationTable
|
||||||
from intervention.models import Intervention
|
from intervention.models import Intervention
|
||||||
@ -20,7 +21,7 @@ from konova.utils.generators import generate_qr_code
|
|||||||
from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DATA_UNSHARED_EXPLANATION, \
|
from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DATA_UNSHARED_EXPLANATION, \
|
||||||
CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED, \
|
CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED, \
|
||||||
COMPENSATION_STATE_REMOVED, COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, \
|
COMPENSATION_STATE_REMOVED, COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, \
|
||||||
DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED
|
DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED
|
||||||
from konova.utils.user_checks import in_group
|
from konova.utils.user_checks import in_group
|
||||||
|
|
||||||
|
|
||||||
@ -469,6 +470,30 @@ def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@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"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
@shared_access_required(Compensation, "id")
|
@shared_access_required(Compensation, "id")
|
||||||
|
Loading…
Reference in New Issue
Block a user