22 ] |
22 ] |
23 |
23 |
24 |
24 |
25 from soc.logic.models import base |
25 from soc.logic.models import base |
26 from soc.logic.models import student as student_logic |
26 from soc.logic.models import student as student_logic |
27 from soc.logic.models.ranker_root import logic as ranker_root_logic |
|
28 from soc.models import student_proposal |
27 from soc.models import student_proposal |
29 |
28 |
30 import soc.models.linkable |
29 import soc.models.linkable |
31 import soc.models.student_proposal |
30 import soc.models.student_proposal |
32 |
31 |
42 """ |
41 """ |
43 |
42 |
44 super(Logic, self).__init__(model=model, base_model=base_model, |
43 super(Logic, self).__init__(model=model, base_model=base_model, |
45 scope_logic=scope_logic) |
44 scope_logic=scope_logic) |
46 |
45 |
|
46 |
|
47 def getRankerFor(self, entity): |
|
48 """Returns the ranker for the given Student Proposal. |
|
49 |
|
50 Args: |
|
51 entity: Student Proposal entity for which the ranker should be returned |
|
52 |
|
53 Returns: |
|
54 Ranker object which is used to rank the given entity |
|
55 """ |
|
56 |
|
57 from soc.logic.models.ranker_root import logic as ranker_root_logic |
|
58 |
|
59 fields = {'link_id': student_proposal.DEF_RANKER_NAME, |
|
60 'scope': entity.org} |
|
61 |
|
62 ranker_root = ranker_root_logic.getForFields(fields, unique=True) |
|
63 ranker = ranker_root_logic.getRootFromEntity(ranker_root) |
|
64 |
|
65 return ranker |
|
66 |
47 def _onCreate(self, entity): |
67 def _onCreate(self, entity): |
48 """Adds this proposal to the organization ranker entity. |
68 """Adds this proposal to the organization ranker entity. |
49 """ |
69 """ |
50 |
70 |
51 fields = {'link_id': student_proposal.DEF_RANKER_NAME, |
71 ranker = self.getRankerFor(entity) |
52 'scope': entity.org} |
|
53 |
|
54 ranker_root = ranker_root_logic.getForFields(fields, unique=True) |
|
55 ranker = ranker_root_logic.getRootFromEntity(ranker_root) |
|
56 ranker.SetScore(entity.key().name(), [entity.score]) |
72 ranker.SetScore(entity.key().name(), [entity.score]) |
57 |
73 |
58 super(Logic, self)._onCreate(entity) |
74 super(Logic, self)._onCreate(entity) |
59 |
75 |
60 def _updateField(self, entity, entity_properties, name): |
76 def _updateField(self, entity, entity_properties, name): |
72 |
88 |
73 value = max(min_score, min(value, max_score-1)) |
89 value = max(min_score, min(value, max_score-1)) |
74 entity_properties[name] = value |
90 entity_properties[name] = value |
75 |
91 |
76 # update the ranker |
92 # update the ranker |
77 fields = {'link_id': student_proposal.DEF_RANKER_NAME, |
93 ranker = self.getRankerFor(entity) |
78 'scope': entity.org} |
|
79 |
|
80 ranker_root = ranker_root_logic.getForFields(fields, unique=True) |
|
81 ranker = ranker_root_logic.getRootFromEntity(ranker_root) |
|
82 ranker.SetScore(entity.key().name(), [value]) |
94 ranker.SetScore(entity.key().name(), [value]) |
83 |
95 |
84 if name == 'status': |
96 if name == 'status': |
85 |
97 |
86 if value in ['invalid', 'rejected'] and entity.status != value: |
98 if value in ['invalid', 'rejected'] and entity.status != value: |
87 # the proposal is going into invalid or rejected state |
99 # the proposal is going into invalid or rejected state |
88 # remove the score from the ranker |
100 # remove the score from the ranker |
89 fields = {'link_id': student_proposal.DEF_RANKER_NAME, |
101 ranker = self.getRankerFor(entity) |
90 'scope': entity.org} |
|
91 |
|
92 ranker_root = ranker_root_logic.getForFields(fields, unique=True) |
|
93 ranker = ranker_root_logic.getRootFromEntity(ranker_root) |
|
94 |
102 |
95 # entries in the ranker can be removed by setting the score to None |
103 # entries in the ranker can be removed by setting the score to None |
96 ranker.SetScore(entity.key().name(), None) |
104 ranker.SetScore(entity.key().name(), None) |
97 |
105 |
98 return super(Logic, self)._updateField(entity, entity_properties, name) |
106 return super(Logic, self)._updateField(entity, entity_properties, name) |