Changeset 7128 for main/waeup.sirp/trunk/src/waeup/sirp/students
- Timestamp:
- 17 Nov 2011, 13:56:53 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/studycourse.py
r6842 r7128 67 67 StudentStudyCourse = attrs_to_fields(StudentStudyCourse) 68 68 69 #@grok.subscribe(IStudentStudyCourse, grok.IObjectAddedEvent)70 #def handle_studycourse_added(obj, event):71 # """When a studycourse is added, update the local roles.72 # """73 # cert = getattr(obj, 'certificate', None)74 # if cert is None:75 # # cert never set yet, no need to update local roles.76 # return77 # update_local_roles(obj)78 # return79 80 @grok.subscribe(IStudentStudyCourse, grok.IObjectModifiedEvent)81 def handle_studycourse_modified(obj, event):82 """When a studycourse is changed, also update the local roles.83 """84 update_local_roles(obj)85 return86 87 def update_local_roles(studycourse):88 """Update local roles of given studycourse.89 """90 student = getattr(studycourse, '__parent__', None)91 if student is None:92 # not part of student, no need to update local roles93 return94 replace_local_clearance_officers(student)95 return96 97 def replace_local_clearance_officers(student):98 """Set local roles of given student.99 100 The local roles are determined by looking up desired101 principals. Then we remove those principals from local roles that102 are not wanted/outdated and add those wanted.103 """104 prm = IPrincipalRoleManager(student)105 curr_officers = prm.getPrincipalsForRole(106 'waeup.local.ClearanceOfficer')107 new_officers = get_valid_clearance_officers(student)108 #print "STUD %s, CURR: %s, NEW: %s" % (student, curr_officers,109 # new_officers)110 for officer in curr_officers:111 if officer in new_officers:112 continue113 prm.unsetRoleForPrincipal('waeup.local.ClearanceOfficer', officer)114 for officer in new_officers:115 if officer in curr_officers:116 continue117 prm.assignRoleToPrincipal('waeup.local.ClearanceOfficer', officer)118 119 return120 121 def get_valid_clearance_officers(student):122 """Lookup desired clearance officers for `student`.123 124 We look up the connected certificate, then its dept. and faculty125 to see which local roles are required: students get the clearance126 officers assigned to their certificate.127 128 Not sure, though, whether we really have to set the real clearance129 officer role for the wanted principals on the dept and faculty.130 """131 cert = getattr(student, 'certificate', None)132 if cert is None:133 return []134 dept = getattr(getattr(cert, '__parent__', None), '__parent__', None)135 fac = getattr(dept, '__parent__', None)136 if dept is None or fac is None:137 # not a serious cert138 return []139 # get officers (principals) responsible for the dept and faculty140 dept_officers = IPrincipalRoleManager(dept).getPrincipalsForRole(141 'waeup.local.ClearanceOfficer')142 fac_officers = IPrincipalRoleManager(fac).getPrincipalsForRole(143 'waeup.local.ClearanceOfficer')144 return dept_officers + fac_officers145 146 69 class StudentStudyCourseFactory(grok.GlobalUtility): 147 70 """A factory for students.
Note: See TracChangeset for help on using the changeset viewer.