Index: WAeUP_SRP/trunk/Students.py
===================================================================
--- WAeUP_SRP/trunk/Students.py	(revision 1110)
+++ WAeUP_SRP/trunk/Students.py	(revision 1111)
@@ -62,4 +62,16 @@
 ###)
 
+def checkJambNo(jnr):
+    try:
+        if len(jnr) != 10:
+            return False
+    except:
+        return False
+    try:
+        int(jnr[:8])
+        return True
+    except:
+        return False
+        
 class StudentsFolder(CPSDocument): ###(
     """
@@ -251,28 +263,41 @@
         import transaction
         import random
-        from pdb import set_trace
-        csv_d = {'jamb_reg_no': "RegNumber",
-                 'status': "Admission Status",
+##        csv_d = {'jamb_reg_no': "RegNumber", ###(
+##                 'status': "Admission Status",
+##                 'name': "Name",
+##                 'score': "Score",
+##                 'sex': "Sex",
+##                 'faculty': "Faculty",
+##                 'department': "Dept",
+##                 'course': "Course",
+##                 'course_code_org': "Course Code",
+##                 }
+###)
+        csv_d = {'jamb_reg_no': "JAMBRegno",
                  'name': "Name",
                  'score': "Score",
                  'sex': "Sex",
+                 'course': "Course Code",
                  'faculty': "Faculty",
                  'department': "Dept",
-                 'course': "Course",
                  'course_code_org': "Course Code",
+                 'status': "Admission Status",
+                 'result_type': None,
                  }
-        csv_fields = [f[1] for f in csv_d.items()]
+        csv_fields = [f[1] for f in csv_d.items() if f[1]]
         tr_count = 0
         total = 0
-        #name = 'pup_new'
-        name = 'pup_update'
+        name = 'pup_new'
+        #name = 'pup_update'
         update = name.endswith('update')
         no_import = []
-        s = ','.join(['"%s"' % fn for fn in csv_fields])
-        no_import.append('%s' % s)
+        ok_import = []
+        ok_import.append('%s' % ','.join(['"%s"' % fn for fn in csv_d.keys()]))
+        no_import.append('%s' % ','.join(['"%s"' % fn for fn in csv_fields]))
         current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
+        ok_import_name = "%s/import/%s_imported_%s.csv" % (i_home,name,current)
+        #open(ok_import_name,"w").write('\n'.join(no_import))
         no_import_name = "%s/import/%s_not_imported_%s.csv" % (i_home,name,current)
-        open(no_import_name,"w").write('\n'.join(no_import))
-        no_import = []
+        #open(no_import_name,"w").write('\n'.join(no_import))
         logger = logging.getLogger('Import.%s' % name)
         starttime = DateTime.now()
@@ -285,12 +310,24 @@
         pume = self.portal_pumeresults
         format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
+        import_format = ','.join(['"%%(%s)s"' % fn for fn in csv_d.keys()])
         eduplicate = '"dupplicate",%s' % format
+        einvalidjamb = '"invalid JambNr",%s' % format
         added = 'added ,%s' % format
+        #from pdb import set_trace;set_trace()
         for jamb in result:
             dict = {}
-            #set_trace()
             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']))
+            dict['result_type'] = 'DE'
+            jnr = jamb.get(csv_d['jamb_reg_no'])
+            if not checkJambNo(jnr):
+                logger.info(einvalidjamb % jamb)
+                dd = {}
+                for f,fn in csv_d.items():
+                    dd[fn] = getattr(data,f)
+                    no_import.append(eduplicate % dd)
+                    no_import.append(eduplicate % jamb)
+                continue
+            res = pume(jamb_reg_no=jnr)
             if len(res) > 0:
                 if update:
@@ -319,4 +356,5 @@
             try:
                 pume.addRecord(**dict)
+                ok_import.append(import_format % dict)
             except ValueError:
                 logger.info(eduplicate % jamb)
@@ -327,4 +365,5 @@
         if len(no_import) > 1:
             open(no_import_name,"w+").write('\n'.join(no_import))
+        open(ok_import_name,"w+").write('\n'.join(ok_import))
         return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
     ###)
