From d5833c7364060076ed4af460a6f020344ce74f21 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 5 Sep 2024 15:01:16 +0100 Subject: Improved engagement detail page layout, using htmx --- engagements/views.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'engagements/views.py') diff --git a/engagements/views.py b/engagements/views.py index ae1abfd..a76a37d 100644 --- a/engagements/views.py +++ b/engagements/views.py @@ -1,11 +1,13 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin from django.db.models import Q -from django.shortcuts import get_object_or_404, redirect, render +from django.http import HttpResponse +from django.shortcuts import get_object_or_404 +from django.shortcuts import redirect, render +from django.template.loader import render_to_string from django.views.generic import ListView from instruments.models import SubInstrument - from .forms import ( EngagementCreateForm, EngagementEffortPlanningCreateForm, @@ -16,6 +18,12 @@ from .forms import ( from .models import Engagement, EngagementEffort, EngagementType, Organisation +def effort_detail(request, effort_id): + effort = get_object_or_404(EngagementEffort, id=effort_id) + html = render_to_string('engagements/snippets/effort_detail.html', {'effort': effort}) + return HttpResponse(html) + + class RegulatedEntitiesView(LoginRequiredMixin, ListView): context_object_name = "entities" queryset = Organisation.objects.filter(is_regulated_entity=True).order_by("name") -- cgit v1.2.3 From 09b099e467df64ac8ce44bbe2d1f80cd1c00a126 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 9 Sep 2024 14:55:38 +0100 Subject: Basic validation on start and end dates for Engagement - form validation when end date is before the start date --- engagements/views.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'engagements/views.py') diff --git a/engagements/views.py b/engagements/views.py index a76a37d..88f2014 100644 --- a/engagements/views.py +++ b/engagements/views.py @@ -155,6 +155,12 @@ def engagement_create(request, slug, reg=None): ef.external_party = Organisation.objects.get(slug=slug) ef.save() return redirect("engagements:plan_for_org", orgslug=slug) + else: + return render( + request, + "engagements/engagement_form.html", + {"form": form, "title": f"Create Engagement for {slug}", "errors": form.errors}, + ) else: if reg: form = EngagementCreateForm( -- cgit v1.2.3 From e3b47f5218aa9155e933c58465aebc071485df40 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 9 Sep 2024 15:24:16 +0100 Subject: Tests passing --- engagements/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engagements/views.py') diff --git a/engagements/views.py b/engagements/views.py index 88f2014..e66d679 100644 --- a/engagements/views.py +++ b/engagements/views.py @@ -2,12 +2,12 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin from django.db.models import Q from django.http import HttpResponse -from django.shortcuts import get_object_or_404 -from django.shortcuts import redirect, render +from django.shortcuts import get_object_or_404, redirect, render from django.template.loader import render_to_string from django.views.generic import ListView from instruments.models import SubInstrument + from .forms import ( EngagementCreateForm, EngagementEffortPlanningCreateForm, -- cgit v1.2.3 From 15520388a725dd9763e80ad617f31aea3b2ddb67 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 10 Sep 2024 15:36:13 +0100 Subject: wip: testing the view containing the ES create form --- engagements/views.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'engagements/views.py') diff --git a/engagements/views.py b/engagements/views.py index e66d679..2257a98 100644 --- a/engagements/views.py +++ b/engagements/views.py @@ -4,7 +4,8 @@ from django.db.models import Q from django.http import HttpResponse from django.shortcuts import get_object_or_404, redirect, render from django.template.loader import render_to_string -from django.views.generic import ListView +from django.urls import reverse_lazy +from django.views.generic import CreateView, ListView from instruments.models import SubInstrument @@ -14,13 +15,14 @@ from .forms import ( EngagementEffortRegulationCreateForm, EngagementEffortReportingCreateForm, EngagementEffortTravelCreateForm, + EngagementStrategyCreateForm, ) -from .models import Engagement, EngagementEffort, EngagementType, Organisation +from .models import Engagement, EngagementEffort, EngagementStrategy, EngagementType, Organisation def effort_detail(request, effort_id): effort = get_object_or_404(EngagementEffort, id=effort_id) - html = render_to_string('engagements/snippets/effort_detail.html', {'effort': effort}) + html = render_to_string("engagements/snippets/effort_detail.html", {"effort": effort}) return HttpResponse(html) @@ -48,7 +50,7 @@ def htmx_effort_planned(request, effid): else: effort.is_planned = True effort.save() - return render(request, "engagements/snippets/effort_summary_panel.html", {"e" : effort}) + return render(request, "engagements/snippets/effort_summary_panel.html", {"e": effort}) @login_required @@ -194,3 +196,10 @@ def engagement_create(request, slug, reg=None): "engagements/engagement_form.html", {"form": form, "title": "Add New Engagement"}, ) + + +class CreateEngagementStrategy(LoginRequiredMixin, CreateView): + model = EngagementStrategy + form_class = EngagementStrategyCreateForm + template_name = "engagements/engagement_strategy_form.html" + success_url = reverse_lazy("engagements:home") -- cgit v1.2.3