Index: /WAeUP_SRP/trunk/PatchBasicWidgetsUnprepare.py
===================================================================
--- /WAeUP_SRP/trunk/PatchBasicWidgetsUnprepare.py	(revision 1065)
+++ /WAeUP_SRP/trunk/PatchBasicWidgetsUnprepare.py	(revision 1065)
@@ -0,0 +1,9 @@
+def unprepare(self, datastructure):
+    # Remove costly things already stored from the datastructure
+    try:
+        del datastructure[self.getWidgetId()]
+    except KeyError:
+        # unprepare may be called several times
+        pass
+from Products.CPSSchemas import BasicWidgets
+BasicWidgets.unprepare = unprepare
Index: /WAeUP_SRP/trunk/Students.py
===================================================================
--- /WAeUP_SRP/trunk/Students.py	(revision 1064)
+++ /WAeUP_SRP/trunk/Students.py	(revision 1065)
@@ -545,4 +545,99 @@
     ###)
 
+    security.declareProtected(ModifyPortalContent,"updateStudyCourse")###(
+    def updateStudyCourse(self):
+        """update StudyCourse from CSV values"""
+        import transaction
+        import random
+        from pdb import set_trace
+        wftool = self.portal_workflow
+        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
+        csv_d = {'jamb_reg_no': "RegNumber",
+                 'jamb_lastname': "Name",
+                 'session': "Session",
+                 'pume_tot_score': "PUME SCORE",
+                 'jamb_score': "JambScore",
+                 'jamb_sex': "Sex",
+                 'jamb_state': "State",
+##                 'jamb_first_cos': "AdminCourse",
+                 'faculty': "AdminFaculty",
+                 'course_code': "AdmitCoscode",
+                 'stud_status':"AdmitStatus",
+                 'department': "AdmitDept",
+                 'jamb_lga': "LGA",
+                 'app_email': "email",
+                 'app_mobile': "PhoneNumbers",
+                 }
+        csv_fields = [f[1] for f in csv_d.items()]
+        tr_count = 0
+        total = 0
+        #name = 'pume_results'
+        name = 'StudyCourseChange'
+        no_import = []
+        s = ','.join(['"(%s)"' % fn for fn in csv_fields])
+        no_import.append('"Error",%s' % s)
+        format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
+        no_certificate = "no certificate %s" % format
+        open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write(
+                    '\n'.join(no_import))
+        logger = logging.getLogger('%s_import' % name)
+        logger.info('Start loading from %s.csv' % name)
+        l = self.portal_catalog({'meta_type': "Certificate"})
+        try:
+            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
+        except:
+            logger.error('Error reading %s.csv' % name)
+            return
+        for jamb in result:
+            jamb['Error'] = "Processing "
+            logger.info(format % jamb)
+            jamb_reg_no = jamb.get(csv_d['jamb_reg_no'])
+            res = self.portal_catalog({'portal_type': "StudentApplication",
+                                     'SearchableText': jamb_reg_no })
+            if not res:
+                em = 'Student with RegNo %s does not exists\n' % jamb_reg_no
+                logger.info(em)
+                jamb['Error'] = "Student not exists"
+                no_import.append(format % jamb)
+                continue
+            sid = res[0].getPath().split('/')[-2]
+            cert_id = makeCertificateCode(jamb.get(csv_d['course_code']))
+            res = self.portal_catalog(portal_type = "Certificate", id = cert_id)
+            if not res:
+                em = 'No Certificate with ID %s \n' % cert_id
+                logger.info(em)
+                jamb['Error'] = "No Certificate %s" % cert_id
+                no_import.append( format % jamb)
+                continue
+            cert_brain = res[0]
+            catalog_entry = {}
+            student = getattr(self,sid)
+            #
+            # Study Course
+            #
+            study_course = student.study_course
+            dsc = {}
+            cert_pl = cert_brain.getPath().split('/')
+            catalog_entry['id'] = sid
+            catalog_entry['faculty'] = cert_pl[-4]
+            catalog_entry['department'] = cert_pl[-3]
+            catalog_entry['course'] = cert_id
+            dsc['study_course'] = cert_id
+            study_course.getContent().edit(mapping=dsc)
+            self.students_catalog.modifyRecord(**catalog_entry)
+            if tr_count > 10:
+                if len(no_import) > 1:
+                    open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write(
+                             '\n'.join(no_import))
+                    no_import = []
+                em = '%d transactions commited\n' % tr_count
+                transaction.commit()
+                logger.info(em)
+                total += tr_count
+                tr_count = 0
+            tr_count += 1
+        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
+    ###)
+
     security.declareProtected(ModifyPortalContent,"OLDloadPumeResultsFromCSV")###(
     def OLDloadPumeResultsFromCSV(self):
Index: /WAeUP_SRP/trunk/__init__.py
===================================================================
--- /WAeUP_SRP/trunk/__init__.py	(revision 1064)
+++ /WAeUP_SRP/trunk/__init__.py	(revision 1065)
@@ -18,4 +18,5 @@
 import PatchCPSStackingDirectoryStorageAdapter
 import PatchBasicWidgetsCPSStringWidget
+import PatchBasicWidgetsUnprepare
 # Only for CPS 3.4.1. In 3.4.2 and later this should be fixed.
 import PatchCPSDefaultImportExport
Index: /WAeUP_SRP/trunk/skins/waeup_student/search_students.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/search_students.py	(revision 1064)
+++ /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 1064)
+++ /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>
