61 |
61 |
62 ranker_root = ranker_root_logic.getForFields(fields, unique=True) |
62 ranker_root = ranker_root_logic.getForFields(fields, unique=True) |
63 ranker = ranker_root_logic.getRootFromEntity(ranker_root) |
63 ranker = ranker_root_logic.getRootFromEntity(ranker_root) |
64 |
64 |
65 return ranker |
65 return ranker |
|
66 |
|
67 def getProposalsToBeAcceptedForOrg(self, org_entity, stepsize=25): |
|
68 """Returns all StudentProposals which will be accepted into the program |
|
69 for the given organization. |
|
70 |
|
71 params: |
|
72 org_entity: the Organization for which the proposals should be checked |
|
73 stepsize: optional parameter to specify the ammount of Student Proposals |
|
74 that should be retrieved per roundtrip to the datastore |
|
75 |
|
76 returns: |
|
77 List with all StudentProposal which will be accepted into the program |
|
78 """ |
|
79 |
|
80 # check if there are already slots taken by this org |
|
81 fields = {'org': org_entity, |
|
82 'status': 'accepted'} |
|
83 |
|
84 query = self.getQueryForFields(fields) |
|
85 |
|
86 slots_left_to_assign = max(0, org_entity.slots - query.count()) |
|
87 |
|
88 if slots_left_to_assign == 0: |
|
89 # no slots left so return nothing |
|
90 return [] |
|
91 |
|
92 fields = {'org': org_entity, |
|
93 'status': 'pending'} |
|
94 order = ['-score'] |
|
95 |
|
96 # get the the number of proposals that would be assigned a slot |
|
97 query = self.getQueryForFields( |
|
98 fields, order=order) |
|
99 |
|
100 proposals = query.fetch(slots_left_to_assign) |
|
101 proposals = [i for i in proposals if i.mentor] |
|
102 |
|
103 offset = slots_left_to_assign |
|
104 |
|
105 # retrieve as many additional proposals as needed in case the top |
|
106 # N do not have a mentor assigned |
|
107 while len(proposals) < slots_left_to_assign: |
|
108 new_proposals = query.fetch(stepsize, offset=offset) |
|
109 |
|
110 if not new_proposals: |
|
111 # we ran out of proposals` |
|
112 break |
|
113 |
|
114 new_proposals = [i for i in new_proposals if i.mentor] |
|
115 proposals += new_proposals |
|
116 offset += stepsize |
|
117 |
|
118 # cut off any superfluous proposals |
|
119 return proposals[:slots_left_to_assign] |
66 |
120 |
67 def _onCreate(self, entity): |
121 def _onCreate(self, entity): |
68 """Adds this proposal to the organization ranker entity. |
122 """Adds this proposal to the organization ranker entity. |
69 """ |
123 """ |
70 |
124 |