From d4e6e7b3c8f10c6671cecea2c2ca42578678eb4a Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 21 Oct 2020 14:49:36 +0100 Subject: can now add caf single date events to caf detail page --- ctrack/caf/templates/caf/caf_detail.html | 10 +++++----- ctrack/register/forms.py | 2 +- ctrack/register/tests/test_forms.py | 4 ++-- ctrack/register/tests/test_views.py | 1 + ctrack/register/views.py | 4 ++++ 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ctrack/caf/templates/caf/caf_detail.html b/ctrack/caf/templates/caf/caf_detail.html index 3a73beb..166ced8 100644 --- a/ctrack/caf/templates/caf/caf_detail.html +++ b/ctrack/caf/templates/caf/caf_detail.html @@ -128,19 +128,19 @@ Date - Event + Event Inspector - Description + Description Comments {% for event in all_events %} - {{ event.date }} - {{ event.type_descriptor }} + {{ event.date|date:"j/n/y" }} + {{ event.type_descriptor }} {{ event.user.name }} - {{ event.short_description }} + {{ event.short_description }} {{ event.comments }} {% endfor %} diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py index 512ae9d..cca4cb9 100644 --- a/ctrack/register/forms.py +++ b/ctrack/register/forms.py @@ -107,7 +107,6 @@ class CAFSingleDateEventForm(forms.ModelForm): fields = [ "type_descriptor", "date", - "related_caf", "short_description", "document_link", "comments", @@ -121,6 +120,7 @@ class CAFSingleDateEventForm(forms.ModelForm): def save(self, **kwargs): form = super().save(commit=False) form.user = self.user + form.related_caf = CAF.objects.get(id=self.caf_id) form.save() return form diff --git a/ctrack/register/tests/test_forms.py b/ctrack/register/tests/test_forms.py index 1ba1cf9..4a9e818 100644 --- a/ctrack/register/tests/test_forms.py +++ b/ctrack/register/tests/test_forms.py @@ -137,7 +137,7 @@ def test_create_note(user, org_with_people): "CAF_VALIDATION_RECORD_EMAILED_TO_OES", ], ) -def test_allowable_caf_single_date_event_forms(allowed_type, user, caf): +def test_caf_single_date_event_forms(allowed_type, user, caf): form = CAFSingleDateEventForm( { "type_descriptor": allowed_type, @@ -146,7 +146,7 @@ def test_allowable_caf_single_date_event_forms(allowed_type, user, caf): "date": "2010-07-01", "comments": "Meaningless comments", }, - user=user, + user=user, caf_id=caf.id ) assert form.is_valid() diff --git a/ctrack/register/tests/test_views.py b/ctrack/register/tests/test_views.py index 0876332..4e8152c 100644 --- a/ctrack/register/tests/test_views.py +++ b/ctrack/register/tests/test_views.py @@ -203,3 +203,4 @@ class TestSingleDateCAFEventViews: f"Register a single date event for {caf.version} ({caf.organisation.name})", html, ) + assert "Related caf" not in html diff --git a/ctrack/register/views.py b/ctrack/register/views.py index 49e40d8..c8fe1c5 100644 --- a/ctrack/register/views.py +++ b/ctrack/register/views.py @@ -166,6 +166,10 @@ class CAFCreateSingleDateEventView(FormView): kwargs["caf_id"] = self.kwargs.get("caf_id") return kwargs + def form_valid(self, form): + form.save() + return super().form_valid(form) + def get_success_url(self): self.success_url = reverse_lazy("caf:detail", args=[self.kwargs.get("caf_id")]) return super().get_success_url() -- cgit v1.2.3