Index: WAeUP_SRP/trunk/WAeUPTool.py
===================================================================
--- WAeUP_SRP/trunk/WAeUPTool.py	(revision 1874)
+++ WAeUP_SRP/trunk/WAeUPTool.py	(revision 1875)
@@ -810,4 +810,5 @@
         jamb_reg_no = mapping.get('jamb_reg_no',None)
         matric_no = mapping.get('matric_no',None)
+        editable_keys = mapping.keys()
         if sid:
             res = self.students_catalog(id = sid)
@@ -824,42 +825,44 @@
             if not res:
                 return '',"no student with jamb_reg_no %s" % jamb_reg_no
+            editable_keys.remove('jamb_reg_no')
         elif matric_no:
             res = self.students_catalog(matric_no = matric_no)
             if not res:
                 return '',"no student with matric_no %s" % matric_no
-            #elif jamb_reg_no and res[0].jamb_reg_no and\
-            #  jamb_reg_no != res[0].jamb_reg_no:
-            #    return '%s' % res[0].id ,"student has no jamb_reg_no %s" % jamb_reg_no
-
+            editable_keys.remove('matric_no')
         sid = res[0].id
         student_obj = getattr(students_folder,sid)
         f2t = self.student_field2types
         d = {}
-        d['jamb_sex']  = 'M'
-        if mapping.get('sex'):
-            d['jamb_sex']  = 'F'
+        #import pdb;pdb.set_trace()
+        any_change = False
         for pt in f2t.keys():
-            sub_obj = getattr(student_obj,f2t[pt]['id'],None)
-            if sub_obj is None:
-                try:
-                    student_obj.invokeFactory(pt,f2t[pt]['id'])
-                except:
-                    continue
-                sub_obj = getattr(student_obj,f2t[pt]['id'])
-            sub_doc = sub_obj.getContent()
-            # self.portal_workflow.doActionFor(sub_obj,'open',dest_container=sub_obj)
-            d['Title'] = f2t[pt]['title']
-            for field in f2t[pt]['fields']:
-                if not mapping.get(field,None):
-                    continue
-                d[field] = mapping.get(field,'')
-            sub_doc.edit(mapping = d)
-            # new_state = f2t[pt]['wf_transition']
-            # if new_state != "remain":
-            #     self.portal_workflow.doActionFor(sub_obj,new_state,dest_container=sub_obj)
-        # wfaction = 'return'
-        # self.portal_workflow.doActionFor(student_obj,wfaction)
-        # student_obj.manage_setLocalRoles(sid, ['Owner',])
-        return sid,''
+            if pt == "student_application":
+                d['jamb_sex']  = 'M'
+                if mapping.get('sex'):
+                    d['jamb_sex']  = 'F'
+            intersect = set(f2t[pt]['fields']).intersection(set(editable_keys))
+            if intersect:
+                sub_obj = getattr(student_obj,f2t[pt]['id'],None)
+                if sub_obj is None:
+                    try:
+                        student_obj.invokeFactory(pt,f2t[pt]['id'])
+                    except:
+                        continue
+                    sub_obj = getattr(student_obj,f2t[pt]['id'])
+                    d['Title'] = f2t[pt]['title']
+                sub_doc = sub_obj.getContent()
+                for field in intersect:
+                    changed = False
+                    if getattr(sub_doc,field) != mapping.get(field,''):
+                        any_change = True
+                        changed = True
+                        d[field] = mapping.get(field,'')
+                    if changed:
+                        sub_doc.edit(mapping = d)
+        if any_change:
+            return sid,''
+        else:
+            return sid,'not modified'
     ###)
 
@@ -915,5 +918,4 @@
             return em
         for item in items:
-            tr_count += 1
             if start:
                 start = False
@@ -952,7 +954,9 @@
                 imported.append(em)
                 logger.info("%(total_imported)d of %(total)d %(em)s" % vars())
+                tr_count += 1
                 total_imported += 1
             total += 1
-            if tr_count > 1000:
+            if total_imported and not total_imported % 100:
+                transaction.commit()
                 if len(not_imported) > 0:
                     open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write(
@@ -964,5 +968,4 @@
                     imported = []
                 em = '%d transactions committed\n' % (tr_count)
-                transaction.commit()
                 regs = []
                 logger.info(em)
