1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render
from django.views.generic import CreateView, ListView, DetailView
from ctrack.assessments.models import CAFAssessment, CAFObjective, CAFPrinciple, CAFAssessmentOutcomeScore
from ctrack.caf.forms import CAFForm
from ctrack.caf.models import ApplicableSystem, CAF
class CreateCAF(LoginRequiredMixin, CreateView):
form_class = CAFForm
template_name = "caf/create.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form'] = self.form_class
return context
class ListCAF(LoginRequiredMixin, ListView):
pass
# class DetailCAF(LoginRequiredMixin, DetailView):
# model = CAF
# Let's write a traditional function view!
def caf_detail_view(request, pk):
caf = CAF.objects.get(pk=pk)
# get any assessments that have been done on this caf
assessments = caf.cafassessment_set.all()
# caf_principles = CAFPrinciple.objects.all()
_scrs = []
for ass in assessments:
lst_scores = []
lst_scores.append(ass)
lst_scores.append(CAFAssessmentOutcomeScore.objects.filter(caf_assessment=ass))
_scrs.append(lst_scores)
context = {
'object': caf,
'assessments_and_scores': _scrs,
'organisation': ApplicableSystem.objects.filter(caf=caf).first().organisation
}
return render(request, 'caf/caf_detail.html', context)
class ListApplicableSystem(LoginRequiredMixin, ListView):
model = ApplicableSystem
# apparently you can pass a list of model objects to a template if you name it
# here - otherwise you need to provide a QuerySet
template_name = "caf/applicablesystem_list.html"
def get_queryset(self):
ess = ApplicableSystem.objects.all().order_by("organisation__name")
return ess
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
return context
|