Mentors cant resign when mentoring a project/proposal.
authorLennard de Rijk <ljvderijk@gmail.com>
Sat, 21 Mar 2009 00:30:07 +0000
changeset 1972 5f1e3b5262cb
parent 1971 0b7f57c16fee
child 1973 31d695f737ac
Mentors cant resign when mentoring a project/proposal. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/logic/models/mentor.py
--- a/app/soc/logic/models/mentor.py	Fri Mar 20 23:59:18 2009 +0000
+++ b/app/soc/logic/models/mentor.py	Sat Mar 21 00:30:07 2009 +0000
@@ -29,6 +29,13 @@
 import soc.models.role
 
 
+DEF_ALREADY_MENTORING_RPOJECT_MSG = "This Mentor is mentoring a Student "\
+    "Project and can therefore not be resigned. Please assign another Mentor."
+
+DEF_ALREADY_MENTORING_PROPOSAL_MSG = "This Mentor is mentoring a Student "\
+    "Proposal and can therefore not be resigned. Please assign another Mentor."
+
+
 class Logic(role.Logic):
   """Logic methods for the Mentor model.
   """
@@ -43,5 +50,34 @@
                                 scope_logic=scope_logic,
                                 disallow_last_resign=disallow_last_resign)
 
+  def canResign(self, entity):
+    """Checks if the Mentor is able to resign.
+
+    Checks if there are no Student Proposals or Student Projects that
+    have this mentor assigned to it.
+
+    Args:
+      entity: a Mentor entity
+
+    """
+
+    from soc.logic.models.student_project import logic as student_project_logic
+    from soc.logic.models.student_proposal import logic as student_proposal_logic
+
+    fields = {'mentor': entity}
+
+    student_project_entity = student_project_logic.getForFields(fields,
+                                                                unique=True)
+    if student_project_entity:
+      return DEF_ALREADY_MENTORING_RPOJECT_MSG
+
+    student_proposal_entity = student_proposal_logic.getForFields(fields,
+                                                                  unique=True)
+
+    if student_proposal_entity:
+      return DEF_ALREADY_MENTORING_PROPOSAL_MSG
+
+    return super(Logic, self).canResign(entity)
+
 
 logic = Logic()