summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-10-23 16:24:13 +0100
committerMatthew Lemon <y@yulqen.org>2024-10-23 16:24:13 +0100
commit788cb0ae7ee5353b7b57623449fa10996e5839f9 (patch)
tree82fb9708dd1d239bcd83ee0c13ae1bc7cb15afca
parent92aef59c99cd4cb0ca067216016922aa6661a90a (diff)
Rudimentary form to create Assessment from org EP pagedev
-rw-r--r--engagements/forms.py42
-rw-r--r--engagements/templates/engagements/eng_forms/assessment_create.html4
-rw-r--r--engagements/templates/engagements/engagement_detail.html4
-rw-r--r--engagements/templates/engagements/ep_org.html4
-rw-r--r--engagements/urls.py4
-rw-r--r--engagements/views.py20
6 files changed, 42 insertions, 36 deletions
diff --git a/engagements/forms.py b/engagements/forms.py
index 852ba74..ddd7aa0 100644
--- a/engagements/forms.py
+++ b/engagements/forms.py
@@ -248,22 +248,30 @@ class AssessmentCreateForm(forms.ModelForm):
class Meta:
model = Engagement
fields = ["proposed_start_date", "proposed_end_date", "officers", "engagement_type", "external_party"]
+ widgets = {
+ "proposed_start_date": forms.DateInput(
+ attrs={
+ "type": "date",
+ "class": "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50",
+ },
+ format="j M y H:i",
+ ),
+ "proposed_end_date": forms.DateInput(
+ attrs={
+ "type": "date",
+ "class": "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50",
+ },
+ format="j M y H:i",
+ ),
+ }
- def __init__(self, *args, **kwargs):
- # eng_type_id = kwargs.pop("eng_type_id", None)
- # entity_id = kwargs.pop("entity_id", None)
+ def __init__(self, *args, org, **kwargs):
super().__init__(*args, **kwargs)
- self.fields["proposed_start_date"].initial = "tosser"
- self.fields["engagement_type"].initial = "ASSESSMENT"
- # if eng_type_id is not None:
- # try:
- # engagement_type = EngagementType.objects.get(id=eng_type_id)
- # self.initial["engagement_type"] = engagement_type
- # except EngagementType.DoesNotExist:
- # raise ValidationError(f"EngagementType with id {eng_type_id} does not exist")
- # if entity_id is not None:
- # try:
- # entity = Organisation.objects.get(id=entity_id)
- # self.initial["external_party"] = entity
- # except Organisation.DoesNotExist:
- # raise ValidationError(f"Organisation with id {entity_id} does not exist")
+ entity = Organisation.objects.get(slug=org)
+ et = EngagementType.objects.get(name="ASSESSMENT")
+ self.initial["engagement_type"] = et.pk
+ self.initial["external_party"] = entity.pk
+ self.fields["engagement_type"].widget= forms.HiddenInput()
+ self.fields["engagement_type"].label = ""
+ self.fields["external_party"].widget= forms.HiddenInput()
+ self.fields["external_party"].label = ""
diff --git a/engagements/templates/engagements/eng_forms/assessment_create.html b/engagements/templates/engagements/eng_forms/assessment_create.html
index 1b87711..d32d23c 100644
--- a/engagements/templates/engagements/eng_forms/assessment_create.html
+++ b/engagements/templates/engagements/eng_forms/assessment_create.html
@@ -1,7 +1,7 @@
{% extends "core/base.html" %}
{% load widget_tweaks %}
-{% block title %}Create new Assessment{% endblock title %}
+{% block title %}Create new Assessment for {{ org.name }}{% endblock title %}
{% block content %}
@@ -13,7 +13,7 @@
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/>
</svg>
</a>
- <h2 class="text-2xl font-bold mb-6">Create new Assessment</h2>
+ <h2 class="text-2xl font-bold mb-6">Create new Assessment at {{ org.name }}</h2>
<div class="bg-blue-50 border border-blue-200 rounded-md p-4 mb-6">
<p class="text-sm text-blue-800">
Please fill out the form below to create a new Assessment in the Engagement Plan.
diff --git a/engagements/templates/engagements/engagement_detail.html b/engagements/templates/engagements/engagement_detail.html
index f98191e..1ab2a33 100644
--- a/engagements/templates/engagements/engagement_detail.html
+++ b/engagements/templates/engagements/engagement_detail.html
@@ -9,7 +9,9 @@
<h3 class="font-semibold text-3xl">{{ engagement.friendly_type }}
at {{ engagement.external_party }}</h3>
<h4 class="text-gray-600">{{ engagement.proposed_start_date|date:"l j M Y" }}</h4>
- <p class="py-2">{% lorem %}</p>
+ <p class="py-2 text-white bg-red-500">The main text at the top of this page is dummy text which shows
+ how the outcome of an engagement could be presented. The Summary and Effort boxes
+ below are functional, however.</p>
<h3 class="text-2xl">Executive summary</h3>
diff --git a/engagements/templates/engagements/ep_org.html b/engagements/templates/engagements/ep_org.html
index e4dc8be..3264ad6 100644
--- a/engagements/templates/engagements/ep_org.html
+++ b/engagements/templates/engagements/ep_org.html
@@ -11,8 +11,8 @@
</header>
<div class="p-4">
<div class="mb-4">
- <a href="{% url 'engagements:create' entity.slug 'reg' %}" class="text-blue-600 hover:underline">Add New Regulatory Engagement</a> |
- <a href="{% url 'engagements:create' entity.slug %}" class="text-blue-600 hover:underline">Add New Engagement</a>
+ <p>Create new:
+ <a href="{% url 'engagements:create_assessment' entity.slug %}" class="text-blue-600 hover:underline">Assessment</a></p>
</div>
<h3 class="text-2xl font-semibold mb-4">2023</h3>
diff --git a/engagements/urls.py b/engagements/urls.py
index c9bfb90..26c9d37 100644
--- a/engagements/urls.py
+++ b/engagements/urls.py
@@ -6,7 +6,7 @@ app_name = "engagements"
urlpatterns = [
path("", views.engagement_planning, name="home"),
path("<int:pk>", views.engagement_detail, name="engagement_detail"),
- path("org/", views.OrgListView.as_view(), name="org_detail"),
+ path("org/", views.OrgListView.as_view(), name="org_list"),
path("plan/<slug:orgslug>/", views.engagement_plan_for, name="plan_for_org"),
path(
"regulatedentities/",
@@ -17,7 +17,7 @@ urlpatterns = [
path("effort/<int:effort_id>/detail/", views.effort_detail, name="effort_detail"),
path("create/<slug:slug>/", views.engagement_create, name="create"),
path("create/<slug:slug>/<str:reg>", views.engagement_create, name="create"),
- path("create-assessment/", views.create_assessment, name="create_assessment"),
+ path("create-assessment/<slug:org>", views.create_assessment, name="create_assessment"),
path("es-create/", views.CreateEngagementStrategy.as_view(), name="es-create"),
path(
"effort/create/<int:eid>/<str:etype>",
diff --git a/engagements/views.py b/engagements/views.py
index 55ddecd..2e40af8 100644
--- a/engagements/views.py
+++ b/engagements/views.py
@@ -213,21 +213,17 @@ class OrgListView(LoginRequiredMixin, ListView):
@login_required
-def create_assessment(request):
+def create_assessment(request, org):
if request.method == "POST":
- pass
+ form = AssessmentCreateForm(request.POST, org=org)
+ if form.is_valid():
+ form.save()
+ return redirect("engagements:home")
else:
- eng_type_id = request.GET.get("eng_type_id", None)
- entity_id = request.GET.get("entity_id", None)
- if not eng_type_id:
- return HttpResponseBadRequest("You must provide an engagement_type id")
- if not entity_id:
- return HttpResponseBadRequest("You must provide an entity id")
- eng_type = EngagementType.objects.get(id=eng_type_id)
- entity = Organisation.objects.get(id=entity_id)
- form = AssessmentCreateForm()
+ form = AssessmentCreateForm(org=org)
+ org = Organisation.objects.get(slug=org)
return render(
request,
"engagements/eng_forms/assessment_create.html",
- {"form": form},
+ {"form": form, "org": org},
)