Index: /WAeUP_SRP/trunk/Students.py
===================================================================
--- /WAeUP_SRP/trunk/Students.py	(revision 970)
+++ /WAeUP_SRP/trunk/Students.py	(revision 971)
@@ -17,5 +17,5 @@
 from Products.WAeUP_SRP.Academics import makeCertificateCode
 import logging
-import csv,re
+import csv,re,os
 import Globals
 p_home = Globals.package_home(globals())
@@ -23,4 +23,6 @@
 MAX_TRANS = 100
 import DateTime
+import PIL.Image
+from StringIO import StringIO
 
 def makeCertificateCode(code): ###(
@@ -263,6 +265,7 @@
         tr_count = 0
         total = 0
-        #name = 'pume_results'
-        name = 'pup'
+        #name = 'pup_new'
+        name = 'pup_update'
+        update = name.endswith('update')
         no_import = []
         s = ','.join(['"(%s)"' % fn for fn in csv_fields])
@@ -287,4 +290,21 @@
             for f,fn in csv_d.items():
                 dict[f] = jamb.get(csv_d[f])
+            res = pume(jamb_reg_no=jamb.get(csv_d['jamb_reg_no']))
+            if len(res) > 0:
+                if update:
+                    pume.modifyRecord(**dict)
+                else:
+                    data = res[0]
+                    if data.name != jamb.get(csv_d['name']):
+                        #set_trace()
+                        logger.info(eduplicate % jamb)
+                        #em = 'Student with REG-NO %(jamb_reg_no)s already exists\n' % dict
+                        #logger.info(em)
+                        dd = {}
+                        for f,fn in csv_d.items():
+                            dd[fn] = getattr(data,f)
+                        no_import.append(eduplicate % dd)
+                        no_import.append(eduplicate % jamb)
+                    continue
             try:
                 pume.addRecord(**dict)
@@ -299,4 +319,5 @@
             '\n'.join(no_import))
         return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
+    ###)
 
     security.declareProtected(ModifyPortalContent,"createNewStudents")###(
@@ -305,38 +326,21 @@
         import transaction
         import random
-        from pdb import set_trace
+        #from pdb import set_trace
         wftool = self.portal_workflow
         students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
-        csv_d = {'jamb_reg_no': "JAMBRegno",
+        csv_d = {'jamb_reg_no': "RegNumber",
                  'jamb_lastname': "Name",
-                 #'pume_options': "Options",
-                 #'session': "Session",
-                 #'days': "Days",
-                 #'response': "Responce",
-                 #'wrong': "Wrong",
-                 #'pume_eng_score': "EngScore",
-                 #'pume_gen_score': "GenScore",
-                 'pume_tot_score': "Score",
-                 #'batch': "Batch",
-                 #'serial': "SerialNo",
-                 'jamb_score': "Score",
-                 #'omitted':"Omitted",
-                 #'search_key': "SearchKey",
+                 'session': "Session",
+                 'pume_tot_score': "PUME SCORE",
+                 'jamb_score': "JambScore",
                  'jamb_sex': "Sex",
-                 'fac1': "Faculty",
-                 'dep': "Dept",
-                 #'fac2': "Fac2",
-                 'jamb_first_cos': "Course Code",
-                 'stud_status':"Admission Status",
-                 #'registered': "Registered",
-                 #'jamb_state': "State",
-                 #'eng_fail': "EngFail",
-                 #'gen_fail': "GenFail",
-                 #'un_ans_eng': "UnAnsEng",
-                 #'un_ans_eng': "UnAnsGen",
-                 #'total_ans': "TotalUnAns",
-                 #'dept': "Dept",
-                 #'jamb_second_cos': "Course2",
-                 #'jamb_third_cos': "course3",
+                 'jamb_state': "State",
+                 'jamb_first_cos': "AdminCourse",
+                 'faculty': "AdminFaculty",
+                 'course_code': "AdmitCoscode",
+                 'stud_status':"AdmitStatus",
+                 'department': "AdmitDept",
+                 'jamb_lga': "LGA",
+                 'app_email': "email",
                  }
         csv_fields = [f[1] for f in csv_d.items()]
@@ -344,14 +348,19 @@
         total = 0
         #name = 'pume_results'
-        name = 'pup'
+        name = 'Admitted'
         no_import = []
         s = ','.join(['"(%s)"' % fn for fn in csv_fields])
-        no_import.append('%s' % s)
+        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))
-        no_import = []
         logger = logging.getLogger('%s_import' % name)
         logger.info('Start loading from %s.csv' % name)
