Index: /WAeUP_SRP/trunk/skins/waeup_student/search_students.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/search_students.py	(revision 1277)
+++ /WAeUP_SRP/trunk/skins/waeup_student/search_students.py	(revision 1278)
@@ -12,14 +12,18 @@
 list Students for ClearanceOfficers
 """
+import logging
+logger = logging.getLogger('Search.Timer')
+from DateTime import DateTime
+#
+#with_timer = True
+with_timer = False
+#
 request = REQUEST
 form = request.form
 fget = form.get
-#wftool = context.portal_workflow
 mtool = context.portal_membership
 member = mtool.getAuthenticatedMember()
 is_anon = mtool.isAnonymousUser()
-#roles = member.getRolesInContext(context)
 lt = context.portal_layouts
-#pr = context.portal_registration
 path_info = request.get('PATH_INFO').split('/')
 
@@ -27,5 +31,4 @@
 if is_anon:
     allowed = False
-
 try:
     from Products.AdvancedQuery import Eq, Between, Le,In
@@ -57,25 +60,37 @@
 user_info['departments'] = []
 user_info['faculties'] = []
-#from Products.zdb import set_trace
-#set_trace()
 co_view = False
+faculties =  fget('faculties')
+departments = fget('departments')
+dep_str = fac_str = ''
 if "ClearanceOfficers" in member.getGroups():
     state = "clearance_requested"
     only_review = False
     co_view = True
-    query = In('portal_type',('Faculty',)) &\
-             In('localUsersWithRoles', ("user:%s" % member,))
-    res = evalAdvancedQuery(query)
-    faculties = []
-    if res:
-        faculties = [f.getId for f in res]
-    user_info['faculties'] = faculties
-    query = In('portal_type',('Department',)) &\
-             In('localUsersWithRoles', ("user:%s" % member,))
-    res = evalAdvancedQuery(query)
-    departments = []
-    if res:
-        departments = [f.getId for f in res]
-    user_info['departments'] = departments
+    if faculties or departments:
+        #from Products.zdb import set_trace;set_trace()
+        if faculties:
+            fac_str = faculties
+            faculties = faculties.split()
+        if departments:
+            dep_str = departments
+            departments = departments.split()
+    else:
+        query = In('portal_type',('Faculty',)) &\
+                 In('localUsersWithRoles', ("user:%s" % member,))
+        res = evalAdvancedQuery(query)
+        faculties = []
+        if res:
+            faculties = [f.getId for f in res]
+        user_info['faculties'] = faculties
+        fac_str = " ".join(faculties)
+        query = In('portal_type',('Department',)) &\
+                 In('localUsersWithRoles', ("user:%s" % member,))
+        res = evalAdvancedQuery(query)
+        departments = []
+        if res:
+            departments = [f.getId for f in res]
+        user_info['departments'] = departments
+        dep_str = " ".join(departments)
 default = {'search_mode': 'student_id',
         'review_state': state,
@@ -89,4 +104,6 @@
                       layout_mode='edit',
                       formaction="search_students",
+                      faculties = fac_str,
+                      departments = dep_str,
                       commit = False,
                       )
@@ -140,10 +157,10 @@
         res = context.students_catalog(department=term.strip())
         search_set = [r.id for r in res]
+    elif what == "matric_no":
+        res = context.students_catalog(matric_no=term.strip())
+        search_set = [r.id for r in res]
     elif what in st_queries:
         if what == "jamb_reg_no":
             pt = ('StudentApplication',)
-            st = "%s" % term.strip().lower()
-        elif what == "matric_no":
-            pt = ('StudentClearance',)
             st = "%s" % term.strip().lower()
         elif what == "name":
@@ -156,23 +173,39 @@
                 pl = r.getPath().split('/')
                 search_set.append(pl[pl.index('students') + 1])
-elif co_view:
-    #from Products.zdb import set_trace
-    #set_trace()
+if only_review or with_review or co_view:
+    if with_timer:
+        start = DateTime().timeTime()
+        logger.info('"%s","start 100"' % member)
+    query = Eq('review_state',state)
+    review_res = evalAdvancedQuery(query)
+    if with_timer:
+        end = DateTime().timeTime()
+        logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
+if co_view:
     only_review = False
+    with_review = True
+    if with_timer:
+        start = DateTime().timeTime()
+        logger.info('"%s","start 200"' % member)
     query = In('faculty',faculties) | In('department',departments)
     res = aq_students(query)
+    if with_timer:
+        end = DateTime().timeTime()
+        logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
+    start = DateTime().timeTime()
     search_set = [r.id for r in res]
-if only_review or with_review:
-    query = Eq('review_state',state)
-    review_res = evalAdvancedQuery(query)
-review_set = []
+    if with_timer:
+        end = DateTime().timeTime()
+        logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
+if with_timer:
+    logger.info('"%s","start 300"' % member)
+    start = DateTime().timeTime()
 if review_res:
-    for r in review_res:
-        if r.portal_type == "StudentAccommodation":
-            start = r.getPath().find('/students/') + 10
-            review_set.append(r.getPath()[start:start+7])
-        else:
-            review_set.append(r.getId)
-#set_trace()
+    review_set = [r.getId for r in review_res]
+if with_timer:
+    end = DateTime().timeTime()
+    logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
+    logger.info('"%s","start 400"' % member)
+    start = DateTime().timeTime()
 if only_review:
     all = review_set
@@ -184,6 +217,12 @@
 else:
     all = search_set
+if with_timer:
+    end = DateTime().timeTime()
+    logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
 items = all[:500]
 students = []
+if with_timer:
+    logger.info('"%s","start 500"' % member)
+    start = DateTime().timeTime()
 if items:
     for item in items:
@@ -193,15 +232,9 @@
         for field in stcat.schema() + stcat.indexes():
             info[field] = getattr(record, field)
-##        if "ClearanceOfficers" in member.getGroups():
-##            co_view = True
-##            res = context.portal_catalog(portal_type='Student', id = item)
-##            if len(res) != 1:
-##                continue
-##            droles = member.getRolesInContext(res[0].getObject())
-##            info['review_state'] = res[0].review_state
-##            if "ClearanceOfficer" in droles:
-##                students.append(info)
         else:
             students.append(info)
+    if with_timer:
+        end = DateTime().timeTime()
+        logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
 
     return context.search_students_form(rendered = rend,
