Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal.
authorLennard de Rijk <ljvderijk@gmail.com>
Sun, 15 Mar 2009 20:40:03 +0000
changeset 1884 90b372ece1a5
parent 1883 ce564c03d90a
child 1885 6b7d5e6a7fd2
Delete all ReviewFollowers and remove the entry in the ranker before deleting a StudentProposal. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
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()