aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ctrack/caf/templates/caf/caf_detail.html111
-rw-r--r--ctrack/caf/views.py5
-rw-r--r--ctrack/organisations/tests/test_views.py1
-rw-r--r--ctrack/register/admin.py8
-rw-r--r--ctrack/register/forms.py4
-rw-r--r--ctrack/register/singledatetimeevent_update_form.html/register/engagementevent_confirm_delete.html34
-rw-r--r--ctrack/register/singledatetimeevent_update_form.html/register/engagementevent_form.html64
-rw-r--r--ctrack/register/templates/register/caf_single_date_event_form.html (renamed from ctrack/register/templates/single_datetime_event_create.html)6
-rw-r--r--ctrack/register/templates/register/single_datetime_event_create.html (renamed from ctrack/register/singledatetimeevent_update_form.html/single_datetime_event_create.html)0
-rw-r--r--ctrack/register/tests/test_views.py43
-rw-r--r--ctrack/register/urls.py7
-rw-r--r--ctrack/register/views.py27
12 files changed, 156 insertions, 154 deletions
diff --git a/ctrack/caf/templates/caf/caf_detail.html b/ctrack/caf/templates/caf/caf_detail.html
index adda474..3a73beb 100644
--- a/ctrack/caf/templates/caf/caf_detail.html
+++ b/ctrack/caf/templates/caf/caf_detail.html
@@ -58,11 +58,11 @@
<div class="col-md-12 my-2">
<div class="card bg-light">
<div class="card-body">
- <div class="card-title text-muted">CAF Basic Information</div>
+ <div class="card-title" style="font-size: 1.1rem;">Basic Information</div>
<div>
- <table class="table">
+ <table class="table table-sm table-bordered">
<tr>
- <td><strong>Organisation</strong></td>
+ <td class="w-25"><strong>Organisation</strong></td>
<td><a href="{% url 'organisations:detail' organisation.slug %}">{{ organisation }}</a></td>
</tr>
<tr>
@@ -100,20 +100,90 @@
</div>
</div>
+
+ <div class="row">
+ <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;">CAF History</div>
+ <div class="mb-2">
+ <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-calendar-date" fill="currentColor"
+ xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd"
+ d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z"/>
+ <path d="M6.445 11.688V6.354h-.633A12.6 12.6 0 0 0 4.5 7.16v.695c.375-.257.969-.62 1.258-.777h.012v4.61h.675zm1.188-1.305c.047.64.594 1.406 1.703 1.406 1.258 0 2-1.066 2-2.871 0-1.934-.781-2.668-1.953-2.668-.926 0-1.797.672-1.797 1.809 0 1.16.824 1.77 1.676 1.77.746 0 1.23-.376 1.383-.79h.027c-.004 1.316-.461 2.164-1.305 2.164-.664 0-1.008-.45-1.05-.82h-.684zm2.953-2.317c0 .696-.559 1.18-1.184 1.18-.601 0-1.144-.383-1.144-1.2 0-.823.582-1.21 1.168-1.21.633 0 1.16.398 1.16 1.23z"/>
+ </svg>
+ <a href="{% url "register:event_caf_create_single_date_event_from_caf" object.id %}">New Single Date Event</a> |
+ <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-calendar-range" fill="currentColor"
+ xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd"
+ d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z"/>
+ <path d="M9 7a1 1 0 0 1 1-1h5v2h-5a1 1 0 0 1-1-1zM1 9h4a1 1 0 0 1 0 2H1V9z"/>
+ </svg>
+ <a href="#">New Period Event</a>
+ </div>
+
+ <div class="container-fluid p-0">
+ <table class="table table-sm table-bordered table-striped">
+ <thead>
+ <tr class="d-flex">
+ <th class="col-1">Date</th>
+ <th class="col-2">Event</th>
+ <th class="col-2">Inspector</th>
+ <th class="col-3">Description</th>
+ <th class="col-4">Comments</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for event in all_events %}
+ <tr class="d-flex">
+ <td class="col-1">{{ event.date }}</td>
+ <td class="col-2">{{ event.type_descriptor }}</td>
+ <td class="col-2">{{ event.user.name }}</td>
+ <td class="col-3">{{ event.short_description }}</td>
+ <td class="col-4">{{ event.comments }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div.container>
+
+ {# <div class="list-group">#}
+ {# {% for event in single_date_events %}#}
+ {# <div class="list-group-item">#}
+ {# <div class="d-flex w-100 justify-content-between">#}
+ {# <p class="mb-1"><strong>{{ event.date|date:"j F Y" }}</strong></p>#}
+ {# <small>{{ event.type }}</small>#}
+ {# </div>#}
+ {# {% if event.comments%}#}
+ {# <p class="mb-2">{{ event.comments }}<br>#}
+ {# <small>(Inspector: {{ event.user }})</small>#}
+ {# </p>#}
+ {# {% else %}#}
+ {# <p class="mb-1"><small>No comments made.</small></p>#}
+ {# {% endif %}#}
+ {# </div>#}
+ {# {% endfor %}#}
+ {# </div>#}
+ </div>
+ </div>
+ </div>
+ </div>
+
<div class="row">
<div class="col-md-12 my-2">
<div class="card bg-light">
<div class="card-body">
- <div class="card-title text-muted">NIS Systems <a
+ <div class="card-title" style="font-size: 1.1rem;">NIS Systems <a
href="{% url "caf:as_create_from_caf" object.pk %}"
class="btn btn-outline-primary btn-sm float-right">Add
new...</a></div>
<div>
- <table class="table table-responsive">
+ <table class="table table-bordered">
{% if systems|length > 0 %}
{% for system in systems %}
<tr>
- <td><a href="{% url "caf:ass_detail" system.id %}">{{ system.name }}</a></td>
+ <td class="w-25"><a href="{% url "caf:ass_detail" system.id %}">{{ system.name }}</a></td>
<td>{{ system.function }}<br>
<a href="{% url "caf:detail" system.pk %}" class="small">
{{ system.caf }}
@@ -132,36 +202,7 @@
</div>
</div>
- <div class="row">
- <div class="col-md-12">
- <div class="card bg-light">
- <div class="card-body">
- <div class="card-title text-muted">CAF History <a href="{% url "register:create_from_caf" object.pk %}"
- class="btn btn-outline-primary btn-sm float-right">Add
- new...</a>
- </div>
- <div class="list-group">
- {% for event in object.get_events %}
- <div class="list-group-item">
- <div class="d-flex w-100 justify-content-between">
- <p class="mb-1"><strong>{{ event.date|date:"j F Y" }}</strong></p>
- <small>{{ event.type }}</small>
- </div>
- {% if event.comments%}
- <p class="mb-2">{{ event.comments }}<br>
- <small>(Inspector: {{ event.user }})</small>
- </p>
- {% else %}
- <p class="mb-1"><small>No comments made.</small></p>
- {% endif %}
- </div>
- {% endfor %}
- </div>
- </div>
- </div>
- </div>
- </div>
<div class="row">
<div class="col-md-12 my-2">
diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py
index a5d9953..e8479ab 100644
--- a/ctrack/caf/views.py
+++ b/ctrack/caf/views.py
@@ -1,3 +1,5 @@
+import itertools
+
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.http import HttpResponseRedirect
@@ -24,6 +26,8 @@ def caf_detail_view(request, pk):
assessments = caf.cafassessment_set.all()
# caf_principles = CAFPrinciple.objects.all()
_scrs = []
+ _events = list(itertools.chain(caf.cafsingledateevent_set.all(), caf.caftwindateevent_set.all()))
+ all_events = sorted(_events, key=lambda x: x.date, reverse=True)
for ass in assessments:
lst_scores = [ass, CAFAssessmentOutcomeScore.objects.filter(caf_assessment=ass)]
_scrs.append(lst_scores)
@@ -34,6 +38,7 @@ def caf_detail_view(request, pk):
"systems": caf.systems.all(),
"single_date_events": caf.cafsingledateevent_set.all(),
"twin_date_events": caf.caftwindateevent_set.all(),
+ "all_events": all_events,
}
return render(request, "caf/caf_detail.html", context)
diff --git a/ctrack/organisations/tests/test_views.py b/ctrack/organisations/tests/test_views.py
index 3584d96..e1b31fb 100644
--- a/ctrack/organisations/tests/test_views.py
+++ b/ctrack/organisations/tests/test_views.py
@@ -49,6 +49,7 @@ def test_meetings_in_organisation_detail_view(user, client, org_with_people):
assert "First Meeting" in html
+
def test_private_event_filter(user, org_with_people):
"""
In this test we are creating five events, using two different users.
diff --git a/ctrack/register/admin.py b/ctrack/register/admin.py
index c4e071d..6e6aa26 100644
--- a/ctrack/register/admin.py
+++ b/ctrack/register/admin.py
@@ -1,6 +1,6 @@
from django.contrib import admin
-from ctrack.register.models import EngagementEvent, SingleDateTimeEvent, NoteEvent
+from ctrack.register.models import EngagementEvent, SingleDateTimeEvent, NoteEvent, CAFSingleDateEvent
from ctrack.register.models import EngagementType
@@ -19,6 +19,11 @@ class SingleDateTimeEventAdmin(admin.ModelAdmin):
list_display = ("type_descriptor", "short_description", "datetime", "user", "created_date")
+class CAFSingleDateEventAdmin(admin.ModelAdmin):
+ model = CAFSingleDateEvent
+ list_display = ("type_descriptor", "date")
+
+
class NoteEventAdmin(admin.ModelAdmin):
model = NoteEvent
list_display = ("short_description", "organisation", "user")
@@ -27,4 +32,5 @@ class NoteEventAdmin(admin.ModelAdmin):
admin.site.register(EngagementEvent, EngagementEventAdmin)
admin.site.register(EngagementType, EngagementEventTypeAdmin)
admin.site.register(SingleDateTimeEvent, SingleDateTimeEventAdmin)
+admin.site.register(CAFSingleDateEvent, CAFSingleDateEventAdmin)
admin.site.register(NoteEvent, NoteEventAdmin)
diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py
index 8b0452f..512ae9d 100644
--- a/ctrack/register/forms.py
+++ b/ctrack/register/forms.py
@@ -106,14 +106,16 @@ class CAFSingleDateEventForm(forms.ModelForm):
model = CAFSingleDateEvent
fields = [
"type_descriptor",
+ "date",
"related_caf",
"short_description",
- "date",
+ "document_link",
"comments",
]
def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user")
+ self.caf_id = kwargs.pop("caf_id")
super().__init__(*args, **kwargs)
def save(self, **kwargs):
diff --git a/ctrack/register/singledatetimeevent_update_form.html/register/engagementevent_confirm_delete.html b/ctrack/register/singledatetimeevent_update_form.html/register/engagementevent_confirm_delete.html
deleted file mode 100644
index ec61949..0000000
--- a/ctrack/register/singledatetimeevent_update_form.html/register/engagementevent_confirm_delete.html
+++ /dev/null
@@ -1,34 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}
- Confirm Deletion
-{% endblock title %}
-
-{% load crispy_forms_tags %}
-
-{% block content %}
- <div class="container mt-3">
- <div class="row">
- <div class="col-6 offset-md-2 pt-3">
- <div class="card">
- <div class="card-body">
- <h5 class="card-title">Confirm deletion</h5>
- <div class="card-text">Are you sure you want to delete the event <strong>{{ object.type.descriptor }} | {{ object.short_description }}</strong>?</div>
- <div class="card-text">
- <p>This event was created by <strong>{{ object.user }}</strong> - ensure you have their permission.</p>
- </div>
- <div class="col p-2">
- <form method="post">
- {% csrf_token %}
- <div class="form-row">
- <button type="submit" class="btn btn-danger m-1" value="Confirm" id="submit-button">Delete</button>
- <a href="{{ view.get_success_url }}" class="btn btn-primary m-1">Cancel</a>
- </div>
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
-{% endblock content %}
diff --git a/ctrack/register/singledatetimeevent_update_form.html/register/engagementevent_form.html b/ctrack/register/singledatetimeevent_update_form.html/register/engagementevent_form.html
deleted file mode 100644
index 014f9b3..0000000
--- a/ctrack/register/singledatetimeevent_update_form.html/register/engagementevent_form.html
+++ /dev/null
@@ -1,64 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}
- Register a new OES event
-{% endblock title %}
-
-{% load crispy_forms_tags %}
-
-{% block content %}
-
- <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
- <script>
- $(document).ready(function () {
-
- $("#id_type").change(function () {
- const selected = $("#id_type option:selected").text();
- if (selected.includes("CAF")) {
- $("#caf_alert").removeAttr('hidden');
- $("#div_id_related_caf").addClass("border rounded p-3 border-danger");
- $("select[name=related_caf] option:eq(1)").attr("selected", "selected");
- } else {
- $("#caf_alert").prop("hidden", true);
- $("#div_id_related_caf").removeClass("border rounded p-3 border-danger");
- $("select[name=related_caf] option:eq(0)").attr("selected", "selected");
- }
- });
- });
- </script>
-
-
- <div class="container mt-3">
- <div class="row">
- <div class="col-md-12 pl-0 my-2">
- <h4>Register a new event</h4>
- </div>
- </div>
- <div class="row">
- <div class="col-md-12 pl-0 my-2 bg-light">
- <h3 class="text-secondary">{{ org.name }}</h3>
- </div>
- </div>
- <div class="row">
- <div class="col-md-7 py-2 mb-3 border bg-light">
- <div hidden id="caf_alert" class="alert alert-danger" role="alert">
- If selecting a CAF type here, you must select the CAF this event applies to in
- the "Related CAFs" field below.
- </div>
- {% crispy form %}
- </div>
- <div class="col-md-5">
- <div class="card">
- <div class="card-body">
- <h5 class="card-title">Help on Engagement Events</h5>
- <p class="card-text">All key events in the compliance lifecycle need to be registered.</p>
- <p class="card-text">Events can be <em>singular</em> (such as an email) or <em>periodic</em> (such as a CAF
- analysis period).</p>
- <p class="card-text">All events should be registered here.</p>
- <a href="#" class="btn btn-primary">Go somewhere</a>
- </div>
- </div>
- </div>
- </div>
- </div>
-{% endblock content %}
diff --git a/ctrack/register/templates/single_datetime_event_create.html b/ctrack/register/templates/register/caf_single_date_event_form.html
index d88d19a..98344db 100644
--- a/ctrack/register/templates/single_datetime_event_create.html
+++ b/ctrack/register/templates/register/caf_single_date_event_form.html
@@ -4,11 +4,7 @@
{% load crispy_forms_tags %}
{% block form %}
- {% if org %}
- <h3 class="mt-2">Create a new simple event involving {{ org }}</h3>
- {% else %}
- <h3 class="mt-2">Create a new simple event</h3>
- {% endif %}
+ <h3 class="mt-2">Register a single date event for {{ caf.version }} ({{ caf.organisation.name }})</h3>
<p>Simple events are emails, phone calls, basic meetings, notes, deadlines, etc.
If you arrived at this page from an organisation's page, you are able to select
participants in the event from that organisation.</p>
diff --git a/ctrack/register/singledatetimeevent_update_form.html/single_datetime_event_create.html b/ctrack/register/templates/register/single_datetime_event_create.html
index d88d19a..d88d19a 100644
--- a/ctrack/register/singledatetimeevent_update_form.html/single_datetime_event_create.html
+++ b/ctrack/register/templates/register/single_datetime_event_create.html
diff --git a/ctrack/register/tests/test_views.py b/ctrack/register/tests/test_views.py
index 9887942..0876332 100644
--- a/ctrack/register/tests/test_views.py
+++ b/ctrack/register/tests/test_views.py
@@ -2,6 +2,8 @@ import pytest
from django.test import TestCase
from django.urls import reverse
+from ctrack.caf.models import CAF
+from ctrack.caf.tests.factories import CAFFactory
from ctrack.organisations.tests.factories import SingleDateTimeEventFactory
from ctrack.register.views import SingleDateTimeEventCreate
@@ -66,10 +68,17 @@ class TestSingleDateTimeEvent:
"datetime": good_date,
"comments": "Blah...",
"location": "The Moon",
- "participants": org_with_people.get_people()
+ "participants": org_with_people.get_people(),
}
client.force_login(cct_user)
- response = client.post(reverse("register:event_create_simple_event_from_org", args=[org_with_people.slug]), data, follow=True)
+ response = client.post(
+ reverse(
+ "register:event_create_simple_event_from_org",
+ args=[org_with_people.slug],
+ ),
+ data,
+ follow=True,
+ )
test_case.assertRedirects(
response,
reverse("organisations:detail", args=[org_with_people.slug]),
@@ -144,20 +153,23 @@ class TestSingleDateTimeEvent:
view.setup(request)
assert "org_slug" in view.get_form_kwargs()
- def test_meeting_type_and_org_passed_as_kwarg(
- self, user, org, request_factory
- ):
+ def test_meeting_type_and_org_passed_as_kwarg(self, user, org, request_factory):
event_type = "PHONE_CALL"
slug = org.slug
view = SingleDateTimeEventCreate()
- url = reverse("register:event_create_simple_event_from_org_with_type", args=[slug, event_type])
+ url = reverse(
+ "register:event_create_simple_event_from_org_with_type",
+ args=[slug, event_type],
+ )
request = request_factory.get(url)
request.user = user
view.request = request
view.setup(request)
assert "event_type" in view.get_form_kwargs()
- def test_can_update_single_datetime_event_from_org(self, user, org_with_people, client):
+ def test_can_update_single_datetime_event_from_org(
+ self, user, org_with_people, client
+ ):
org_slug = org_with_people.slug
people = org_with_people.person_set.all()
e1 = SingleDateTimeEventFactory(type_descriptor="MEETING")
@@ -167,7 +179,9 @@ class TestSingleDateTimeEvent:
_collected_p.append((p.first_name, p.last_name))
e1.save()
pk = e1.pk
- url = reverse("register:event_update_simple_event_from_org", args=[pk, org_slug])
+ url = reverse(
+ "register:event_update_simple_event_from_org", args=[pk, org_slug]
+ )
client.force_login(user)
response = client.get(url)
assert response.status_code == 200
@@ -176,7 +190,16 @@ class TestSingleDateTimeEvent:
class TestSingleDateCAFEventViews:
- def test_initial_caf_received(self, client):
- url = reverse("register:event_create_simple_event")
+ def test_initial_caf_received(self, client, user, caf):
+ client.force_login(user)
+ url = reverse(
+ "register:event_caf_create_single_date_event_from_caf",
+ kwargs={"caf_id": caf.id},
+ )
response = client.get(url)
assert response.status_code == 200
+ html = response.content.decode("utf-8")
+ test_case.assertInHTML(
+ f"Register a single date event for {caf.version} ({caf.organisation.name})",
+ html,
+ )
diff --git a/ctrack/register/urls.py b/ctrack/register/urls.py
index 3f3c4f8..7be778e 100644
--- a/ctrack/register/urls.py
+++ b/ctrack/register/urls.py
@@ -4,7 +4,7 @@ from ctrack.register.views import (
EngagementEventCreate,
EngagementEventCreateFromCaf,
EngagementEventDelete,
- SingleDateTimeEventCreate, SingleDateTimeEventUpdate, CreateNoteEvent,
+ SingleDateTimeEventCreate, SingleDateTimeEventUpdate, CreateNoteEvent, CAFCreateSingleDateEventView,
)
app_name = "register"
@@ -49,6 +49,11 @@ urlpatterns = [
"event/create-note",
view=CreateNoteEvent.as_view(),
name="event_create_note"
+ ),
+ path(
+ "event/create-caf-single-date-event/<int:caf_id>",
+ view=CAFCreateSingleDateEventView.as_view(),
+ name="event_caf_create_single_date_event_from_caf"
)
# path(
# "event/create-caf-single-date-event",
diff --git a/ctrack/register/views.py b/ctrack/register/views.py
index 935bbed..49e40d8 100644
--- a/ctrack/register/views.py
+++ b/ctrack/register/views.py
@@ -7,9 +7,9 @@ from ctrack.caf.models import CAF
from ctrack.organisations.models import Organisation
from ctrack.register.forms import (
CreateSimpleDateTimeEventForm,
- EngagementEventCreateForm, CreateNoteEventForm,
+ EngagementEventCreateForm, CreateNoteEventForm, CAFSingleDateEventForm,
)
-from ctrack.register.models import EngagementEvent, SingleDateTimeEvent, NoteEvent
+from ctrack.register.models import EngagementEvent, SingleDateTimeEvent, NoteEvent, CAFSingleDateEvent
class EngagementEventDelete(DeleteView):
@@ -122,7 +122,7 @@ class SingleDateTimeEventUpdate(UpdateView):
class SingleDateTimeEventCreate(FormView):
- template_name = "single_datetime_event_create.html"
+ template_name = "register/single_datetime_event_create.html"
form_class = CreateSimpleDateTimeEventForm
success_url = reverse_lazy("organisations:list")
@@ -153,3 +153,24 @@ class SingleDateTimeEventCreate(FormView):
def form_valid(self, form):
form.save()
return super().form_valid(form)
+
+
+class CAFCreateSingleDateEventView(FormView):
+ template_name = "register/caf_single_date_event_form.html"
+ form_class = CAFSingleDateEventForm
+ success_url = reverse_lazy("caf:detail")
+
+ def get_form_kwargs(self):
+ kwargs = super().get_form_kwargs()
+ kwargs["user"] = self.request.user
+ kwargs["caf_id"] = self.kwargs.get("caf_id")
+ return kwargs
+
+ def get_success_url(self):
+ self.success_url = reverse_lazy("caf:detail", args=[self.kwargs.get("caf_id")])
+ return super().get_success_url()
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data()
+ context["caf"] = CAF.objects.get(id=self.kwargs.get("caf_id"))
+ return context