aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-09-29 12:03:54 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-09-29 12:41:34 +0100
commit5314ffb3308a02de8e8bd51cb4ce1784181a4a81 (patch)
tree016fdbf35b37f106bb91b00ab652e254dc4f3713
parentcf4ee94db89e697d625106e78831b7e219cd8c03 (diff)
Can now add an engagement event from org detail with only relevant people in dropdown
nearly converted engagement event form so that it is based on org tidy in prep for big change to engagement event form link to related CAF included in the OES engagements table formatting
-rw-r--r--ctrack/organisations/templates/organisations/organisation_detail.html12
-rw-r--r--ctrack/register/forms.py4
-rw-r--r--ctrack/register/models.py4
-rw-r--r--ctrack/register/templates/register/engagementevent_form.html2
-rw-r--r--ctrack/register/urls.py2
-rw-r--r--ctrack/register/views.py11
6 files changed, 27 insertions, 8 deletions
diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html
index 4af5d6f..708f5a2 100644
--- a/ctrack/organisations/templates/organisations/organisation_detail.html
+++ b/ctrack/organisations/templates/organisations/organisation_detail.html
@@ -200,7 +200,7 @@
<div class="col-md-12 my-2">
<div class="card bg-light">
<div class="card-body">
- <div class="card-title" style="font-size: 1.1rem;">OES Engagements<a href="{% url "register:create" %}"
+ <div class="card-title" style="font-size: 1.1rem;">Engagements<a href="{% url "register:create" object.slug %}"
class="btn btn-outline-primary btn-sm float-right">Add
new...</a></div>
<div class="table table-responsive">
@@ -210,6 +210,7 @@
<th>Date</th>
<th>Type</th>
<th>Description</th>
+ <th>CAF</th>
<th>Response Requested</th>
<th>Response Due</th>
</tr>
@@ -220,6 +221,11 @@
<td>{{ event.date |date:"D d M Y H:i" }}</td>
<td><a href="#">{{ event.type }}</a></td>
<td>{{ event.short_description }}</td>
+ {% if event.related_caf %}
+ <td><a href="{% url "caf:detail" event.related_caf.id %}">{{ event.related_caf }}</a></td>
+ {% else %}
+ <td>NA</td>
+ {% endif %}
{% if event.response_date_requested %}
<td style="color: {{ event.days_to_response_due.descriptor }}">{{ event.response_date_requested |date:"D d M Y" }}</td>
{% else %}
@@ -229,7 +235,7 @@
<td>{{ event.response_received | date:"D d M Y" }}</td>
{% else %}
{% if event.response_date_requested %}
- <td style="color: {{ event.days_to_response_due.descriptor }};">{{ event.days_to_response_due.days}} {{ event.days_to_response_due.day_str }}</td>
+ <td style="color: {{ event.days_to_response_due.descriptor }};">{{ event.days_to_response_due.days }} {{ event.days_to_response_due.day_str }}</td>
{% else %}
<td>NA</td>
{% endif %}
@@ -237,7 +243,7 @@
</tr>
{% endfor %}
{% else %}
- <a class="btn btn-outline-primary btn-sm" href="{% url "register:create" %}" role="button">Add
+ <a class="btn btn-outline-primary btn-sm" href="{% url "register:create" object.slug %}" role="button">Add
new...</a>
{% endif %}
</table>
diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py
index 0335149..fe3d35a 100644
--- a/ctrack/register/forms.py
+++ b/ctrack/register/forms.py
@@ -3,13 +3,15 @@ from crispy_forms.layout import Button, ButtonHolder, Layout, Submit
from django import forms
from django.urls import reverse
+from ctrack.organisations.models import Person
from ctrack.register.models import EngagementEvent
class EngagementEventCreateForm(forms.ModelForm):
- def __init__(self, *args, **kwargs):
+ def __init__(self, org_slug, *args, **kwargs):
super().__init__(*args, **kwargs)
cancel_redirect = reverse("core:home")
+ self.fields["participants"].queryset = Person.objects.filter(organisation__slug=org_slug)
self.helper = FormHelper(self)
self.helper.layout = Layout(
"type",
diff --git a/ctrack/register/models.py b/ctrack/register/models.py
index 8a01875..4231dd0 100644
--- a/ctrack/register/models.py
+++ b/ctrack/register/models.py
@@ -7,6 +7,7 @@ from django.db import models
from ctrack.caf.models import CAF
from ctrack.organisations.models import Person
+
def _style_descriptor(days: int) -> str:
if days < 1:
return "red"
@@ -22,6 +23,7 @@ def _day_string(days: int) -> str:
else:
return "day"
+
class EngagementType(models.Model):
"""
Examples here are Phone, Email, Letter, Site visit, Meeting, Audit, Inspection, etc.
@@ -78,5 +80,3 @@ class EngagementEvent(models.Model):
d = self.date.date()
iso_format_date = d.isoformat()
return f"{iso_format_date} | {self.type.descriptor} | {self.short_description}"
-
-
diff --git a/ctrack/register/templates/register/engagementevent_form.html b/ctrack/register/templates/register/engagementevent_form.html
index 972ad52..ac42c9c 100644
--- a/ctrack/register/templates/register/engagementevent_form.html
+++ b/ctrack/register/templates/register/engagementevent_form.html
@@ -10,7 +10,7 @@
<div class="container mt-3">
<div class="row">
<div class="col-md-12 pl-0 my-2">
- <h4>Register a new OES event</h4>
+ <h4>Register a new engagement event for {{ org.name }}</h4>
</div>
</div>
<div class="row">
diff --git a/ctrack/register/urls.py b/ctrack/register/urls.py
index 4d9c219..ce8c9fd 100644
--- a/ctrack/register/urls.py
+++ b/ctrack/register/urls.py
@@ -6,6 +6,6 @@ app_name = "register"
urlpatterns = [
path(
- "engagement-event/create/", view=EngagementEventCreate.as_view(), name="create"
+ "engagement-event/create/from-org/<slug:slug>", view=EngagementEventCreate.as_view(), name="create"
),
]
diff --git a/ctrack/register/views.py b/ctrack/register/views.py
index deae422..4f547f9 100644
--- a/ctrack/register/views.py
+++ b/ctrack/register/views.py
@@ -3,6 +3,7 @@ from django.http import HttpResponseRedirect
from django.urls import reverse, reverse_lazy
from django.views.generic import FormView
+from ctrack.organisations.models import Organisation
from ctrack.register.forms import EngagementEventCreateForm
@@ -15,3 +16,13 @@ class EngagementEventCreate(LoginRequiredMixin, FormView):
def form_valid(self, form):
form.save()
return HttpResponseRedirect(reverse("organisations:list"))
+
+ def get_form_kwargs(self):
+ kwargs = super().get_form_kwargs()
+ kwargs["org_slug"] = self.kwargs["slug"]
+ return kwargs
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data()
+ context["org"] = Organisation.objects.get(slug=self.kwargs["slug"])
+ return context