Index: /WAeUP_SRP/trunk/PatchCPSUserFolderUserFolder.py
===================================================================
--- /WAeUP_SRP/trunk/PatchCPSUserFolderUserFolder.py	(revision 2054)
+++ /WAeUP_SRP/trunk/PatchCPSUserFolderUserFolder.py	(revision 2055)
@@ -6,4 +6,13 @@
 security = ClassSecurityInfo()
 
+def getCertificateObject(self,st_entry):
+    try:
+        return getattr(getattr(getattr(self.portal_url.getPortalObject().campus.academics,
+                                                  st_entry.faculty),
+                                          st_entry_department).certificate,
+                                  st_entry.course)
+    except:
+        return None
+    
 security.declarePublic('getRolesInContext')
 def getRolesInContext(self, object):
@@ -95,5 +104,7 @@
                    real_object.portal_type not in ("Student",
                                                    "StudentClearance",
-                                                   "StudentStudyLevel"):
+                                                   "StudentStudyLevel",
+                                                   "StudentCourseResult",
+                                                  ):
             break
 
@@ -104,17 +115,17 @@
         # can be later simplified by replacing by students_catalog values - Henrik
         # getattr works always because of acquisition ?! Henrik
-        sc = getattr(real_object,'study_course',None)
-        if sc is None:
-            break
-        sc_obj = sc.getContent()
-        cert_id = sc_obj.study_course
-        res_cert = self.portal_catalog(id = cert_id)
-        if len(res_cert) != 1:
-            break
-        certificate_brain = res_cert[0]
-        certificate_obj = certificate_brain.getObject()
-        cert_path = certificate_brain.getPath().split('/')
-        fac_id = cert_path[-4]
-        dep_id = cert_path[-3]
+        # sc = getattr(real_object,'study_course',None)
+        # if sc is None:
+        #     break
+        # sc_obj = sc.getContent()
+        # cert_id = sc_obj.study_course
+        # res_cert = self.portal_catalog(id = cert_id)
+        # if len(res_cert) != 1:
+        #     break
+        # certificate_brain = res_cert[0]
+        # certificate_obj = certificate_brain.getObject()
+        # cert_path = certificate_brain.getPath().split('/')
+        # fac_id = cert_path[-4]
+        # dep_id = cert_path[-3]
         # temporary self-healing function
         # deprecated after reindexing the students_catalog
@@ -124,17 +135,30 @@
             break
         st_entry = res[0]
-        if st_entry.faculty != fac_id or\
-           st_entry.department != dep_id or\
-           st_entry.course != cert_id:
-               self.students_catalog.modifyRecord(id = student_id,
-                                                faculty = fac_id,
-                                                department = dep_id,
-                                                course = cert_id
-                                                )
-        if real_object.portal_type == "StudentStudyLevel":
-            if real_object.meta_type != "StudentStudyLevel":
-                context_obj = getattr(certificate_obj,real_object.getId(),None)
+        # if st_entry.faculty != fac_id or\
+        #    st_entry.department != dep_id or\
+        #    st_entry.course != cert_id:
+        #        self.students_catalog.modifyRecord(id = student_id,
+        #                                         faculty = fac_id,
+        #                                         department = dep_id,
+        #                                         course = cert_id
+        #                                         )
+        if real_object.portal_type in ("StudentStudyLevel","StudentCourseResult"):
+            # res_cert = self.portal_catalog(id = st_entry.course)
+            # if len(res_cert) != 1:
+            #     break
+            # certificate_brain = res_cert[0]
+            # certificate_obj = certificate_brain.getObject()
+            certificate_obj = getCertificateObject(self,st_entry)
+            if certificate_obj is None:
+                break
+            if real_object.meta_type.endswith('Folder'): # it is a proxy
+                object = real_object
             else:
-                context_obj = getattr(certificate_obj,real_object.aq_parent.getId(),None)
+                object = real_object.aq_parent
+            if real_object.portal_type == "StudentStudyLevel":
+                level = object.getId()
+            elif real_object.portal_type == "StudentCourseResult":
+                level = object.aq_parent.getId()
+            context_obj = getattr(certificate_obj,level,None)
             if context_obj is None:
                 #from pdb import set_trace;set_trace()
@@ -144,4 +168,7 @@
             #we need some special processing since CourseAdvisers are only
             #specified per StudyLevel
+            certificate_obj = getCertificateObject(self,st_entry)
+            if certificate_obj is None:
+                break
             allowed = set(('CourseAdviser', 'SectionManager'))
             for context_obj in certificate_obj.objectValues():
