aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ctrack/organisations/admin.py1
-rw-r--r--ctrack/organisations/forms.py62
-rw-r--r--ctrack/organisations/models.py2
-rw-r--r--ctrack/organisations/templates/organisations/incidentreport_form.html5
-rw-r--r--ctrack/organisations/views.py22
5 files changed, 81 insertions, 11 deletions
diff --git a/ctrack/organisations/admin.py b/ctrack/organisations/admin.py
index ce2b21b..203baa9 100644
--- a/ctrack/organisations/admin.py
+++ b/ctrack/organisations/admin.py
@@ -24,6 +24,7 @@ get_organisation_name.short_description = "Organisation"
class IncidentReportAdmin(admin.ModelAdmin):
model = IncidentReport
+ readonly_fields = ["date_time_incident_reported"]
class AddressTypeAdmin(admin.ModelAdmin):
diff --git a/ctrack/organisations/forms.py b/ctrack/organisations/forms.py
index d98e9f0..6bcd723 100644
--- a/ctrack/organisations/forms.py
+++ b/ctrack/organisations/forms.py
@@ -1,7 +1,8 @@
from crispy_forms.helper import FormHelper
-from crispy_forms.layout import Layout, Submit
+from crispy_forms.layout import Button, ButtonHolder, Layout, Submit
from django import forms
from django.forms import inlineformset_factory
+from django.urls import reverse
from ctrack.organisations.models import Address, IncidentReport, Organisation
@@ -88,6 +89,63 @@ AddressInlineFormSet = inlineformset_factory(
)
-class IncidentReportForm(forms.Form):
+class IncidentReportForm(forms.ModelForm):
+ def __init__(self, *args, **kwargs):
+ self.org = kwargs["org"]
+ self.reporting_person = kwargs["reporting_person"]
+ kwargs.pop("org")
+ kwargs.pop("reporting_person")
+ cancel_redirect = reverse("core:home")
+ super().__init__(*args, **kwargs)
+ self.helper = FormHelper(self)
+ self.helper.layout = Layout(
+ "role",
+ "phone_number",
+ "email",
+ "internal_incident_number",
+ "date_time_incident_detected",
+ "incident_type",
+ "incident_status",
+ "incident_stage",
+ "summary",
+ "mitigations",
+ "others_informed",
+ "next_steps",
+ ButtonHolder(
+ Submit("submit", "Submit", css_class="btn-primary"),
+ Button(
+ "cancel",
+ "Cancel",
+ onclick=f"location.href='{cancel_redirect}';",
+ css_class="btn-danger",
+ ),
+ ),
+ )
+
+ def save(self, commit=True):
+ ir = super().save(commit=False)
+ ir.organisation = self.org
+ ir.reporting_person = self.reporting_person
+ if commit:
+ ir.save()
+ return ir
+
class Meta:
model = IncidentReport
+ fields = [
+ "role",
+ "phone_number",
+ "email",
+ "internal_incident_number",
+ "date_time_incident_detected",
+ "incident_type",
+ "incident_status",
+ "incident_stage",
+ "summary",
+ "mitigations",
+ "others_informed",
+ "next_steps",
+ ]
+ widgets = {
+ "date_time_incident_detected": forms.DateTimeInput(attrs={"type": "date"})
+ }
diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py
index a107829..2dd798c 100644
--- a/ctrack/organisations/models.py
+++ b/ctrack/organisations/models.py
@@ -221,7 +221,7 @@ class IncidentReport(models.Model):
help_text="This can be approximate",
)
date_time_incident_reported = models.DateTimeField(
- verbose_name="Date/Time incident reported"
+ verbose_name="Date/Time incident reported", auto_now=True
)
incident_type = models.CharField(
choices=INCIDENT_TYPES, help_text="This can be appoximate", max_length=10
diff --git a/ctrack/organisations/templates/organisations/incidentreport_form.html b/ctrack/organisations/templates/organisations/incidentreport_form.html
index 5387f56..4a0f632 100644
--- a/ctrack/organisations/templates/organisations/incidentreport_form.html
+++ b/ctrack/organisations/templates/organisations/incidentreport_form.html
@@ -20,9 +20,8 @@
<div class="col-sm-5">
<div class="card" style="width: 18rem;">
<div class="card-body">
- <h5 class="card-title">Help submitting a form</h5>
- <p class="card-text">An organisation is the parent/operating company. There is probably advice and
- proper definitions for this somewhere. Maybe if you click the link below, it will take you there?</p>
+ <h5 class="card-title">Help submitting an incident form</h5>
+ <p class="card-text">Bobbins for now..</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py
index e73792a..30ce5a0 100644
--- a/ctrack/organisations/views.py
+++ b/ctrack/organisations/views.py
@@ -6,8 +6,9 @@ from django.contrib.auth.mixins import (
UserPassesTestMixin,
)
from django.db import transaction
-from django.urls import reverse_lazy
-from django.views.generic import CreateView, DetailView, ListView
+from django.http import HttpResponseRedirect
+from django.urls import reverse, reverse_lazy
+from django.views.generic import CreateView, DetailView, FormView, ListView
from .forms import AddressInlineFormSet, IncidentReportForm, OrganisationCreateForm
from .models import IncidentReport, Organisation
@@ -73,7 +74,18 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView):
return context
-class IncidentReportCreateView(LoginRequiredMixin, CreateView):
+class IncidentReportCreateView(LoginRequiredMixin, FormView):
model = IncidentReport
- fields = "__all__"
- form = IncidentReportForm
+ form_class = IncidentReportForm
+ template_name = "organisations/incidentreport_form.html"
+ success_url = reverse_lazy("core:home")
+
+ def get_form_kwargs(self):
+ kwargs = super().get_form_kwargs()
+ kwargs["org"] = self.request.user.stakeholder.person.organisation
+ kwargs["reporting_person"] = self.request.user.stakeholder.person
+ return kwargs
+
+ def form_valid(self, form):
+ form.save()
+ return HttpResponseRedirect(reverse("core:home"))