-        #set_trace()
+        l = self.portal_catalog({'meta_type': "Certificate"})
+        certs = {}
+        cert_docs = {}
+        for f in l:
+            certs[f.getId] = f.getObject().getContent()
         try:
             result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
@@ -360,9 +369,7 @@
             return
         for jamb in result:
-            format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
-            processing = "processing %s" % format
-            logger.info(processing % jamb)
+            jamb['Error'] = "Processing "
+            logger.info(format % jamb)
             jamb_reg_no = jamb.get(csv_d['jamb_reg_no'])
-            #import pdb;pdb.set_trace()
             res = self.portal_catalog({'portal_type': "StudentApplication",
                                      'SearchableText': jamb_reg_no })
@@ -370,19 +377,17 @@
                 em = 'Student with REG-NO %s already exists\n' % jamb_reg_no
                 logger.info(em)
-                no_import.append(em)
+                jamb['Error'] = "Student exists"
                 no_import.append(format % jamb)
                 continue
-            cert_id = makeCertificateCode(jamb.get(csv_d['jamb_first_cos']))
-            res = self.portal_catalog({'portal_type': "Certificate",
-                                     'id': cert_id })
-            if len(res) < 1:
+            cert_id = makeCertificateCode(jamb.get(csv_d['course_code']))
+            if cert_id not in certs.keys():
                 em = 'No Certificate with ID %s \n' % cert_id
                 logger.info(em)
-                no_import.append(em)
-                no_import.append(format % jamb)
+                jamb['Error'] = "No Certificate %s" % cert_id
+                no_import.append( format % jamb)
                 continue
-            cert = res[0].getObject()
-            cert_path = res[0].getPath()
-            cert_doc = cert.getContent()
+            cert_doc = certs[cert_id]
+            catalog_entry = {}
+            catalog_entry['jamb_reg_no'] = jamb_reg_no
             jamb_name = jamb.get(csv_d['jamb_lastname'])
             jamb_name.replace('>','')
@@ -398,4 +403,5 @@
                 except BadRequest:
                     sid = self.generateStudentId(letter)
+            catalog_entry['id'] = sid
             tr_count += 1
             logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
@@ -413,11 +419,27 @@
                          'jamb_first_cos',
                          'jamb_sex',
-                         #'jamb_state',
-                         #'jamb_first_cos',
-                         #'jamb_second_cos',
+                         'jamb_state',
+                         'jamb_lga',
+                         'app_email',
                          )
             for f in da_fields:
                 da[f] = jamb.get(csv_d[f])
+            catalog_entry['email'] = jamb.get(csv_d['app_email'])
             app = student.application
+            app_doc = app.getContent()
+            picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no) 
+            #import pdb;pdb.set_trace()
+            if os.path.exists(picture):
+                file = open(picture)
+                img = PIL.Image.open(file)
+                img.thumbnail((150,200),
+                              resample=PIL.Image.ANTIALIAS)
+                # We now need a buffer to write to. It can't be the same
+                # as the inbuffer as the PNG writer will write over itself.
+                outfile = StringIO()
+                img.save(outfile, format=img.format)
+                app_doc.manage_addFile('passport',
+                                       file=outfile,
+                                       title="%s.jpg" % jamb_reg_no)
             app.getContent().edit(mapping=da)
             app.manage_setLocalRoles(sid, ['Owner',])
@@ -434,5 +456,4 @@
             pume.manage_setLocalRoles(sid, ['Owner',])
             #student.getContent().createSubObjects()
-            names = jamb_name.split()
             dp = {} 
             if len(names) == 3:
@@ -442,8 +463,13 @@
             elif len(names) == 2:
                 dp['firstname'] = names[0].capitalize()
+                dp['middlename'] = ''
                 dp['lastname'] = names[1].capitalize()
             else:
+                dp['firstname'] = ''
+                dp['middlename'] = ''
                 dp['lastname'] = jamb_name
             dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F'
+            catalog_entry['sex'] = dp['sex']
+            catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp
             student.invokeFactory('StudentPersonal','personal')
             per = student.personal
