20 __authors__ = [ |
20 __authors__ = [ |
21 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
21 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
22 ] |
22 ] |
23 |
23 |
24 |
24 |
|
25 from google.appengine.ext import db |
|
26 |
25 from soc.logic.models import base |
27 from soc.logic.models import base |
26 from soc.logic.models import organization as org_logic |
28 from soc.logic.models import organization as org_logic |
27 |
29 |
28 import soc.models.linkable |
30 import soc.models.linkable |
29 import soc.models.student_project |
31 import soc.models.student_project |
40 """ |
42 """ |
41 |
43 |
42 super(Logic, self).__init__(model=model, base_model=base_model, |
44 super(Logic, self).__init__(model=model, base_model=base_model, |
43 scope_logic=scope_logic) |
45 scope_logic=scope_logic) |
44 |
46 |
|
47 def updateProjectsForGradingRecords(self, record_entities): |
|
48 """Updates StudentProjects using a list of GradingRecord entities. |
|
49 |
|
50 Args: |
|
51 record_entities: List of GradingRecord entities to process. |
|
52 """ |
|
53 |
|
54 projects_to_update = [] |
|
55 |
|
56 for record_entity in record_entities: |
|
57 |
|
58 project_entity = record_entity.project |
|
59 |
|
60 if project_entity.status in ['withdrawn', 'invalid']: |
|
61 # skip this project |
|
62 continue |
|
63 |
|
64 # get the key from the GradingRecord entity since that gets stored |
|
65 record_key = record_entity.key() |
|
66 |
|
67 passed_evals = project_entity.passed_evaluations |
|
68 failed_evals = project_entity.failed_evaluations |
|
69 |
|
70 # try to remove this GradingRecord from the existing list of evals |
|
71 if record_key in passed_evals: |
|
72 passed_evals.remove(record_key) |
|
73 |
|
74 if record_key in failed_evals: |
|
75 failed_evals.remove(record_key) |
|
76 |
|
77 # get the grade_decision from the GradingRecord |
|
78 grade_decision = record_entity.grade_decision |
|
79 |
|
80 # update GradingRecord lists with respect to the grading_decision |
|
81 if grade_decision == 'pass': |
|
82 passed_evals.append(record_key) |
|
83 elif grade_decision == 'fail': |
|
84 failed_evals.append(record_key) |
|
85 |
|
86 if project_entity.status != 'completed': |
|
87 # Only when the project has not been completed should the status be |
|
88 # updated to reflect the new setting of the evaluations. |
|
89 |
|
90 if len(failed_evals) == 0: |
|
91 # no failed evaluations present |
|
92 new_status = 'accepted' |
|
93 else: |
|
94 new_status = 'failed' |
|
95 else: |
|
96 new_status = project_entity.status |
|
97 |
|
98 # update the necessary fields and store it before updating |
|
99 project_entity.passed_evaluations = passed_evals |
|
100 project_entity.failed_evaluations = failed_evals |
|
101 project_entity.status = new_status |
|
102 |
|
103 projects_to_update.append(project_entity) |
|
104 |
|
105 # batch put the StudentProjects that need to be updated |
|
106 db.put(projects_to_update) |
|
107 |
45 |
108 |
46 logic = Logic() |
109 logic = Logic() |