Hide keyboard shortcuts

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 

2 

3from config import Names as N 

4from control.utils import pick as G 

5from control.table import Table 

6from control.typ.related import castObjectId 

7 

8 

9class AssessmentT(Table): 

10 """Logic for the assessment table. 

11 

12 Inserting an assessment means also to insert the right 

13 set of criteriaEntry records and prefill some of their fields. 

14 """ 

15 

16 def __init__(self, *args, **kwargs): 

17 super().__init__(*args, **kwargs) 

18 

19 def insert(self, force=False, masterTable=None, masterId=None): 

20 mayInsert = force or self.mayInsert 

21 if not mayInsert: 21 ↛ 22line 21 didn't jump to line 22, because the condition on line 21 was never true

22 return None 

23 

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 

26 

27 context = self.context 

28 db = context.db 

29 uid = self.uid 

30 eppn = self.eppn 

31 table = self.table 

32 typeCriteria = db.typeCriteria 

33 

34 masterOid = castObjectId(masterId) 

35 

36 wfitem = context.getWorkflowItem(masterOid) 

37 

38 if not wfitem.permission(N.startAssessment): 38 ↛ 39line 38 didn't jump to line 39, because the condition on line 38 was never true

39 return None 

40 

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 

49 

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 

59 

60 assessmentId = db.insertItem(table, uid, eppn, False, **fields) 

61 

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) 

68 

69 return assessmentId