Coverage for control/cust/assessment_table.py : 86%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from flask import flash
3from config import Names as N
4from control.utils import pick as G
5from control.table import Table
6from control.typ.related import castObjectId
9class AssessmentT(Table):
10 """Logic for the assessment table.
12 Inserting an assessment means also to insert the right
13 set of criteriaEntry records and prefill some of their fields.
14 """
16 def __init__(self, *args, **kwargs):
17 super().__init__(*args, **kwargs)
19 def insert(self, force=False, masterTable=None, masterId=None):
20 mayInsert = force or self.mayInsert
21 if not mayInsert:
22 return None
24 if not masterTable or not masterId: 24 ↛ 25line 24 didn't jump to line 25, because the condition on line 24 was never true
25 return None
27 context = self.context
28 db = context.db
29 uid = self.uid
30 eppn = self.eppn
31 table = self.table
32 typeCriteria = db.typeCriteria
34 masterOid = castObjectId(masterId)
36 wfitem = context.getWorkflowItem(masterOid)
38 if not wfitem.permission(N.startAssessment):
39 return None
41 (contribType, contribTitle) = wfitem.info(N.contrib, N.type, N.title)
42 if not contribType:
43 flash("You cannot assess a contribution without a type", "error")
44 return None
45 isActual = G(G(db.typeContribution, contribType), N.actual)
46 if not isActual: 46 ↛ 47line 46 didn't jump to line 47, because the condition on line 46 was never true
47 flash("You cannot assess a contribution with a legacy type", "error")
48 return None
50 fields = {
51 masterTable: masterOid,
52 N.assessmentType: contribType,
53 N.title: f"assessment of {contribTitle}",
54 }
55 criteria = G(typeCriteria, contribType, default=[])
56 if not criteria: 56 ↛ 57line 56 didn't jump to line 57, because the condition on line 56 was never true
57 flash("This contribution type has no criteria", "error")
58 return None
60 assessmentId = db.insertItem(table, uid, eppn, False, **fields)
62 records = [
63 {N.seq: seq, N.criteria: crit, N.assessment: assessmentId}
64 for (seq, crit) in enumerate(criteria)
65 ]
66 db.insertMany(N.criteriaEntry, uid, eppn, records)
67 self.adjustWorkflow(masterOid, new=False)
69 return assessmentId