Index: /WAeUP_SRP/trunk/WAeUPTables.py
===================================================================
--- /WAeUP_SRP/trunk/WAeUPTables.py	(revision 1701)
+++ /WAeUP_SRP/trunk/WAeUPTables.py	(revision 1702)
@@ -32,4 +32,5 @@
 p_home = Globals.package_home(globals())
 i_home = Globals.INSTANCE_HOME
+from Products.AdvancedQuery import Eq, Between, Le,In
 
 from interfaces import IWAeUPTable
@@ -355,6 +356,95 @@
             return None
         return getattr(doc,'current_verdict',None)
-
-###)
+    ###)
+
+    def reindexIndex(self, name, REQUEST,pghandler=None): ###(
+        if isinstance(name, str):
+            name = (name,)
+        reindextypes = {} 
+        reindex_special = []
+        #import pdb;pdb.set_trace()
+        for n in name:
+            if n in ("review_state","registered_courses"):
+                reindex_special.append(n)
+            else:
+                for pt in self.affected_types.keys():
+                    if n in self.affected_types[pt]:
+                        if reindextypes.has_key(pt):
+                            reindextypes[pt].append(n)
+                        else:
+                            reindextypes[pt]= [n]
+                        break
+        students = self.portal_catalog(portal_type="Student")
+        aq_portal = self.portal_catalog.evalAdvancedQuery
+        num_objects = len(students)
+        if pghandler:
+            pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects)
+        noattr = set(('StudentClearance','StudentPersonal')) & set(reindextypes.keys())
+        for i in xrange(num_objects):
+            if pghandler: pghandler.report(i)
+            student_brain = students[i]
+            data = {}
+            modified = False
+            sid = data['id'] = student_brain.getId
+            if reindex_special and 'review_state' in reindex_special:
+                modified = True
+                data['review_state'] = student_brain.review_state
+            if reindextypes:
+                query = Eq('path',student_brain.getPath())
+                sub_brains = aq_portal(query)
+                modified = True
+                spath = student_brain.getPath()
+                if len(sub_brains) > 1:
+                    for sub_brain in sub_brains:
+                        if not sub_brain.portal_type in reindextypes.keys():
+                            continue
+                        doc = sub_brain.getObject().getContent()
+                        for field in self.affected_types[sub_brain.portal_type]:
+                            if hasattr(self,'get_from_doc_%s' % field):
+                                data[field] = getattr(self,'get_from_doc_%s' % field)(doc)
+                            else:
+                                data[field] = getattr(doc,field)
+                elif len(sub_brains) == 1 and noattr:
+                    import_res = self.returning_import(id = sid)
+                    if not import_res:
+                        continue
+                    import_record = import_res[0]
+                    data['matric_no'] = import_record.matric_no
+                    data['sex'] = import_record.Sex == 'F'
+                    data['name'] = "%s %s %s" % (import_record.Firstname,
+                                                 import_record.Middlename,
+                                                 import_record.Lastname)
+                    data['matric_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
+            if modified:
+                self.modifyRecord(**data)
+        if pghandler: pghandler.finish()
+    ###)
 
     def refreshCatalog(self, clear=0, pghandler=None): ###(
@@ -422,7 +512,16 @@
     def notify_event_listener(self,event_type,object,infos):
         "listen for events"
-        pt = object.portal_type
-        mt = object.meta_type
+        pt = getattr(object,'portal_type',None)
+        mt = getattr(object,'meta_type',None)
         students_catalog = self.students_catalog
+        data = {}
+        if pt == 'Student' and\
+           mt == 'CPS Proxy Folder' and\
+           event_type.startswith('workflow'):
+            data['id'] = object.getId()
+            data['review_state'] = self.portal_workflow.getInfoFor(object,'review_state',None)
+            #from pdb import set_trace;set_trace()
+            students_catalog.modifyRecord(**data)
+            return
         if pt not in self.affected_types.keys():
             return
@@ -441,9 +540,8 @@
             
         if event_type not in ('sys_modify_object'):
+            from pdb import set_trace;set_trace()
             return
-        data = {}
         if mt == 'CPS Proxy Folder':
             return
-        #from pdb import set_trace;set_trace()
         for field in self.affected_types[pt]:
             if hasattr(self,'get_from_doc_%s' % field):
