app/soc/logic/models/student_proposal.py
changeset 1753 564f3adf4acf
parent 1624 1fc2089f4bc9
child 1786 d9694a1f1a56
equal deleted inserted replaced
1752:255117ccd6a0 1753:564f3adf4acf
    56     ranker.SetScore(entity.key().name(), [entity.score])
    56     ranker.SetScore(entity.key().name(), [entity.score])
    57 
    57 
    58     super(Logic, self)._onCreate(entity)
    58     super(Logic, self)._onCreate(entity)
    59 
    59 
    60   def _updateField(self, entity, entity_properties, name):
    60   def _updateField(self, entity, entity_properties, name):
    61     """Update the ranker if the score changes and keep the score within bounds.
    61     """Called when the fields of the student_proposal are updated.
       
    62 
       
    63       - Update the ranker if the score changes and keep the score within bounds
       
    64       - Remove the entity from the ranker when the status changes to invalid or rejected
    62     """
    65     """
    63 
    66 
    64     value = entity_properties[name]
    67     value = entity_properties[name]
    65 
    68 
    66     if name == 'score':
    69     if name == 'score':
    76 
    79 
    77       ranker_root = ranker_root_logic.getForFields(fields, unique=True)
    80       ranker_root = ranker_root_logic.getForFields(fields, unique=True)
    78       ranker = ranker_root_logic.getRootFromEntity(ranker_root)
    81       ranker = ranker_root_logic.getRootFromEntity(ranker_root)
    79       ranker.SetScore(entity.key().name(), [value])
    82       ranker.SetScore(entity.key().name(), [value])
    80 
    83 
       
    84     if name == 'status':
       
    85 
       
    86       if value in ['invalid', 'rejected'] and entity.status != value:
       
    87         # the proposal is going into invalid or rejected state
       
    88         # remove the score from the ranker
       
    89         fields = {'link_id': student_proposal.DEF_RANKER_NAME,
       
    90                   'scope': entity.org}
       
    91 
       
    92         ranker_root = ranker_root_logic.getForFields(fields, unique=True)
       
    93         ranker = ranker_root_logic.getRootFromEntity(ranker_root)
       
    94 
       
    95         # entries in the ranker can be removed by setting the score to None
       
    96         ranker.SetScore(entity.key().name(), None)
    81 
    97 
    82     return super(Logic, self)._updateField(entity, entity_properties, name)
    98     return super(Logic, self)._updateField(entity, entity_properties, name)
    83 
    99 
    84 
   100 
    85 logic = Logic()
   101 logic = Logic()