From f1c3af915dcf2746dcd65082bf36a55fda6ee773 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 12 Sep 2024 12:06:13 +0100 Subject: Moved Edit Engagement form to a template include --- engagements/forms.py | 6 ++- .../templates/engagements/engagement_form.html | 61 +--------------------- 2 files changed, 6 insertions(+), 61 deletions(-) diff --git a/engagements/forms.py b/engagements/forms.py index cccaf3b..401d6a9 100644 --- a/engagements/forms.py +++ b/engagements/forms.py @@ -225,8 +225,10 @@ class EngagementCreateForm(forms.ModelForm): "officers": "Inspectors", } help_texts = { - "proposed_start_date": "YYYY-MM-DD", - "proposed_end_date": "YYYY-MM-DD", + "external_party": "These are the people you are dealing with.", + "proposed_start_date": "YYYY-MM-DD", + "proposed_end_date": "YYYY-MM-DD", + "officers": "Use CTRL to select multiple if required.", } widgets = { "proposed_start_date": forms.DateInput(attrs={"type": "date"}), diff --git a/engagements/templates/engagements/engagement_form.html b/engagements/templates/engagements/engagement_form.html index 89f6b0e..0b5cd8b 100644 --- a/engagements/templates/engagements/engagement_form.html +++ b/engagements/templates/engagements/engagement_form.html @@ -30,67 +30,10 @@ -
-

Enter main details:

-
-
- {% csrf_token %} -
- {{ form.external_party.label_tag }} -
- {% render_field form.external_party class+="block w-full rounded-md border-0 p-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %} - {% for error in form.external_party.errors %} -

{{ error }}

- {% endfor %} -
-
+ + {% include "engagements/snippets/standard_form.html" with form=form %} -
- {{ form.proposed_start_date.label_tag }} -
- {% render_field form.proposed_start_date class+="block w-full rounded-md border-0 p-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %} -
-
-
- {{ form.proposed_end_date.label_tag }} -
- {% render_field form.proposed_end_date class+="block w-full rounded-md border-0 p-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %} -
- {% for error in form.proposed_end_date.errors %} -

{{ error }}

- {% endfor %} -
- -
- {{ form.engagement_type.label_tag }} -
- {% render_field form.engagement_type class+="block w-full rounded-md border-0 p-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %} - {% for error in form.engagement_type.errors %} -

{{ error }}

- {% endfor %} -
-
- -
- {{ form.officers.label_tag }} -
- {% render_field form.officers class+="block w-full rounded-md border-0 p-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %} - {% for error in form.officers.errors %} -

{{ error }}

- {% endfor %} -
-
- -
- -
-
-
-
-- cgit v1.2.3 From 7fa97be1538e3278fc46d5279907a0e062a80e9a Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 12 Sep 2024 12:07:23 +0100 Subject: Adds the snippet file missing from the last commit --- .../engagements/snippets/standard_form.html | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 engagements/templates/engagements/snippets/standard_form.html diff --git a/engagements/templates/engagements/snippets/standard_form.html b/engagements/templates/engagements/snippets/standard_form.html new file mode 100644 index 0000000..fb419c2 --- /dev/null +++ b/engagements/templates/engagements/snippets/standard_form.html @@ -0,0 +1,25 @@ +{% load widget_tweaks %} + +
+

Enter main details:

+
+
+ {% csrf_token %} + {% for field in form %} +
+ {{ field.label_tag }} {% if field.field.required %}*{% endif %} +
+ {% render_field field class+="block w-full rounded-md border-0 p-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %} +
+ {% if field.help_text %} +
+

{{ field.help_text }}

+
+ {% endif %} +
+ {% endfor %} +
+
-- cgit v1.2.3 From 4f3bb2927fb8327f5b73e59acb2a91dfbacb5fb5 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 12 Sep 2024 12:52:08 +0100 Subject: Now passes form test --- engagements/tests/test_forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engagements/tests/test_forms.py b/engagements/tests/test_forms.py index 851f986..deb0a29 100644 --- a/engagements/tests/test_forms.py +++ b/engagements/tests/test_forms.py @@ -56,8 +56,8 @@ def test_form_labels(): def test_form_help_texts(): form = EngagementCreateForm() - assert form.fields["proposed_start_date"].help_text == "YYYY-MM-DD" - assert form.fields["proposed_end_date"].help_text == "YYYY-MM-DD" + assert form.fields["proposed_start_date"].help_text == "YYYY-MM-DD" + assert form.fields["proposed_end_date"].help_text == "YYYY-MM-DD" def test_form_widgets(): -- cgit v1.2.3 From fb0df8eaad9365a9e8bcee462b6948056e97c80c Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 12 Sep 2024 12:52:27 +0100 Subject: Removed unneeded login_required on htmx function? --- engagements/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/engagements/views.py b/engagements/views.py index 2257a98..60bec47 100644 --- a/engagements/views.py +++ b/engagements/views.py @@ -41,7 +41,6 @@ def engagement_planning(request): # display the list and ask which one? -@login_required def htmx_effort_planned(request, effid): if request.method == "GET": effort = EngagementEffort.objects.get(id=effid) -- cgit v1.2.3 From c2b95c681b90a84f3ef8635211af280941d1c034 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 7 Oct 2024 14:35:58 +0100 Subject: ignore direnv file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3335a5c..e5692a4 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ Staticfile.auth *.code-workspace db.sqlite3 +.envrc -- cgit v1.2.3 From cdd5e5d9372a63f87827915448cae1cc692db08a Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 7 Oct 2024 14:36:24 +0100 Subject: Adds submit button to form and fix date-span in summary box of eng. detail --- engagements/templates/engagements/engagement_detail.html | 5 ++++- engagements/templates/engagements/engagement_form.html | 3 +-- .../templates/engagements/snippets/standard_form.html | 12 +++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/engagements/templates/engagements/engagement_detail.html b/engagements/templates/engagements/engagement_detail.html index 3acabf6..fbf6735 100644 --- a/engagements/templates/engagements/engagement_detail.html +++ b/engagements/templates/engagements/engagement_detail.html @@ -81,7 +81,10 @@ - Tuesday - 10 May 2022 + {{ engagement.proposed_start_date|date:'j M Y' }} + {% if engagement.proposed_end_date != engagement.proposed_start_date %} + - {{ engagement.proposed_end_date|date:'j M Y' }} + {% endif %} diff --git a/engagements/templates/engagements/engagement_form.html b/engagements/templates/engagements/engagement_form.html index 0b5cd8b..4f04f5e 100644 --- a/engagements/templates/engagements/engagement_form.html +++ b/engagements/templates/engagements/engagement_form.html @@ -33,8 +33,7 @@ {% include "engagements/snippets/standard_form.html" with form=form %} - -{% endblock content %} + {% endblock content %} diff --git a/engagements/templates/engagements/snippets/standard_form.html b/engagements/templates/engagements/snippets/standard_form.html index fb419c2..0756242 100644 --- a/engagements/templates/engagements/snippets/standard_form.html +++ b/engagements/templates/engagements/snippets/standard_form.html @@ -2,8 +2,8 @@

Enter main details:

-
- +
+ {% csrf_token %} {% for field in form %}
@@ -21,5 +21,11 @@ {% endif %}
{% endfor %} -
+
+ +
+ +
-- cgit v1.2.3 From 21500e9f7cb0ba05aafa5cd1c67483785e9d0583 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 7 Oct 2024 14:43:28 +0100 Subject: Fix the start and end dates being the same --- engagements/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engagements/forms.py b/engagements/forms.py index 401d6a9..0fd44ea 100644 --- a/engagements/forms.py +++ b/engagements/forms.py @@ -210,7 +210,7 @@ class EngagementCreateForm(forms.ModelForm): if proposed_start_date > proposed_end_date: raise ValidationError("The proposed start date must be before the proposed end date.") - return proposed_start_date + return proposed_end_date class Meta: model = Engagement -- cgit v1.2.3 From b821c337590e2653074f3f01c649c180918c1c32 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 7 Oct 2024 15:39:44 +0100 Subject: ruff cleanup --- engagements/tests/conftest.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/engagements/tests/conftest.py b/engagements/tests/conftest.py index 7ccb9ad..74e41eb 100644 --- a/engagements/tests/conftest.py +++ b/engagements/tests/conftest.py @@ -1,5 +1,3 @@ -from datetime import date - import pytest from engagements.models import Engagement, EngagementStrategy, EngagementType, Organisation, RegulatoryCycle @@ -20,7 +18,7 @@ def org(): @pytest.fixture def engagement_strategy(regulatory_cycles, org, user): - es = EngagementStrategy.objects.create( + EngagementStrategy.objects.create( description="ES1 description", start_year=RegulatoryCycle.objects.get(start_date="2022-01-01"), end_year=RegulatoryCycle.objects.get(start_date="2024-01-01"), -- cgit v1.2.3 From 222cd8c0737ea76f33b6a9337316b673f532bcc0 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 7 Oct 2024 15:40:13 +0100 Subject: Nice engagement duration text for summary box on detail page --- .../templates/engagements/engagement_detail.html | 7 ++--- engagements/tests/test_views.py | 33 ++++++++++++++++++++-- engagements/utils.py | 14 +++++++++ engagements/views.py | 3 ++ 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/engagements/templates/engagements/engagement_detail.html b/engagements/templates/engagements/engagement_detail.html index fbf6735..c122e11 100644 --- a/engagements/templates/engagements/engagement_detail.html +++ b/engagements/templates/engagements/engagement_detail.html @@ -81,10 +81,9 @@ - {{ engagement.proposed_start_date|date:'j M Y' }} - {% if engagement.proposed_end_date != engagement.proposed_start_date %} - - {{ engagement.proposed_end_date|date:'j M Y' }} - {% endif %} + + {{ day_duration }} + diff --git a/engagements/tests/test_views.py b/engagements/tests/test_views.py index 017b96f..01d73c7 100644 --- a/engagements/tests/test_views.py +++ b/engagements/tests/test_views.py @@ -6,12 +6,41 @@ from django.test import RequestFactory from django.urls import reverse from engagements import models, views -from engagements.models import EngagementStrategy, RegulatoryCycle, Organisation -from engagements.utils import populate_database +from engagements.models import EngagementStrategy, Organisation, RegulatoryCycle +from engagements.utils import duration_formatter, populate_database pytestmark = pytest.mark.django_db +def test_single_day_string(): + """test date formatting for the summary box on the detail page""" + d1 = datetime.date(2024, 10, 10) + d2 = datetime.date(2024, 10, 10) + duration_str = duration_formatter(d1, d2) + assert duration_str == "10 October 2024 (1 day)" + +def test_multi_duration_string(): + """test date formatting for the summary box on the detail page""" + d1 = datetime.date(2024, 10, 10) + d2 = datetime.date(2024, 10, 12) + duration_str = duration_formatter(d1, d2) + assert duration_str == "10-12 October 2024 (3 days)" + +def test_multi_duration_string_longer(): + """test date formatting for the summary box on the detail page""" + d1 = datetime.date(2024, 10, 1) + d2 = datetime.date(2024, 10, 12) + duration_str = duration_formatter(d1, d2) + assert duration_str == "01-12 October 2024 (12 days)" + +def test_multi_duration_over_month_boundary_string(): + """test date formatting for the summary box on the detail page""" + d1 = datetime.date(2024, 9, 30) + d2 = datetime.date(2024, 10, 1) + duration_str = duration_formatter(d1, d2) + assert duration_str == "30 September - 01 October 2024 (2 days)" + + @pytest.fixture def test_data(): return populate_database() diff --git a/engagements/utils.py b/engagements/utils.py index 3b414e9..b80e74d 100644 --- a/engagements/utils.py +++ b/engagements/utils.py @@ -18,6 +18,20 @@ from instruments.models import Instrument, SubInstrument from myuser.models import Team, TeamUser +def duration_formatter(d1: datetime.date, d2: datetime.date) -> str: + trip_delta = d2 - d1 + if trip_delta.days == 0: + # this is a single day event + return f"{d1.strftime("%d %B %Y")} (1 day)" + else: + # if months are different... + if d1.month != d2.month: + # we need to format this differently + return f"{d1.strftime("%d %B")} - {d2.strftime("%d %B %Y")} ({trip_delta.days +1} days)" + else: + return f"{d1.strftime("%d")}-{d2.strftime("%d %B %Y")} ({trip_delta.days + 1} days)" + + def populate_database(): out = defaultdict(list) fake = Faker(locale="en_GB") diff --git a/engagements/views.py b/engagements/views.py index 60bec47..86f886d 100644 --- a/engagements/views.py +++ b/engagements/views.py @@ -18,6 +18,7 @@ from .forms import ( EngagementStrategyCreateForm, ) from .models import Engagement, EngagementEffort, EngagementStrategy, EngagementType, Organisation +from .utils import duration_formatter def effort_detail(request, effort_id): @@ -66,6 +67,7 @@ def engagement_detail(request, pk): effort_total = sum(e.effort_total_hours() for e in effort) effort_planned = sum(e.effort_total_planned_hours() for e in effort) effort_actual = sum(e.effort_actual() for e in effort) + day_duration_str = duration_formatter(engagement.proposed_start_date, engagement.proposed_end_date) context = { "engagement": engagement, "subinstruments": subinstruments, @@ -73,6 +75,7 @@ def engagement_detail(request, pk): "effort_total": effort_total, "effort_planned": effort_planned, "effort_actual": effort_actual, + "day_duration": day_duration_str, "dscs": dscs, } return render(request, "engagements/engagement_detail.html", context) -- cgit v1.2.3 From f590e8c44f8ab5d083e90f17a9e527901c266092 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 14 Oct 2024 14:28:00 +0100 Subject: Ignore tags file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e5692a4..a981596 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ Staticfile.auth db.sqlite3 .envrc +tags -- cgit v1.2.3 From 0a23538f51f9ab43fad75d0f54fa7102ecab3c8c Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 14 Oct 2024 14:29:32 +0100 Subject: Fix navbar to have DED and new menu item --- core/templates/core/base.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/templates/core/base.html b/core/templates/core/base.html index 2a3f446..787718b 100644 --- a/core/templates/core/base.html +++ b/core/templates/core/base.html @@ -19,12 +19,13 @@