aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/caf/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ctrack/caf/views.py')
-rw-r--r--ctrack/caf/views.py23
1 files changed, 21 insertions, 2 deletions
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"