Index: WAeUP_SRP/trunk/skins/waeup_student/search_students.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_student/search_students.py	(revision 1061)
+++ WAeUP_SRP/trunk/skins/waeup_student/search_students.py	(revision 1065)
@@ -15,12 +15,15 @@
 form = request.form
 fget = form.get
-wftool = context.portal_workflow
+#wftool = context.portal_workflow
 mtool = context.portal_membership
 member = mtool.getAuthenticatedMember()
-roles = member.getRolesInContext(context)
-students_folder = context.portal_url.getPortalObject().campus.students
+#roles = member.getRolesInContext(context)
+lt = context.portal_layouts
+#pr = context.portal_registration
+path_info = request.get('PATH_INFO').split('/')
 try:
     from Products.AdvancedQuery import Eq, Between, Le,In
     evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery
+    aq_students = context.students_catalog.evalAdvancedQuery
 except:
     evalAdvancedQuery = None
@@ -37,20 +40,36 @@
                       "StudentStudyLevel",)
 
-student_objects = student_subobjects + ("Student",)
-
-info = {}
+#student_objects = student_subobjects + ("Student",)
+student_objects = ("Student",)
+
+user_info = {}
 items = []
-wf = context.portal_workflow
-#student_wf_states = wf.waeup_student_wf.states.keys()
-#info['wf_states'] = student_wf_states
-#info['wf_states'][0] = " ----- "
-lt = context.portal_layouts
-pr = context.portal_registration
-path_info = request.get('PATH_INFO').split('/')
 validate = request.has_key("cpsdocument_edit_button")
 
 state = "all"
+user_info['member'] = str(member)
+user_info['departments'] = []
+user_info['faculties'] = []
+#from Products.zdb import set_trace
+#set_trace()
+co_view = False
 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
 default = {'search_mode': 'name',
         'review_state': state,
@@ -70,4 +89,5 @@
                              psm = psm,
                              #psm = "%s, %s" % (psm,ds),
+                             info = user_info,
                              students = [],
                              allowed = True,
@@ -90,4 +110,5 @@
                              psm = psm,
                              #psm = "%s, %s" % (psm,ds),
+                             info = user_info,
                              students = items,
                              allowed = True,
@@ -104,4 +125,5 @@
 if len(term) > 0:
     if what == "student_id":
+        students_folder = context.portal_url.getPortalObject().campus.students
         query_step = 1
         if hasattr(students_folder,term.strip()):
@@ -135,13 +157,26 @@
                 pl = r.getPath().split('/')
                 search_set.append(pl[pl.index('students') + 1])
+elif co_view:
+    #from Products.zdb import set_trace
+    #set_trace()
+    only_review = False
+    query = In('faculty',faculties) | In('department',departments) 
+    res = aq_students(query)
+    search_set = [r.id for r in res]
+##        res = context.students_catalog(faculty=faculties[0],)
+##        res = context.students_catalog(faculty=faculties,department=departments)
+#set_trace()
 if with_review:
     query_step += 10
-    review_res = evalAdvancedQuery(In('portal_type',student_objects) & Eq('review_state',state))
+    #review_res = evalAdvancedQuery(('portal_type',student_objects) & Eq('review_state',state))
+    review_res = evalAdvancedQuery(Eq('review_state',state))
 review_set = []
 if review_res:
     for r in review_res:
-        pl = r.getPath().split('/')
-        review_set.append(pl[pl.index('students') + 1])
+        #pl = r.getPath().split('/')
+        #review_set.append(pl[pl.index('students') + 1])
+        review_set.append(r.getId)
 all = []
+#set_trace()
 if only_review:
     all = review_set
@@ -152,11 +187,12 @@
 else:
     all = search_set
-for a in all[:500]:
-    if a in items:
-        continue
-    items.append(a)
+##for a in all[:50]:
+##    if a in items:
+##        continue
+##    items.append(a)
+items = all[:500]
 students = []
-items.sort()
-co_view = False
+#items.sort()
+
 if items:
     for item in items:
@@ -166,13 +202,13 @@
         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)
+##        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)
@@ -180,4 +216,5 @@
     return context.search_students_form(rendered = rend,
                              psm = "",
+                             info = user_info,
                              students = students,
                              allowed = True,
@@ -186,4 +223,5 @@
 return context.search_students_form(rendered = rend,
                              psm = "No student found!",
+                             info = user_info,
                              students = students,
                              allowed = True,
Index: WAeUP_SRP/trunk/skins/waeup_student/search_students_form.pt
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_student/search_students_form.pt	(revision 1061)
+++ WAeUP_SRP/trunk/skins/waeup_student/search_students_form.pt	(revision 1065)
@@ -2,4 +2,5 @@
             portal_status_message options/psm;
             students options/students;
+            info options/info|nothing;
             allowed options/allowed|nothing"
             >
@@ -16,5 +17,18 @@
         <metal:block use-macro="here/error_not_found/macros/not_found" />
       </span>
-      <span tal:condition="allowed"
+      <span tal:condition="allowed" tal:omit-tag="">
+        <h3> Search Student Section</h3><br />
+        <h4><span tal:replace="info/member|nothing" /> 
+          <span tal:condition="info/faculties|nothing" tal:omit-tag="">
+            is ClearanceOfficer for Faculty 
+            <span tal:repeat="faculty info/faculties" tal:content="faculty" />
+          </span>
+          <span tal:condition="info/departments|nothing" tal:omit-tag="">
+            and <span tal:repeat="department info/departments|nothing" tal:content="department"/>
+          </span>
+        <span tal:replace="structure rendered" />
+        </h4><br /><br />
+        
+      <span tal:condition="students"
         tal:define="items students;
         columns python:3;
@@ -29,10 +43,4 @@
         tal:omit-tag=""
         >
-      
-        <h3> Search Student Section</h3>
-        
-        <br />
-      
-        <span tal:replace="structure rendered" />
         <tal:block tal:condition="python: items and batch_info and batch_info['nb_pages'] > 1">
           <div class="batchLayout">
@@ -67,5 +75,5 @@
                           onclick="javascript:window.open('','edit','width=600, height=700, directories=no, toolbar=no, location=no, menubar=no, scrollbars=yes, status=no, resizable=no, dependent=no')"
                           >[change state]</a></td>
-                <td tal:condition="options/co_view|nothing"><span tal:replace="student/review_state" /></td>   
+                <td tal:condition="options/co_view|nothing"><span tal:replace="student/review_state|nothing" /></td>   
               </tr>
             </span>
@@ -110,4 +118,5 @@
         </tal:block>
       </span>
+      </span>
     </metal:main>
   </metal:body>
