--- a/app/soc/logic/models/mentor.py Sat Mar 21 17:12:07 2009 +0000
+++ b/app/soc/logic/models/mentor.py Sat Mar 21 18:02:49 2009 +0000
@@ -22,6 +22,8 @@
]
+from google.appengine.ext import db
+
from soc.logic.models import role
from soc.logic.models import organization as org_logic
@@ -79,5 +81,37 @@
return super(Logic, self).canResign(entity)
+ def _updateField(self, entity, entity_properties, name):
+ """Called when the fields of the mentor are updated
+
+ When status is changed to invalid, removes the Mentor from all Student
+ Proposals possible mentor lists.
+ """
+
+ from soc.logic.models.student_proposal import logic as student_proposal_logic
+
+ value = entity_properties[name]
+
+ if name == 'status' and value != entity.status and value == 'invalid':
+ fields = {'org': entity.scope}
+
+ # TODO make this work for more then 1000 entities
+ proposals_query = student_proposal_logic.getQueryForFields(fields)
+
+ # store all updated proposals
+ changed = []
+
+ for proposal in proposals_query:
+
+ if proposal.possible_mentors.count(entity.key()):
+ # remove from list and add to changed
+ proposal.possible_mentors.remove(entity.key())
+ changed.append(proposal)
+
+ # store all changed proposals
+ db.put(changed)
+
+ return super(Logic, self)._updateField(entity, entity_properties, name)
+
logic = Logic()