Index: /WAeUP_SRP/trunk/WAeUPTables.py
===================================================================
--- /WAeUP_SRP/trunk/WAeUPTables.py	(revision 1953)
+++ /WAeUP_SRP/trunk/WAeUPTables.py	(revision 1954)
@@ -392,5 +392,4 @@
         reindextypes = {}
         reindex_special = []
-        #import pdb;pdb.set_trace()
         for n in name:
             if n in ("review_state","registered_courses"):
@@ -405,5 +404,8 @@
                         break
         students = self.portal_catalog(portal_type="Student")
-        aq_portal = self.portal_catalog.evalAdvancedQuery
+        if hasattr(self,'portal_catalog_real'):
+            aq_portal = self.portal_catalog_real.evalAdvancedQuery
+        else:
+            aq_portal = self.portal_catalog.evalAdvancedQuery
         num_objects = len(students)
         if pghandler:
@@ -433,5 +435,4 @@
                     else:
                         data[field] = getattr(doc,field)
-                #from pdb import set_trace;set_trace()
             if not sub_objects and noattr:
                 import_res = self.returning_import(id = sid)
@@ -446,30 +447,21 @@
                 data['jamb_reg_no'] = import_record.Entryregno
             if reindex_special and 'registered_courses' in reindex_special:
-                query = Eq('id','study_course') & Eq('path',student_brain.getPath())
-                brains = aq_portal(query)
-                while brains:
-                    study_course_path = brains[0].getPath()
-                    level_brains = self.portal_catalog(path = study_course_path,
-                                                       portal_type = "StudentStudyLevel")
-                    if not level_brains:
-                        break
-                    modified = True
-                    level_ids = [l.getId for l in level_brains]
-                    level_ids.sort()
-                    for l in level_brains:
-                        if l.getId == level_ids[-1]:
-                            level_path = l.getPath()
-                            break
-                    result_brains = self.portal_catalog(path = level_path,
-                                                        portal_type = "StudentCourseResult")
-                    course_ids = [cr.getId for cr in result_brains]
-                    courses = []
-                    for c in course_ids:
-                        if c.endswith('_co'):
-                            courses.append(c[:-3])
-                        else:
-                            courses.append(c)
-                    data['registered_courses'] = courses
-                    break
+                try:
+                    study_course = getattr(student_object,"study_course")
+                    level_ids = study_course.objectIds()
+                except:
+                    continue
+                if not level_ids:
+                    continue
+                modified = True
+                level_ids.sort()
+                course_ids = getattr(study_course,level_ids[-1]).objectIds()
+                courses = []
+                for c in course_ids:
+                    if c.endswith('_co'):
+                        courses.append(c[:-3])
+                    else:
+                        courses.append(c)
+                data['registered_courses'] = courses
             if modified:
                 self.modifyRecord(**data)
@@ -543,5 +535,5 @@
         pt = getattr(object,'portal_type',None)
         mt = getattr(object,'meta_type',None)
-        students_catalog = self.students_catalog
+        students_catalog = self
         data = {}
         if pt == 'Student' and\
@@ -564,27 +556,19 @@
             if event_type not in ("sys_add_object","sys_del_object"):
                 return
+            #import pdb;pdb.set_trace()
             course_id = object.getId()
+            if course_id.endswith('_co'):
+                course_id = course_id[:-3]
             student_id = object.absolute_url_path().split('/')[-4]
-            res = self(id = student_id)
+            res = students_catalog(id = student_id)
             if not res:
                 return
             student_rec = res[0]
             registered_courses = student_rec.registered_courses
-            if not registered_courses:
-                level_obj = object.aq_parent
-                courses = []
-                for c in level_obj.objectIds():
-                    if c.endswith('_co'):
-                        courses.append(c[:-3])
-                    else:
-                        courses.append(c)
-                #from pdb import set_trace;set_trace()
-                registered_courses = courses
-            else:
-                if event_type == "sys_add_object":
-                    registered_courses.append(course_id)
-                if event_type == "sys_del_object":
-                    if course_id in registered_courses:
-                        registered_courses.remove(course_id)
+            if event_type == "sys_add_object" and course_id not in registered_courses:
+                registered_courses.append(course_id)
+            elif event_type == "sys_del_object":
+                while course_id in registered_courses:
+                    registered_courses.remove(course_id)
             data['id'] = student_id
             data['registered_courses'] = registered_courses
