diff --git a/compensation/comp_urls.py b/compensation/comp_urls.py index 064570f9..5ec578b3 100644 --- a/compensation/comp_urls.py +++ b/compensation/comp_urls.py @@ -11,8 +11,9 @@ from compensation.views.compensation_views import * urlpatterns = [ # Main compensation path("", index_view, name="index"), - path('new', new_view, name='new'), path('new/id', new_id_view, name='new-id'), + path('new/', new_view, name='new'), + path('new', new_view, name='new'), path('', open_view, name='open'), path('/log', log_view, name='log'), path('/edit', edit_view, name='edit'), diff --git a/compensation/forms/forms.py b/compensation/forms/forms.py index 6f868bd2..f004e47e 100644 --- a/compensation/forms/forms.py +++ b/compensation/forms/forms.py @@ -92,10 +92,21 @@ class NewCompensationForm(BaseForm): ) def __init__(self, *args, **kwargs): + intervention_id = kwargs.pop("intervention_id", None) super().__init__(*args, **kwargs) self.form_title = _("New compensation") - self.action_url = reverse("compensation:new") - self.cancel_redirect = reverse("compensation:index") + + # If the compensation shall directly be initialized from an intervention, we need to fill in the intervention id + # and disable the form field. + # Furthermore the action_url needs to be set accordingly. + if intervention_id is not None: + self.initialize_form_field("intervention", intervention_id) + self.disable_form_field("intervention") + self.action_url = reverse("compensation:new", args=(intervention_id,)) + self.cancel_redirect = reverse("intervention:open", args=(intervention_id,)) + else: + self.action_url = reverse("compensation:new") + self.cancel_redirect = reverse("compensation:index") tmp = Compensation() identifier = tmp._generate_new_identifier() diff --git a/compensation/templates/compensation/detail/compensation/includes/comment.html b/compensation/templates/compensation/detail/compensation/includes/comment.html new file mode 100644 index 00000000..b29552e9 --- /dev/null +++ b/compensation/templates/compensation/detail/compensation/includes/comment.html @@ -0,0 +1,23 @@ +{% load i18n fontawesome_5 %} + +{% if intervention.comment %} +
+
+
+
+
+
+ {% fa5_icon 'info-circle' %} + {% trans 'Comment' %} +
+
+
+
+
+
+ {{obj.comment}} +
+
+
+
+{% endif %} \ No newline at end of file diff --git a/compensation/templates/compensation/detail/compensation/view.html b/compensation/templates/compensation/detail/compensation/view.html index 6401cdb7..20dafe75 100644 --- a/compensation/templates/compensation/detail/compensation/view.html +++ b/compensation/templates/compensation/detail/compensation/view.html @@ -99,7 +99,12 @@
- {% include 'map/geom_form.html' %} +
+ {% include 'map/geom_form.html' %} +
+
+ {% include 'compensation/detail/compensation/includes/comment.html' %} +

diff --git a/compensation/views/compensation_views.py b/compensation/views/compensation_views.py index 126527bc..65d813df 100644 --- a/compensation/views/compensation_views.py +++ b/compensation/views/compensation_views.py @@ -8,6 +8,7 @@ from compensation.forms.forms import NewCompensationForm from compensation.forms.modalForms import NewStateModalForm, NewDeadlineModalForm, NewActionModalForm from compensation.models import Compensation, CompensationState, CompensationAction, CompensationDocument from compensation.tables import CompensationTable +from intervention.models import Intervention from konova.contexts import BaseContext from konova.decorators import * from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm @@ -46,7 +47,8 @@ def index_view(request: HttpRequest): @login_required @default_group_required -def new_view(request: HttpRequest): +@shared_access_required(Intervention, "intervention_id") +def new_view(request: HttpRequest, intervention_id: str = None): """ Renders a view for a new compensation creation @@ -57,7 +59,7 @@ def new_view(request: HttpRequest): """ template = "compensation/new/view.html" - data_form = NewCompensationForm(request.POST or None) + data_form = NewCompensationForm(request.POST or None, intervention_id=intervention_id) geom_form = SimpleGeomForm(request.POST or None, read_only=False) if request.method == "POST": if data_form.is_valid() and geom_form.is_valid(): diff --git a/intervention/templates/intervention/detail/includes/comment.html b/intervention/templates/intervention/detail/includes/comment.html index 9050f4ea..5c37a420 100644 --- a/intervention/templates/intervention/detail/includes/comment.html +++ b/intervention/templates/intervention/detail/includes/comment.html @@ -1,20 +1,22 @@ {% load i18n fontawesome_5 %} {% if intervention.comment %} -
-
-
-
-
- {% fa5_icon 'info-circle' %} - {% trans 'Comment' %} -
+
+
+
+
+
+
+ {% fa5_icon 'info-circle' %} + {% trans 'Comment' %} +
+
-
-
-
- {{intervention.comment}} +
+
+ {{intervention.comment}} +
diff --git a/intervention/templates/intervention/detail/includes/compensations.html b/intervention/templates/intervention/detail/includes/compensations.html index f195d551..894c96af 100644 --- a/intervention/templates/intervention/detail/includes/compensations.html +++ b/intervention/templates/intervention/detail/includes/compensations.html @@ -11,7 +11,7 @@
{% if is_default_member and has_access %} - +