From 271409371dc71b6c9108b2e56cb82ff8ce74415f Mon Sep 17 00:00:00 2001 From: MR Lemon Date: Tue, 21 Apr 2020 16:09:32 +0100 Subject: can now add a system from a CAF detail page --- ctrack/caf/views.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'ctrack/caf/views.py') diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py index ded9233..251024d 100644 --- a/ctrack/caf/views.py +++ b/ctrack/caf/views.py @@ -1,10 +1,11 @@ from django.contrib.auth.mixins import LoginRequiredMixin +from django.http import HttpResponseRedirect from django.shortcuts import render -from django.urls import reverse_lazy +from django.urls import reverse_lazy, reverse from django.views.generic import ListView, DetailView, FormView from ctrack.assessments.models import CAFAssessmentOutcomeScore -from ctrack.caf.forms import ApplicableSystemCreateFromOrgForm +from ctrack.caf.forms import ApplicableSystemCreateFromOrgForm, ApplicableSystemCreateFromCafForm from ctrack.caf.models import ApplicableSystem, CAF from ctrack.organisations.models import Organisation @@ -54,6 +55,24 @@ class ApplicableSystemDetail(LoginRequiredMixin, DetailView): template_name = "caf/applicablesystem_detail.html" +def applicable_system_create_from_caf(request, caf_id): + org_id = CAF.objects.get(pk=caf_id).organisation().id + if request.method=="POST": + form = ApplicableSystemCreateFromCafForm(request.POST, caf_id=caf_id, org_id=org_id) + if form.is_valid(): + ApplicableSystem.objects.create( + name=form.cleaned_data["name"], + description=form.cleaned_data["description"], + caf=form.cleaned_data["caf"], + organisation=form.cleaned_data["organisation"] + ) + return HttpResponseRedirect(reverse("caf:detail", args=[caf_id])) + else: + form = ApplicableSystemCreateFromCafForm(caf_id=caf_id, org_id=org_id) + + return render(request, "caf/applicable_system_create_from_caf.html", {"form": form}) + + class ApplicableSystemCreateFromOrg(LoginRequiredMixin, FormView): form_class = ApplicableSystemCreateFromOrgForm template_name = "caf/applicable_system_create_from_org.html" -- cgit v1.2.3