diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-16 17:23:14 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-16 17:23:14 +0100 |
commit | 1c7d45e92f83263a202d2f72c9daac61d34619cd (patch) | |
tree | ad62f6f4bda17055d29e6bd36ace9c511f7fa29c | |
parent | 8946e0f171379078c5a2230f38cf47f245e9b841 (diff) |
wip: create assessment form
-rw-r--r-- | engagements/forms.py | 27 | ||||
-rw-r--r-- | engagements/templates/engagements/eng_forms/assessment_create.html | 104 | ||||
-rw-r--r-- | engagements/tests/test_forms.py | 12 | ||||
-rw-r--r-- | engagements/tests/test_views.py | 6 | ||||
-rw-r--r-- | engagements/urls.py | 1 | ||||
-rw-r--r-- | engagements/views.py | 24 |
6 files changed, 171 insertions, 3 deletions
diff --git a/engagements/forms.py b/engagements/forms.py index 0fd44ea..852ba74 100644 --- a/engagements/forms.py +++ b/engagements/forms.py @@ -2,7 +2,7 @@ from django import forms from django.core.exceptions import ValidationError from django.forms.widgets import HiddenInput -from .models import Engagement, EngagementEffort, EngagementStrategy +from .models import Engagement, EngagementEffort, EngagementStrategy, EngagementType, Organisation class EngagementEffortReportingCreateForm(forms.ModelForm): @@ -242,3 +242,28 @@ class EngagementStrategyCreateForm(forms.ModelForm): class Meta: fields = "__all__" model = EngagementStrategy + + +class AssessmentCreateForm(forms.ModelForm): + class Meta: + model = Engagement + fields = ["proposed_start_date", "proposed_end_date", "officers", "engagement_type", "external_party"] + + def __init__(self, *args, **kwargs): + # eng_type_id = kwargs.pop("eng_type_id", None) + # entity_id = kwargs.pop("entity_id", None) + 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") diff --git a/engagements/templates/engagements/eng_forms/assessment_create.html b/engagements/templates/engagements/eng_forms/assessment_create.html new file mode 100644 index 0000000..1b87711 --- /dev/null +++ b/engagements/templates/engagements/eng_forms/assessment_create.html @@ -0,0 +1,104 @@ +{% extends "core/base.html" %} +{% load widget_tweaks %} + +{% block title %}Create new Assessment{% endblock title %} + +{% block content %} + +<div class="container mx-auto max-w-2xl mt-8"> + <div class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4 relative"> + <a href="{{ request.META.HTTP_REFERER }}" class="absolute top-2 right-2 p-1 rounded-full hover:bg-gray-200 transition-colors duration-200"> + <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" + stroke="currentColor" class="w-6 h-6"> + <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> + <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. + </p> + </div> + <div class="flex items-end justify-end"> + <p><a class="text-sm font-semibold underline text-blue-800" href="#">Help</a></p> + </div> + + <form method="post" class="space-y-6"> + {% csrf_token %} + {% for field in form %} + <div class="my-2"> + <div> + <label for="{{ field.id_for_label }}" class="block text-sm font-bold text-gray-700 mb-2"> + {{ field.label }} + </label> + </div> + <div> + {% 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 %} + {{ field }} + {% endfor %} + </div> + {% if field.help_text %} + <div class="flex items-end mb-2"> + <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" + stroke-width="1.0" stroke="currentColor" class="size-4 text-gray-500 mr-2"> + <path stroke-linecap="round" stroke-linejoin="round" + d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z"/> + </svg> + <p class="mt-2 text-xs text-gray-500">{{ field.help_text }}</p> + </div> + {% endif %} + </div> + {% endfor %} + <div class="mt-6"> + <button type="submit" + class="w-full py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"> + Submit + </button> + </div> + </form> + + </div> +</div> + + + + + +<!-- <div class="container mx-auto px-4 py-8"> --> +<!-- <div class="bg-white shadow-md rounded-lg overflow-hidden"> --> +<!-- <header class="bg-blue-100 p-4"> --> +<!-- <h2 class="text-3xl font-bold text-center">{{ title }}</h2> --> +<!-- </header> --> +<!-- <div class="p-6"> --> +<!-- <div class="mt-8"> --> +<!-- <h4 class="text-xl font-semibold mb-4">Enter main details:</h4> --> +<!-- <form method="post" class="space-y-6"> --> +<!-- {% csrf_token %} --> +<!-- {% for field in form %} --> +<!-- <div> --> +<!-- <label for="{{ field.id_for_label }}" class="block text-sm font-medium text-gray-700"> --> +<!-- {{ field.label }} --> +<!-- </label> --> +<!-- <div class="mt-1"> --> +<!-- {{ field }} --> +<!-- </div> --> +<!-- {% if field.help_text %} --> +<!-- <p class="mt-2 text-sm text-gray-500">{{ field.help_text|safe }}</p> --> +<!-- {% endif %} --> +<!-- {% for error in field.errors %} --> +<!-- <p class="mt-2 text-sm text-red-600">{{ error }}</p> --> +<!-- {% endfor %} --> +<!-- </div> --> +<!-- {% endfor %} --> +<!-- <div> --> +<!-- <button type="submit" class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"> --> +<!-- Save --> +<!-- </button> --> +<!-- </div> --> +<!-- </form> --> +<!-- </div> --> +<!-- </div> --> +<!-- </div> --> +<!-- </div> --> +{% endblock content %} diff --git a/engagements/tests/test_forms.py b/engagements/tests/test_forms.py index deb0a29..436be34 100644 --- a/engagements/tests/test_forms.py +++ b/engagements/tests/test_forms.py @@ -1,7 +1,12 @@ import pytest from django.forms import DateInput, Select, SelectMultiple -from engagements.forms import EngagementCreateForm, EngagementEffortCreateForm, EngagementStrategyCreateForm +from engagements.forms import ( + EngagementCreateForm, + EngagementEffortCreateForm, + EngagementStrategyCreateForm, + AssessmentCreateForm, +) from engagements.models import EngagementType, RegulatoryCycle pytestmark = pytest.mark.django_db @@ -129,3 +134,8 @@ def test_create_engagement_strategy_form(org, user, regulatory_cycles): } form = EngagementStrategyCreateForm(data=form_data) assert form.is_valid() + + +def test_create_assessment_engagement_type_form(): + e_type = EngagementType(name="ASSESSMENT") + form = AssessmentCreateForm({"initial": e_type}) diff --git a/engagements/tests/test_views.py b/engagements/tests/test_views.py index a7a420b..ef64f5e 100644 --- a/engagements/tests/test_views.py +++ b/engagements/tests/test_views.py @@ -140,3 +140,9 @@ def test_org_list_page_exists(client): url = reverse("engagements:org_detail") response = client.get(url) assert response.status_code == 302 + + +def test_assessment_create_form_view(client): + url = reverse("engagements:create_assessment") + response = client.get(url) + assert response.status_code == 302 diff --git a/engagements/urls.py b/engagements/urls.py index 3f3c9ae..c9bfb90 100644 --- a/engagements/urls.py +++ b/engagements/urls.py @@ -17,6 +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("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 7146b67..55ddecd 100644 --- a/engagements/views.py +++ b/engagements/views.py @@ -1,7 +1,7 @@ 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.http import HttpResponse, HttpResponseBadRequest from django.shortcuts import get_object_or_404, redirect, render from django.template.loader import render_to_string from django.urls import reverse_lazy @@ -16,6 +16,7 @@ from .forms import ( EngagementEffortReportingCreateForm, EngagementEffortTravelCreateForm, EngagementStrategyCreateForm, + AssessmentCreateForm, ) from .models import Engagement, EngagementEffort, EngagementStrategy, EngagementType, Organisation from .utils import duration_formatter @@ -209,3 +210,24 @@ class CreateEngagementStrategy(LoginRequiredMixin, CreateView): class OrgListView(LoginRequiredMixin, ListView): model = Organisation + + +@login_required +def create_assessment(request): + if request.method == "POST": + pass + 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() + return render( + request, + "engagements/eng_forms/assessment_create.html", + {"form": form}, + ) |