Changeset 1875


Ignore:
Timestamp:
10 Jun 2007, 16:42:46 (17 years ago)
Author:
joachim
Message:

new import edit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/WAeUPTool.py

    r1869 r1875  
    810810        jamb_reg_no = mapping.get('jamb_reg_no',None)
    811811        matric_no = mapping.get('matric_no',None)
     812        editable_keys = mapping.keys()
    812813        if sid:
    813814            res = self.students_catalog(id = sid)
     
    824825            if not res:
    825826                return '',"no student with jamb_reg_no %s" % jamb_reg_no
     827            editable_keys.remove('jamb_reg_no')
    826828        elif matric_no:
    827829            res = self.students_catalog(matric_no = matric_no)
    828830            if not res:
    829831                return '',"no student with matric_no %s" % matric_no
    830             #elif jamb_reg_no and res[0].jamb_reg_no and\
    831             #  jamb_reg_no != res[0].jamb_reg_no:
    832             #    return '%s' % res[0].id ,"student has no jamb_reg_no %s" % jamb_reg_no
    833 
     832            editable_keys.remove('matric_no')
    834833        sid = res[0].id
    835834        student_obj = getattr(students_folder,sid)
    836835        f2t = self.student_field2types
    837836        d = {}
    838         d['jamb_sex']  = 'M'
    839         if mapping.get('sex'):
    840             d['jamb_sex']  = 'F'
     837        #import pdb;pdb.set_trace()
     838        any_change = False
    841839        for pt in f2t.keys():
    842             sub_obj = getattr(student_obj,f2t[pt]['id'],None)
    843             if sub_obj is None:
    844                 try:
    845                     student_obj.invokeFactory(pt,f2t[pt]['id'])
    846                 except:
    847                     continue
    848                 sub_obj = getattr(student_obj,f2t[pt]['id'])
    849             sub_doc = sub_obj.getContent()
    850             # self.portal_workflow.doActionFor(sub_obj,'open',dest_container=sub_obj)
    851             d['Title'] = f2t[pt]['title']
    852             for field in f2t[pt]['fields']:
    853                 if not mapping.get(field,None):
    854                     continue
    855                 d[field] = mapping.get(field,'')
    856             sub_doc.edit(mapping = d)
    857             # new_state = f2t[pt]['wf_transition']
    858             # if new_state != "remain":
    859             #     self.portal_workflow.doActionFor(sub_obj,new_state,dest_container=sub_obj)
    860         # wfaction = 'return'
    861         # self.portal_workflow.doActionFor(student_obj,wfaction)
    862         # student_obj.manage_setLocalRoles(sid, ['Owner',])
    863         return sid,''
     840            if pt == "student_application":
     841                d['jamb_sex']  = 'M'
     842                if mapping.get('sex'):
     843                    d['jamb_sex']  = 'F'
     844            intersect = set(f2t[pt]['fields']).intersection(set(editable_keys))
     845            if intersect:
     846                sub_obj = getattr(student_obj,f2t[pt]['id'],None)
     847                if sub_obj is None:
     848                    try:
     849                        student_obj.invokeFactory(pt,f2t[pt]['id'])
     850                    except:
     851                        continue
     852                    sub_obj = getattr(student_obj,f2t[pt]['id'])
     853                    d['Title'] = f2t[pt]['title']
     854                sub_doc = sub_obj.getContent()
     855                for field in intersect:
     856                    changed = False
     857                    if getattr(sub_doc,field) != mapping.get(field,''):
     858                        any_change = True
     859                        changed = True
     860                        d[field] = mapping.get(field,'')
     861                    if changed:
     862                        sub_doc.edit(mapping = d)
     863        if any_change:
     864            return sid,''
     865        else:
     866            return sid,'not modified'
    864867    ###)
    865868
     
    915918            return em
    916919        for item in items:
    917             tr_count += 1
    918920            if start:
    919921                start = False
     
    952954                imported.append(em)
    953955                logger.info("%(total_imported)d of %(total)d %(em)s" % vars())
     956                tr_count += 1
    954957                total_imported += 1
    955958            total += 1
    956             if tr_count > 1000:
     959            if total_imported and not total_imported % 100:
     960                transaction.commit()
    957961                if len(not_imported) > 0:
    958962                    open("%s/import/%s_not_imported%s.csv" % (i_home,filename,current),"a").write(
     
    964968                    imported = []
    965969                em = '%d transactions committed\n' % (tr_count)
    966                 transaction.commit()
    967970                regs = []
    968971                logger.info(em)
Note: See TracChangeset for help on using the changeset viewer.