equal
deleted
inserted
replaced
27 |
27 |
28 import soc.models.mentor |
28 import soc.models.mentor |
29 import soc.models.role |
29 import soc.models.role |
30 |
30 |
31 |
31 |
|
32 DEF_ALREADY_MENTORING_RPOJECT_MSG = "This Mentor is mentoring a Student "\ |
|
33 "Project and can therefore not be resigned. Please assign another Mentor." |
|
34 |
|
35 DEF_ALREADY_MENTORING_PROPOSAL_MSG = "This Mentor is mentoring a Student "\ |
|
36 "Proposal and can therefore not be resigned. Please assign another Mentor." |
|
37 |
|
38 |
32 class Logic(role.Logic): |
39 class Logic(role.Logic): |
33 """Logic methods for the Mentor model. |
40 """Logic methods for the Mentor model. |
34 """ |
41 """ |
35 |
42 |
36 def __init__(self, model=soc.models.mentor.Mentor, |
43 def __init__(self, model=soc.models.mentor.Mentor, |
41 |
48 |
42 super(Logic, self).__init__(model=model, base_model=base_model, |
49 super(Logic, self).__init__(model=model, base_model=base_model, |
43 scope_logic=scope_logic, |
50 scope_logic=scope_logic, |
44 disallow_last_resign=disallow_last_resign) |
51 disallow_last_resign=disallow_last_resign) |
45 |
52 |
|
53 def canResign(self, entity): |
|
54 """Checks if the Mentor is able to resign. |
|
55 |
|
56 Checks if there are no Student Proposals or Student Projects that |
|
57 have this mentor assigned to it. |
|
58 |
|
59 Args: |
|
60 entity: a Mentor entity |
|
61 |
|
62 """ |
|
63 |
|
64 from soc.logic.models.student_project import logic as student_project_logic |
|
65 from soc.logic.models.student_proposal import logic as student_proposal_logic |
|
66 |
|
67 fields = {'mentor': entity} |
|
68 |
|
69 student_project_entity = student_project_logic.getForFields(fields, |
|
70 unique=True) |
|
71 if student_project_entity: |
|
72 return DEF_ALREADY_MENTORING_RPOJECT_MSG |
|
73 |
|
74 student_proposal_entity = student_proposal_logic.getForFields(fields, |
|
75 unique=True) |
|
76 |
|
77 if student_proposal_entity: |
|
78 return DEF_ALREADY_MENTORING_PROPOSAL_MSG |
|
79 |
|
80 return super(Logic, self).canResign(entity) |
|
81 |
46 |
82 |
47 logic = Logic() |
83 logic = Logic() |