# HG changeset patch # User Lennard de Rijk # Date 1237149603 0 # Node ID 90b372ece1a52b27910cef712279a045b1963e3b # Parent ce564c03d90a795a61e4550e37cacf3a09d22f70 Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed diff -r ce564c03d90a -r 90b372ece1a5 app/soc/logic/models/student_proposal.py --- a/app/soc/logic/models/student_proposal.py Sun Mar 15 20:27:50 2009 +0000 +++ b/app/soc/logic/models/student_proposal.py Sun Mar 15 20:40:03 2009 +0000 @@ -105,5 +105,30 @@ return super(Logic, self)._updateField(entity, entity_properties, name) + def delete(self, entity): + """Removes Ranker entry and all ReviewFollowers before deleting the entity. + + Args: + entity: an existing entity in datastore + """ + + from soc.models.logic.review_follower import logic as review_follower_logic + + # entries in the ranker can be removed by setting the score to None + ranker = self.getRankerFor(entity) + ranker.SetScore(entity.key().name(), None) + + # get all the ReviewFollwers that have this entity as it's scope + fields = {'scope': entity} + + # TODO be sure that this captures all the followers + followers = review_follower_logic.getForFields(fields) + + for follower in followers: + review_follower_logic.delete(follower) + + # call to super to complete the deletion + super(Logic, self).delete(entity) + logic = Logic()