@@ -482,11 +508,15 @@
             for f in from_certificate:
                 dsc[f] = getattr(cert_doc,f)
-            cpl = cert_path.split('/')
-            dsc['faculty'] = cpl[-4]
-            dsc['department'] = cpl[-3]
+            dsc['faculty'] = jamb.get(csv_d['faculty'])
+            dsc['department'] = jamb.get(csv_d['department'])
+            catalog_entry['faculty'] = jamb.get(csv_d['faculty'])
+            catalog_entry['department'] = jamb.get(csv_d['department'])
+            catalog_entry['course'] = cert_id
+            catalog_entry['level'] = getattr(cert_doc,'start_level')
             dsc['study_course'] = cert_id
-            dsc['entry_session'] = "2006/2007" #jamb.get(csv_d['session'])
+            dsc['entry_session'] = jamb.get(csv_d['session'])
             study_course.getContent().edit(mapping=dsc)
-            if tr_count > MAX_TRANS:
+            self.students_catalog.addRecord(**catalog_entry)
+            if tr_count > 1000:
                 if len(no_import) > 1:
                     open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write(
Index: /WAeUP_SRP/trunk/WAeUPTables.py
===================================================================
--- /WAeUP_SRP/trunk/WAeUPTables.py	(revision 970)
+++ /WAeUP_SRP/trunk/WAeUPTables.py	(revision 971)
@@ -178,4 +178,15 @@
 InitializeClass(PumeResultsTable)
 
+class StudentsCatalog(WAeUPTable):
+
+    meta_type = 'WAeUP Students Catalog'
+    name = "students_catalog"
+    key = "id"
+    def __init__(self):
+        WAeUPTable.__init__(self, 'students_catalog')
+
+
+InitializeClass(StudentsCatalog)
+
 # BBB:
 AccomodationTable = AccommodationTable
Index: /WAeUP_SRP/trunk/exportimport.py
===================================================================
--- /WAeUP_SRP/trunk/exportimport.py	(revision 970)
+++ /WAeUP_SRP/trunk/exportimport.py	(revision 971)
@@ -100,4 +100,5 @@
     importWAeUPTable(site.portal_pins, '', context,'pins')
     importWAeUPTable(site.portal_pumeresults, '', context,'pumeresults')
+    importWAeUPTable(site.students_catalog, '', context,'students_catalog')
 
 from Products.CPSCore.exportimport.catalog import CatalogToolXMLAdapter
Index: /WAeUP_SRP/trunk/profiles/default/students_catalog.xml
===================================================================
--- /WAeUP_SRP/trunk/profiles/default/students_catalog.xml	(revision 971)
+++ /WAeUP_SRP/trunk/profiles/default/students_catalog.xml	(revision 971)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<object name="portal_catalog" meta_type="CMF Catalog">
+ <column value="id"/>
+ <column value="jamb_reg_no"/>
+ <column value="name"/>
+ <column value="sex"/>
+ <column value="faculty"/>
+ <column value="department"/>
+ <column value="course"/>
+ <column value="email"/>
+ <column value="level"/>
+ <index name="id" meta_type="FieldIndex">
+  <indexed_attr value="id"/>
+ </index>
+ <index name="jamb_reg_no" meta_type="FieldIndex">
+  <indexed_attr value="jamb_reg_no"/>
+ </index>
+ <index name="faculty" meta_type="KeywordIndex">
+  <indexed_attr value="faculty"/>
+ </index>
+ <index name="department" meta_type="KeywordIndex">
+  <indexed_attr value="department"/>
+ </index>
+ <index name="level" meta_type="KeywordIndex">
+  <indexed_attr value="level"/>
+ </index>
+ <index name="course" meta_type="KeywordIndex">
+  <indexed_attr value="course"/>
+ </index>
+</object>
Index: /WAeUP_SRP/trunk/profiles/default/toolset.xml
===================================================================
--- /WAeUP_SRP/trunk/profiles/default/toolset.xml	(revision 970)
+++ /WAeUP_SRP/trunk/profiles/default/toolset.xml	(revision 971)
@@ -7,4 +7,6 @@
  <required tool_id="portal_pumeresults"
            class="Products.WAeUP_SRP.WAeUPTables.PumeResultsTable"/>
+ <required tool_id="students_catalog"
+           class="Products.WAeUP_SRP.WAeUPTables.StudentsCatalog"/>
  <required tool_id="waeup_tool"
            class="Products.WAeUP_SRP.WAeUPTool.WAeUPTool"/>
Index: /WAeUP_SRP/trunk/skins/waeup_student/getStudentInfo.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/getStudentInfo.py	(revision 970)
+++ /WAeUP_SRP/trunk/skins/waeup_student/getStudentInfo.py	(revision 971)
@@ -34,4 +34,7 @@
 student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id)
 student = context.restrictedTraverse(student_path,default=None)
