Ignore:
Timestamp:
11 May 2007, 15:33:54 (17 years ago)
Author:
joachim
Message:

add importEdit (untested)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/WAeUPTool.py

    r1773 r1774  
    755755    ###)
    756756
     757    security.declareProtected(ModifyPortalContent,'importEditStudent') ###(
     758    def importEditStudent(self,dict):
     759        "edit a students data"
     760        logger = logging.getLogger('WAeUPTool.create_student')
     761        students_folder = self.portal_url.getPortalObject().campus.students
     762        sid = dict.get('id',None)
     763        jamb_reg_no = dict.get('jamb_reg_no',None)
     764        matric_no = dict.get('matric_no',None)
     765        if sid:
     766            res = self.students_catalog(id = sid)
     767            if not res:
     768                return '',"no student with id %s" % sid
     769            elif matric_no and res[0].matric_no and\
     770              matric_no != res[0].matric_no:
     771                return '%s' % res[0].id ,"student has no matric_no %s" % matric_no
     772            elif jamb_reg_no and res[0].jamb_reg_no and\
     773              jamb_reg_no != res[0].jamb_reg_no:
     774                return '%s' % res[0].id ,"student has no jamb_reg_no %s" % jamb_reg_no
     775        elif matric_no:
     776            res = self.students_catalog(matric_no = matric_no)
     777            if not res:
     778                return '',"no student with matric_no %s" % matric_no
     779            elif jamb_reg_no and res[0].jamb_reg_no and\
     780              jamb_reg_no != res[0].jamb_reg_no:
     781                return '%s' % res[0].id ,"student has no jamb_reg_no %s" % jamb_reg_no
     782        elif jamb_reg_no:
     783            res = self.students_catalog(jamb_reg_no = jamb_reg_no)
     784            if not res:
     785                return '',"no student with jamb_reg_no %s" % jamb_reg_no
     786        sid = res[0].id
     787        student_obj = getattr(students_folder,sid)
     788        f2t = self.student_field2types
     789        d = {}
     790        d['jamb_sex']  = 'M'
     791        if dict.get('sex'):
     792            d['jamb_sex']  = 'F'
     793        for pt in f2t.keys():
     794            sub_obj = getattr(student_obj,f2t[pt]['id'],None)
     795            if sub_obj is None:
     796                student_obj.invokeFactory(pt,f2t[pt]['id'])
     797                sub_obj = getattr(student_obj,f2t[pt]['id'])
     798            sub_doc = sub_obj.getContent()
     799            self.portal_workflow.doActionFor(sub_obj,'open',dest_container=sub_obj)
     800            d['Title'] = f2t[pt]['title']
     801            for field in f2t[pt]['fields']:
     802                d[field] = dict.get(field,'')
     803            sub_doc.edit(mapping = d)
     804            # new_state = f2t[pt]['wf_state']
     805            # if new_state != "remain":
     806            #     self.portal_workflow.doActionFor(sub_obj,new_state,dest_container=sub_obj)
     807        # wfaction = 'return'
     808        # self.portal_workflow.doActionFor(student_obj,wfaction)
     809        # student_obj.manage_setLocalRoles(sid, ['Owner',])
     810        return sid,''
     811    ###)
     812
    757813    security.declareProtected(ModifyPortalContent,"importData")###(
    758     def importData(self,filename,name):
     814    def importData(self,filename,name,edit=False):
    759815        """load data from CSV values"""
    760816        import transaction
     
    788844        for widget in layout.keys():
    789845            validators[widget] = layout[widget].validate
    790         importer_name = "import%s" % name.capitalize()
     846        if edit:
     847            importer_name = "importEdit%s" % name.capitalize()
     848        else:
     849            importer_name = "import%s" % name.capitalize()
    791850        importer = getattr(self, '%s' % importer_name,None)
    792851        if importer is None:
Note: See TracChangeset for help on using the changeset viewer.