Keep the score within the allowed bounds via student_proposal logic.
Patch by: Lennard de Rijk
Reviewed by: to-be-reviewed
--- a/app/soc/logic/models/student_proposal.py Tue Mar 03 22:52:11 2009 +0000
+++ b/app/soc/logic/models/student_proposal.py Tue Mar 03 23:01:31 2009 +0000
@@ -57,12 +57,19 @@
super(Logic, self)._onCreate(entity)
def _updateField(self, entity, entity_properties, name):
- """Update the ranker if the score changes
+ """Update the ranker if the score changes and keep the score within bounds.
"""
value = entity_properties[name]
if name == 'score':
+ # keep the score within bounds
+ min_score, max_score = student_proposal.DEF_SCORE
+
+ value = max(min_score, min(value, max_score-1))
+ entity_properties[name] = value
+
+ # update the ranker
fields = {'link_id': student_proposal.DEF_RANKER_NAME,
'scope': entity.org}
@@ -70,6 +77,7 @@
ranker = ranker_logic.logic.getRootFromEntity(ranker_root)
ranker.SetScore(entity.key().name(), [value])
+
return super(Logic, self)._updateField(entity, entity_properties, name)