+#from Products.zdb import set_trace
+#set_trace()
+
 if student is None or student.portal_type != 'Student':
     return None
Index: /WAeUP_SRP/trunk/skins/waeup_student/search_students.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/search_students.py	(revision 970)
+++ /WAeUP_SRP/trunk/skins/waeup_student/search_students.py	(revision 971)
@@ -62,5 +62,6 @@
                       ob=default,
                       layout_mode='edit',
-                      formaction="search_students"
+                      formaction="search_students",
+                      commit = False,
                       )
 if psm == '':
@@ -68,5 +69,5 @@
                              psm = psm,
                              #psm = "%s, %s" % (psm,ds),
-                             students = items,
+                             students = [],
                              allowed = True,
                              )
@@ -127,21 +128,11 @@
 if res:
     for r in res:
-        if r.portal_type in ("StudentStudyLevel",):
-            student = r.getObject().aq_parent.aq_parent
-        elif r.portal_type in student_subobjects:
-            student = r.getObject().aq_parent
-        else:
-            student = r.getObject()
-        search_set.append(student)
+        pl = r.getPath().split('/')
+        search_set.append(pl[pl.index('students') + 1])
 review_set = []
 if review_res:
     for r in review_res:
-        if r.portal_type in ("StudentStudyLevel",):
-            student = r.getObject().aq_parent.aq_parent
-        elif r.portal_type in student_subobjects:
-            student = r.getObject().aq_parent
-        else:
-            student = r.getObject()
-        review_set.append(student)
+        pl = r.getPath().split('/')
+        review_set.append(pl[pl.index('students') + 1])
 all = []
 if only_review:
@@ -158,18 +149,21 @@
     items.append(a)
 students = []
-items.sort(cmp_id)
+items.sort()
 co_view = False
 if items:
     for item in items:
         #if context.isClearanceOfficer(info):
+        info = {}
         if "ClearanceOfficers" in member.getGroups():
             co_view = True
-            droles = member.getRolesInContext(item)
-            if "ClearanceOfficer" in droles:
-                info = context.getStudentInfo(item)
-                students.append(info)
+##            droles = member.getRolesInContext(item)
+##            if "ClearanceOfficer" in droles:
+##                info = context.getStudentInfo(item)
+##                students.append(info)
         else:
-            info = context.getStudentInfo(item)
-            students.append(info)
+            #info = context.getStudentInfo(item)
+            info = context.students_catalog(id = item) 
+            if len(info) == 1:
+                students.append(info[0])
 
     return context.search_students_form(rendered = rend,
Index: /WAeUP_SRP/trunk/skins/waeup_student/search_students_form.pt
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_student/search_students_form.pt	(revision 970)
+++ /WAeUP_SRP/trunk/skins/waeup_student/search_students_form.pt	(revision 971)
@@ -55,10 +55,10 @@
               <tr tal:condition="student" 
                   tal:attributes="class python:test(repeat['student'].even(), 'even ajaxtd', 'odd ajaxtd')">
-                <td><a href="id" tal:attributes="href string:${student/student/absolute_url}"
+                <td><a href="id" tal:attributes="href string:${context/portal_url}/campus/students/${student/id}"
                        tal:content="student/id"></a></td>    
                 <td>
                   <span tal:replace="student/name" />
                 </td>    
-                <td><span tal:replace="python: student['app_doc'].jamb_reg_no" /></td>    
+                <td><span tal:replace="student/jamb_reg_no" /></td>    
                 <td tal:condition="options/co_view|nothing">
                        <a href="id" 
@@ -67,5 +67,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="not: options/co_view|nothing"><span tal:replace="student/review_state" /></td>   
+                <td tal:condition="options/co_view|nothing"><span tal:replace="student/review_state" /></td>   
               </tr>
             </span>
