# HG changeset patch # User Lennard de Rijk # Date 1237595407 0 # Node ID 5f1e3b5262cb8a4f4145e77e5776aa0e460f6d2c # Parent 0b7f57c16feecd7d14d90091704f85134fc1c4c0 Mentors cant resign when mentoring a project/proposal. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed diff -r 0b7f57c16fee -r 5f1e3b5262cb 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()