|
1
|
|
|
from skf.database import db |
|
|
|
|
|
|
2
|
|
|
from skf.api.security import log, val_num, val_float |
|
3
|
|
|
from skf.database.checklists import checklists |
|
|
|
|
|
|
4
|
|
|
from skf.database.checklists_kb import checklists_kb |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
def get_checklist_item(checklist_id): |
|
8
|
|
|
log("User requested specific checklist item", "LOW", "PASS") |
|
9
|
|
|
val_float(checklist_id) |
|
10
|
|
|
|
|
11
|
|
|
result = checklists_kb.query.filter(checklists_kb.checklistID == checklist_id).one() |
|
12
|
|
|
return result |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
def get_checklist_items(): |
|
16
|
|
|
log("User requested list of checklist items", "LOW", "PASS") |
|
17
|
|
|
result = checklists_kb.query.group_by(checklists_kb.checklistID).paginate(1, 1500, False) |
|
18
|
|
|
return order_checklist_items(result) |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
def get_checklist_items_lvl(lvl): |
|
22
|
|
|
log("User requested list of checklist items based on level", "LOW", "PASS") |
|
23
|
|
|
val_num(lvl) |
|
24
|
|
|
if lvl == 1: |
|
25
|
|
|
result = checklists_kb.query.filter(checklists_kb.checklist_items.has(level = 0) | checklists_kb.checklist_items.has(level = 1)).group_by(checklists_kb.checklistID).paginate(1, 1500, False) |
|
26
|
|
|
elif lvl == 2: |
|
27
|
|
|
result = checklists_kb.query.filter(checklists_kb.checklist_items.has(level = 0) | checklists_kb.checklist_items.has(level = 1) | checklists_kb.checklist_items.has(level = 2)).group_by(checklists_kb.checklistID).paginate(1, 1500, False) |
|
28
|
|
|
elif lvl == 3: |
|
29
|
|
|
result = checklists_kb.query.filter(checklists_kb.checklist_items.has(level = 0) | checklists_kb.checklist_items.has(level = 1) | checklists_kb.checklist_items.has(level = 2) | checklists_kb.checklist_items.has(level = 3)).group_by(checklists_kb.checklistID).paginate(1, 1500, False) |
|
30
|
|
|
return order_checklist_items(result) |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
def order_checklist_items(checklist_items): |
|
34
|
|
|
ordered_checklist_items = [] |
|
35
|
|
|
for item in checklist_items.items: |
|
36
|
|
|
numbers = item.checklistID.split('.') |
|
37
|
|
|
category = int(numbers[0]) |
|
38
|
|
|
category_requirement = int(numbers[1]) |
|
39
|
|
|
if (len(ordered_checklist_items) == 0): |
|
40
|
|
|
ordered_checklist_items.append(item) |
|
41
|
|
|
else: |
|
42
|
|
|
y = 0 |
|
43
|
|
|
while y < len(ordered_checklist_items): |
|
44
|
|
|
numbers_ordered = ordered_checklist_items[y].checklistID.split('.') |
|
45
|
|
|
category_ordered = int(numbers_ordered[0]) |
|
46
|
|
|
category_requirement_ordered = int(numbers_ordered[1]) |
|
47
|
|
|
if (category < category_ordered): |
|
48
|
|
|
ordered_checklist_items.insert(y, item) |
|
49
|
|
|
break |
|
50
|
|
|
else: |
|
51
|
|
|
if (category == category_ordered): |
|
52
|
|
|
if (category_requirement < category_requirement_ordered): |
|
53
|
|
|
ordered_checklist_items.insert(y, item) |
|
54
|
|
|
break |
|
55
|
|
|
y = y + 1 |
|
56
|
|
|
if (y == len(ordered_checklist_items)): |
|
57
|
|
|
ordered_checklist_items.insert(y, item) |
|
58
|
|
|
checklist_items.items = ordered_checklist_items |
|
59
|
|
|
return checklist_items |
|
60
|
|
|
|
|
61
|
|
|
|