1 | from skf.database import db |
||
2 | from skf.database.projects import projects |
||
3 | from skf.database.checklists_kb import checklists_kb |
||
4 | from skf.database.questions_pre import questions_pre |
||
5 | from skf.database.project_sprints import project_sprints |
||
6 | from skf.database.checklists_results import checklists_results |
||
7 | from skf.database.question_pre_results import question_pre_results |
||
8 | from skf.database.question_sprint_results import question_sprint_results |
||
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
9 | from skf.api.security import log, val_num, val_alpha |
||
10 | |||
11 | |||
12 | def get_pre_items(): |
||
13 | log("User requested list of question pre items", "LOW", "PASS") |
||
14 | result = questions_pre.query.paginate(1, 500, False) |
||
15 | return result |
||
16 | |||
17 | |||
18 | def store_pre_questions(user_id, data): |
||
19 | log("User stored new pre question list", "MEDIUM", "PASS") |
||
20 | val_num(user_id) |
||
21 | question = data.get('questions') |
||
22 | val_num(question[0]['projectID']) |
||
23 | project_id = question[0]['projectID'] |
||
24 | project_results = project_sprints.query.filter(project_sprints.projectID == project_id).one() |
||
25 | sprint_id = project_results.sprintID |
||
26 | projects_result = projects.query.filter(projects.projectID == project_id).one() |
||
27 | project_lvl = projects_result.level |
||
28 | status = 1 |
||
29 | pre_item = "True" |
||
30 | for result in data.get('questions'): |
||
31 | val_num(result['question_pre_ID']) |
||
32 | val_alpha(result['result']) |
||
33 | val_num(result['projectID']) |
||
34 | question_pre_ID = result['question_pre_ID'] |
||
35 | question_result = result['result'] |
||
36 | question_project_id = result['projectID'] |
||
37 | questions = question_pre_results(question_project_id, question_pre_ID, question_result) |
||
38 | db.session.add(questions) |
||
39 | db.session.commit() |
||
40 | questions_results = question_pre_results.query.filter(question_pre_results.projectID == question_project_id).filter(question_pre_results.result == "False").all() |
||
41 | for results in questions_results: |
||
42 | project_id = results.projectID |
||
43 | questionpreID = results.question_pre_ID |
||
44 | if project_lvl == 1: |
||
45 | checklists = checklists_kb.query.filter(checklists_kb.question_pre_ID == questionpreID).filter(checklists_kb.checklist_items.has(level = 0) | checklists_kb.checklist_items.has(level = 1)).group_by(checklists_kb.checklistID).order_by(checklists_kb.checklistID).all() |
||
46 | elif project_lvl == 2: |
||
47 | checklists = checklists_kb.query.filter(checklists_kb.question_pre_ID == questionpreID).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).order_by(checklists_kb.checklistID).all() |
||
48 | elif project_lvl == 3: |
||
49 | checklists = checklists_kb.query.filter(checklists_kb.question_pre_ID == questionpreID).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).order_by(checklists_kb.checklistID).all() |
||
50 | for row in checklists: |
||
51 | checklists_query = checklists_results(row.checklistID, project_id, sprint_id, status, pre_item, row.kbID) |
||
52 | db.session.add(checklists_query) |
||
53 | db.session.commit() |
||
54 | if project_lvl == 1: |
||
55 | checklists_first = checklists_kb.query.filter(checklists_kb.include_first == "True").filter(checklists_kb.checklist_items.has(level = 0) | checklists_kb.checklist_items.has(level = 1)).group_by(checklists_kb.checklistID).order_by(checklists_kb.checklistID).all() |
||
56 | elif project_lvl == 2: |
||
57 | checklists_first = checklists_kb.query.filter(checklists_kb.include_first == "True").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).order_by(checklists_kb.checklistID).all() |
||
58 | elif project_lvl == 3: |
||
59 | checklists_first = checklists_kb.query.filter(checklists_kb.include_first == "True").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).order_by(checklists_kb.checklistID).all() |
||
60 | for row in checklists_first: |
||
61 | checklists_query_first = checklists_results(row.checklistID, question_project_id, sprint_id, status, pre_item, row.kbID) |
||
62 | db.session.add(checklists_query_first) |
||
63 | db.session.commit() |
||
64 | return {'message': 'Pre questions successfully created'} |
||
65 | |||
66 | |||
67 | def update_pre_questions(project_id, user_id, data): |
||
68 | log("User updated pre question list", "MEDIUM", "PASS") |
||
69 | val_num(user_id) |
||
70 | val_num(project_id) |
||
71 | clear_question_pre_rows = db.session.query(question_pre_results).filter(question_pre_results.projectID == project_id) |
||
72 | clear_question_pre_rows.delete(synchronize_session=False) |
||
73 | clear_checklists_results_rows = db.session.query(checklists_results).filter(checklists_results.preItem == 'True').filter(checklists_results.projectID == project_id) |
||
74 | clear_checklists_results_rows.delete(synchronize_session=False) |
||
75 | db.session.commit() |
||
76 | project_results = project_sprints.query.filter(project_sprints.projectID == project_id).one() |
||
77 | sprint_id = project_results.sprintID |
||
78 | projects_result = projects.query.filter(projects.projectID == project_id).one() |
||
79 | project_lvl = projects_result.level |
||
80 | status = 1 |
||
81 | pre_item = "True" |
||
82 | for result in data.get('questions'): |
||
83 | val_num(result['question_pre_ID']) |
||
84 | val_alpha(result['result']) |
||
85 | question_pre_ID = result['question_pre_ID'] |
||
86 | question_result = result['result'] |
||
87 | questions = question_pre_results(project_id, question_pre_ID, question_result) |
||
88 | db.session.add(questions) |
||
89 | db.session.commit() |
||
90 | questions_results = question_pre_results.query.filter(question_pre_results.projectID == project_id).filter(question_pre_results.result == "False").all() |
||
91 | for results in questions_results: |
||
92 | projectID = results.projectID |
||
93 | questionpreID = results.question_pre_ID |
||
0 ignored issues
–
show
|
|||
94 | if project_lvl == 1: |
||
95 | checklists = checklists_kb.query.filter(checklists_kb.checklist_items.has(level = 0) | checklists_kb.checklist_items.has(level = 1)).group_by(checklists_kb.checklistID).order_by(checklists_kb.checklistID).all() |
||
96 | elif project_lvl == 2: |
||
97 | checklists = 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).order_by(checklists_kb.checklistID).all() |
||
98 | elif project_lvl == 3: |
||
99 | checklists = 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).order_by(checklists_kb.checklistID).all() |
||
100 | for row in checklists: |
||
101 | checklists_query = checklists_results(row.checklistID, projectID, sprint_id, status, pre_item, row.kbID) |
||
102 | db.session.add(checklists_query) |
||
103 | db.session.commit() |
||
104 | if project_lvl == 1: |
||
105 | checklists_first = checklists_kb.query.filter(checklists_kb.include_first == "True").filter(checklists_kb.checklist_items.has(level = 0) | checklists_kb.checklist_items.has(level = 1)).group_by(checklists_kb.checklistID).order_by(checklists_kb.checklistID).all() |
||
106 | elif project_lvl == 2: |
||
107 | checklists_first = checklists_kb.query.filter(checklists_kb.include_first == "True").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).order_by(checklists_kb.checklistID).all() |
||
108 | elif project_lvl == 3: |
||
109 | checklists_first = checklists_kb.query.filter(checklists_kb.include_first == "True").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).order_by(checklists_kb.checklistID).all() |
||
110 | for row in checklists_first: |
||
111 | checklists_query_first = checklists_results(row.checklistID, projectID, sprint_id, status, pre_item, row.kbID) |
||
112 | db.session.add(checklists_query_first) |
||
113 | db.session.commit() |
||
114 | return {'message': 'Pre questions successfully updated'} |
||
115 | |||
116 | |||
117 |