author | Daniel Diniz <ajaksu@gmail.com> |
Mon, 06 Jul 2009 16:13:27 +0200 | |
changeset 2560 | a944c0169ad8 |
parent 2198 | 95ac403c6dd4 |
permissions | -rw-r--r-- |
1422
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
2 |
# |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
4 |
# |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
8 |
# |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
10 |
# |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
16 |
|
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
17 |
"""Student Proposal (Model) query functions. |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
18 |
""" |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
19 |
|
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
21 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
22 |
] |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
23 |
|
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
24 |
|
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
25 |
from soc.logic.models import base |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
26 |
from soc.logic.models import student as student_logic |
1611
83e7b09ce959
Brown paper bag fix in student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1610
diff
changeset
|
27 |
from soc.models import student_proposal |
1422
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
28 |
|
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
29 |
import soc.models.linkable |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
30 |
import soc.models.student_proposal |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
31 |
|
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
32 |
|
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
33 |
class Logic(base.Logic): |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
34 |
"""Logic methods for the Student Proposal model. |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
35 |
""" |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
36 |
|
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
37 |
def __init__(self, model=soc.models.student_proposal.StudentProposal, |
1624
1fc2089f4bc9
Fix too long lines in soc.logic.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1623
diff
changeset
|
38 |
base_model=soc.models.linkable.Linkable, |
1fc2089f4bc9
Fix too long lines in soc.logic.models.student_proposal module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1623
diff
changeset
|
39 |
scope_logic=student_logic): |
1422
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
40 |
"""Defines the name, key_name and model for this entity. |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
41 |
""" |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
42 |
|
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
43 |
super(Logic, self).__init__(model=model, base_model=base_model, |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
44 |
scope_logic=scope_logic) |
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
45 |
|
1786
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
46 |
|
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
47 |
def getRankerFor(self, entity): |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
48 |
"""Returns the ranker for the given Student Proposal. |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
49 |
|
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
50 |
Args: |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
51 |
entity: Student Proposal entity for which the ranker should be returned |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
52 |
|
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
53 |
Returns: |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
54 |
Ranker object which is used to rank the given entity |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
55 |
""" |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
56 |
|
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
57 |
from soc.logic.models.ranker_root import logic as ranker_root_logic |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
58 |
|
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
59 |
fields = {'link_id': student_proposal.DEF_RANKER_NAME, |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
60 |
'scope': entity.org} |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
61 |
|
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
62 |
ranker_root = ranker_root_logic.getForFields(fields, unique=True) |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
63 |
ranker = ranker_root_logic.getRootFromEntity(ranker_root) |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
64 |
|
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
65 |
return ranker |
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
66 |
|
2198
95ac403c6dd4
Renamed stepsize to step_size in Student Proposal Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2197
diff
changeset
|
67 |
def getProposalsToBeAcceptedForOrg(self, org_entity, step_size=25): |
2197
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
68 |
"""Returns all StudentProposals which will be accepted into the program |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
69 |
for the given organization. |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
70 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
71 |
params: |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
72 |
org_entity: the Organization for which the proposals should be checked |
2198
95ac403c6dd4
Renamed stepsize to step_size in Student Proposal Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2197
diff
changeset
|
73 |
step_size: optional parameter to specify the amount of Student Proposals |
2197
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
74 |
that should be retrieved per roundtrip to the datastore |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
75 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
76 |
returns: |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
77 |
List with all StudentProposal which will be accepted into the program |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
78 |
""" |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
79 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
80 |
# check if there are already slots taken by this org |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
81 |
fields = {'org': org_entity, |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
82 |
'status': 'accepted'} |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
83 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
84 |
query = self.getQueryForFields(fields) |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
85 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
86 |
slots_left_to_assign = max(0, org_entity.slots - query.count()) |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
87 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
88 |
if slots_left_to_assign == 0: |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
89 |
# no slots left so return nothing |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
90 |
return [] |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
91 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
92 |
fields = {'org': org_entity, |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
93 |
'status': 'pending'} |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
94 |
order = ['-score'] |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
95 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
96 |
# get the the number of proposals that would be assigned a slot |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
97 |
query = self.getQueryForFields( |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
98 |
fields, order=order) |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
99 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
100 |
proposals = query.fetch(slots_left_to_assign) |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
101 |
proposals = [i for i in proposals if i.mentor] |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
102 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
103 |
offset = slots_left_to_assign |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
104 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
105 |
# retrieve as many additional proposals as needed in case the top |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
106 |
# N do not have a mentor assigned |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
107 |
while len(proposals) < slots_left_to_assign: |
2198
95ac403c6dd4
Renamed stepsize to step_size in Student Proposal Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2197
diff
changeset
|
108 |
new_proposals = query.fetch(step_size, offset=offset) |
2197
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
109 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
110 |
if not new_proposals: |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
111 |
# we ran out of proposals` |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
112 |
break |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
113 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
114 |
new_proposals = [i for i in new_proposals if i.mentor] |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
115 |
proposals += new_proposals |
2198
95ac403c6dd4
Renamed stepsize to step_size in Student Proposal Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2197
diff
changeset
|
116 |
offset += step_size |
2197
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
117 |
|
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
118 |
# cut off any superfluous proposals |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
119 |
return proposals[:slots_left_to_assign] |
efa28a1ccf76
Moved the code to retrieve all Proposal which should be accepted for one Organization to the Proposal Logic module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2160
diff
changeset
|
120 |
|
1610
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
121 |
def _onCreate(self, entity): |
1623
8b70d6bb3f8f
Renamed rankerroot to ranker_root and made some changes due to comments.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1612
diff
changeset
|
122 |
"""Adds this proposal to the organization ranker entity. |
1610
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
123 |
""" |
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
124 |
|
1786
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
125 |
ranker = self.getRankerFor(entity) |
2160
3f9dd37d98a8
Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1885
diff
changeset
|
126 |
ranker.SetScore(entity.key().id_or_name(), [entity.score]) |
1610
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
127 |
|
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
128 |
super(Logic, self)._onCreate(entity) |
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
129 |
|
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
130 |
def _updateField(self, entity, entity_properties, name): |
1753
564f3adf4acf
Students who withdraw their proposal will now be removed from the ranker.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1624
diff
changeset
|
131 |
"""Called when the fields of the student_proposal are updated. |
564f3adf4acf
Students who withdraw their proposal will now be removed from the ranker.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1624
diff
changeset
|
132 |
|
564f3adf4acf
Students who withdraw their proposal will now be removed from the ranker.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1624
diff
changeset
|
133 |
- Update the ranker if the score changes and keep the score within bounds |
564f3adf4acf
Students who withdraw their proposal will now be removed from the ranker.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1624
diff
changeset
|
134 |
- Remove the entity from the ranker when the status changes to invalid or rejected |
1610
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
135 |
""" |
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
136 |
|
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
137 |
value = entity_properties[name] |
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
138 |
|
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
139 |
if name == 'score': |
1612
09bccdf6bdec
Keep the score within the allowed bounds via student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1611
diff
changeset
|
140 |
# keep the score within bounds |
09bccdf6bdec
Keep the score within the allowed bounds via student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1611
diff
changeset
|
141 |
min_score, max_score = student_proposal.DEF_SCORE |
09bccdf6bdec
Keep the score within the allowed bounds via student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1611
diff
changeset
|
142 |
|
09bccdf6bdec
Keep the score within the allowed bounds via student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1611
diff
changeset
|
143 |
value = max(min_score, min(value, max_score-1)) |
09bccdf6bdec
Keep the score within the allowed bounds via student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1611
diff
changeset
|
144 |
entity_properties[name] = value |
09bccdf6bdec
Keep the score within the allowed bounds via student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1611
diff
changeset
|
145 |
|
09bccdf6bdec
Keep the score within the allowed bounds via student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1611
diff
changeset
|
146 |
# update the ranker |
1786
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
147 |
ranker = self.getRankerFor(entity) |
2160
3f9dd37d98a8
Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1885
diff
changeset
|
148 |
ranker.SetScore(entity.key().id_or_name(), [value]) |
1610
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
149 |
|
1753
564f3adf4acf
Students who withdraw their proposal will now be removed from the ranker.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1624
diff
changeset
|
150 |
if name == 'status': |
564f3adf4acf
Students who withdraw their proposal will now be removed from the ranker.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1624
diff
changeset
|
151 |
|
564f3adf4acf
Students who withdraw their proposal will now be removed from the ranker.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1624
diff
changeset
|
152 |
if value in ['invalid', 'rejected'] and entity.status != value: |
564f3adf4acf
Students who withdraw their proposal will now be removed from the ranker.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1624
diff
changeset
|
153 |
# the proposal is going into invalid or rejected state |
564f3adf4acf
Students who withdraw their proposal will now be removed from the ranker.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1624
diff
changeset
|
154 |
# remove the score from the ranker |
1786
d9694a1f1a56
Added getRankerFor method to student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1753
diff
changeset
|
155 |
ranker = self.getRankerFor(entity) |
1753
564f3adf4acf
Students who withdraw their proposal will now be removed from the ranker.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1624
diff
changeset
|
156 |
|
564f3adf4acf
Students who withdraw their proposal will now be removed from the ranker.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1624
diff
changeset
|
157 |
# entries in the ranker can be removed by setting the score to None |
2160
3f9dd37d98a8
Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1885
diff
changeset
|
158 |
ranker.SetScore(entity.key().id_or_name(), None) |
1612
09bccdf6bdec
Keep the score within the allowed bounds via student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1611
diff
changeset
|
159 |
|
1610
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
160 |
return super(Logic, self)._updateField(entity, entity_properties, name) |
6f675b690f92
Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1422
diff
changeset
|
161 |
|
1884
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
162 |
def delete(self, entity): |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
163 |
"""Removes Ranker entry and all ReviewFollowers before deleting the entity. |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
164 |
|
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
165 |
Args: |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
166 |
entity: an existing entity in datastore |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
167 |
""" |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
168 |
|
1885
6b7d5e6a7fd2
Fixed an Epic Fail in StudentProposal logic ^_^.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1884
diff
changeset
|
169 |
from soc.logic.models.review_follower import logic as review_follower_logic |
1884
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
170 |
|
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
171 |
# entries in the ranker can be removed by setting the score to None |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
172 |
ranker = self.getRankerFor(entity) |
2160
3f9dd37d98a8
Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1885
diff
changeset
|
173 |
ranker.SetScore(entity.key().id_or_name(), None) |
1884
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
174 |
|
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
175 |
# get all the ReviewFollwers that have this entity as it's scope |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
176 |
fields = {'scope': entity} |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
177 |
|
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
178 |
# TODO be sure that this captures all the followers |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
179 |
followers = review_follower_logic.getForFields(fields) |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
180 |
|
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
181 |
for follower in followers: |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
182 |
review_follower_logic.delete(follower) |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
183 |
|
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
184 |
# call to super to complete the deletion |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
185 |
super(Logic, self).delete(entity) |
90b372ece1a5
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1786
diff
changeset
|
186 |
|
1422
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
187 |
|
052218c51035
Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
188 |
logic = Logic() |