security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsFromCSV")###( def loadFullTimeStudentsFromCSV(self): """load Fulltime Studentdata from CSV values""" import transaction import random tr_count = 0 name = 'short_full_time' no_import = False if not no_import: no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") no_import.write('"MatricNo","EntryRegNo","CurrentSession","StudentLevel","fullname","FirstName","MiddleName","Lastname","FormerSurname","Sex","Nationality","State","LGA","PermanentAddress","PermanentAddressCity","CampusAddress","PhoneNumber","Emailaddress","Mode","CourseMajor","Faculty","Dept"\n') logger = logging.getLogger('Import.%s' % name) logger.info('Start loading from %s.csv' % name) pwlist = [] pwlist.append('"student_id","firstname","middlename","lastname","matric_no","jamb_reg_no","access_code"') pwl_template = Template('"$student_id","$firstname","$middlename","$lastname","$matric_no","$jamb_reg_no","$access_code"') students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() try: students = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) except: logger.error('Error reading %s.csv' % name) return l = self.portal_catalog({'meta_type': "StudentClearance",}) matrics = [] for s in l: matrics.append(s.getObject().getContent().matric_no) print matrics l = self.portal_catalog({'meta_type': "Certificate"}) certs = {} for c in l: ca,ac,fa,dep_id,co,certcode = c.relative_path.split('/') cid = "%(dep_id)s_%(certcode)s" % vars() certs[cid] = c.getObject() for student in students: logger.info('processing "%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student) sid = student.get('MatricNo') if sid == "": em = 'Empty MatricNo\n' logger.info(em) no_import.write(em) no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student) continue certcode = makeCertificateCode(student.get('CourseMajor')) dep_id = student.get('Dept') fac_id = student.get('Faculty') cid = "%(dep_id)s_%(certcode)s" % vars() if cid not in certs.keys(): em = 'Certificate with ID %s %s not found\n' % (certcode, student.get('CourseMajor')) logger.info(em) no_import.write(em) no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student) continue certificate_doc = certs[cid].getContent() level = student.get('StudentLevel') try: int(level) except: em = 'Student with ID %(MatricNo)s StudentLevel is empty\n' % student logger.info(em) no_import.write(em) no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student) continue matric_no = student.get('MatricNo') if matric_no not in matrics: matrics.append(matric_no) sid = self.generateStudentId(student.get('Lastname')[0]) #self.log('Creating Faculty %(id)s = %(Title)s' % faculty) students_folder.invokeFactory('Student', sid) logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars()) student_obj = getattr(self,sid) access_code = "%d" % random.randint(1000000000,9999999999) student_obj.getContent().makeStudentMember(sid,access_code,) pwl_dict = {'student_id': sid,'access_code':access_code} student_obj.invokeFactory('StudentApplication','application') application = student_obj.application da = {'Title': 'Application Data'} student_obj.invokeFactory('StudentPersonal','personal') da['jamb_reg_no'] = student.get('EntryRegNo') personal = student_obj.personal dp = {'Title': 'Personal Data'} student_obj.invokeFactory('StudentClearance','clearance') clearance = student_obj.clearance dc = {'Title': 'Clearance/Eligibility Record'} dc['matric_no'] = matric_no state = student.get('State') lga = student.get('LGA') if state and lga: lga = state + ' / ' + lga else: lga = "None" dc['lga'] = lga dc['nationality'] = student.get('Nationality') dc['email'] = student.get('Emailaddress') dp['firstname'] = student.get('FirstName') dp['middlename'] = student.get('MiddleName') dp['lastname'] = student.get('Lastname') dp['former_surname'] = student.get('FormerSurname') dp['sex'] = student.get('Sex') == 'F' dp['perm_address'] = student.get('PermanentAddress') dp['perm_city'] = student.get('PermanentAddressCity') dp['campus_address'] = student.get('CampusAddress') dp['phone'] = student.get('PhoneNumber') application.getContent().edit(mapping=da) personal.getContent().edit(mapping=dp) clearance.getContent().edit(mapping=dc) # # Study Course # student_obj.invokeFactory('StudentStudyCourse','study_course') studycourse = student_obj.study_course dsc = {} from_certificate = ['title', 'max_elect', 'max_pass', 'n_core', 'nr_years', 'probation_credits', 'promotion_credits', 'start_level', ] for f in from_certificate: dsc[f] = getattr(certificate_doc,f) dsc['faculty'] = fac_id dsc['department'] = dep_id dsc['study_course'] = certcode css = student.get('CurrentSession') or '2004-2005' cs = int(css.split('-')[0]) - 2000 cl = int(student.get('StudentLevel') or '100')/100 dsc['entry_session'] = "200%s" % (cs - cl) dsc['clr_ac_pin'] = access_code studycourse.getContent().edit(mapping=dsc) # # Level # ## l = getattr(studycourse,level,None) ## if 0 and l is None: ## #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) ## logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student) ## studycourse.invokeFactory('StudentStudyLevel', level) ## l = getattr(studycourse, level) ## certificate = certs[certcode] ## cert_level = getattr(certificate,level,None) ## if cert_level is None: ## logger.info('Level %(level)s not in %(certcode)s' % vars()) ## l.getContent().edit(mapping={'Title': "Level %s" % level}) else: em = 'Student with ID %(MatricNo)s %(fullname)s already exists\n' % student logger.info(em) no_import.write(em) no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student) continue if tr_count > MAX_TRANS: transaction.commit() em = 'Transaction commited\n' % student logger.info(em) tr_count = 0 tr_count += 1 pwl_dict.update(dc) pwl_dict.update(da) pwl_dict.update(dp) wftool = self.portal_workflow pwlist.append(pwl_template.substitute(pwl_dict)) wftool.doActionFor(student_obj,'clear_and_validate') student_obj.manage_setLocalRoles(sid, ['Owner',]) wftool.doActionFor(application,'close') application.manage_setLocalRoles(sid, ['Owner',]) wftool.doActionFor(clearance,'close') clearance.manage_setLocalRoles(sid, ['Owner',]) wftool.doActionFor(personal,'close') personal.manage_setLocalRoles(sid, ['Owner',]) wftool.doActionFor(studycourse,'close_for_edit') studycourse.manage_setLocalRoles(sid, ['Owner',]) open("%s/import/pwlist-%s.csv" % (i_home,name),"w+").write('\n'.join(pwlist)) return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) ###) security.declareProtected(ModifyPortalContent,"loadPumeResultsFromCSV")###( def loadPumeResultsFromCSV(self): """load Fulltime Studentdata from CSV values into pumeresults catalog""" import transaction import random ## 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", 'faculty': "Faculty", 'department': "Dept", 'course_code_org': "Course Code", 'status': "Admission Status", 'result_type': None, } csv_fields = [f[1] for f in csv_d.items() if f[1]] tr_count = 0 total = 0 #name = 'pup_new' name = 'pup_update' update = name.endswith('update') no_import = [] 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)) logger = logging.getLogger('Import.%s' % name) starttime = DateTime.now() logger.info('Start loading from %s.csv' % name) try: result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) except: logger.error('Error reading %s.csv' % name) return 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 = '%s,"duplicate"' % format einvalidjamb = '%s,"invalid JambRegNo"' % format added = 'added ,%s' % format #from pdb import set_trace;set_trace() for jamb in result: dict = {} for f,fn in csv_d.items(): dict[f] = jamb.get(csv_d[f]) 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: try: pume.modifyRecord(**dict) except ValueError: logger.info(eduplicate % jamb) continue except KeyError: pume.addRecord(**dict) logger.info(added % jamb) continue 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) ok_import.append(import_format % dict) except ValueError: logger.info(eduplicate % jamb) #em = 'Student with REG-NO %(jamb_reg_no)s already exists\n' % dict #logger.info(em) no_import.append(eduplicate % jamb) logger.info('End loading from %s.csv' % name) 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')) ###) security.declareProtected(ModifyPortalContent,"OLDloadPumeResultsFromCSV")###( def OLDloadPumeResultsFromCSV(self): """load Fulltime Studentdata from CSV values""" import transaction import random wftool = self.portal_workflow students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() csv_d = {'jamb_reg_no': "JAMBRegno", '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': "JambScore", 'omitted':"Omitted", 'search_key': "SearchKey", 'jamb_sex': "Sex", 'fac1': "Fac1", 'fac2': "Fac2", 'jamb_first_cos': "CourseofStudy", 'stud_status':"StudStatus", '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", } csv_fields = [f[1] for f in csv_d.items()] tr_count = 0 name = 'pume_results' no_import = [] s = ','.join(['"%s"' % fn for fn in csv_fields]) no_import.append('%s\n' % s) logger = logging.getLogger('Import.%s' % name) logger.info('Start loading from %s.csv' % name) try: result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) except: logger.error('Error reading %s.csv' % name) return for jamb in result: format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) processing = "processing %s" % format logger.info(processing % jamb) jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) #import pdb;pdb.set_trace() res = self.portal_catalog({'portal_type': "StudentApplication", 'jamb_reg_no': jamb_reg_no }) if res: em = 'Student with REG-NO %s already exists\n' % jamb_reg_no logger.info(em) no_import.append(em) no_import.append(format % jamb) continue cert_id = jamb.get(csv_d['jamb_first_cos']).upper() res = self.portal_catalog({'portal_type': "Certificate", 'id': cert_id }) if len(res) < 1: em = 'No Certificate with ID %s \n' % cert_id logger.info(em) no_import.append(em) no_import.append(format % jamb) continue cert = res[0].getObject() cert_path = res[0].getPath() cert_doc = cert.getContent() jamb_name = jamb.get(csv_d['jamb_lastname']) jamb_name.replace('>','') names = jamb_name.split() letter = names[-1][0].upper() sid = self.generateStudentId(letter) not_created = True while not_created: try: students_folder.invokeFactory('Student', sid) not_created = False except BadRequest: sid = self.generateStudentId(letter) logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) student = getattr(self,sid) student.manage_setLocalRoles(sid, ['Owner',]) student.invokeFactory('StudentClearance','clearance') #wftool.doActionFor(student.clearance,'open') dp = {'Title': 'Clearance/Eligibility Record'} student.clearance.manage_setLocalRoles(sid, ['Owner',]) student.invokeFactory('StudentPume','pume') dp = {'Title': 'Pume Data'} student.invokeFactory('StudentApplication','application') da = {'Title': 'Application Data'} da["jamb_lastname"] = jamb_name da_fields = ('jamb_reg_no', 'jamb_sex', 'jamb_state', 'jamb_score', 'jamb_first_cos', 'jamb_sex', 'jamb_state', 'jamb_first_cos', 'jamb_second_cos', ) for f in da_fields: da[f] = jamb.get(csv_d[f]) app = student.application app.getContent().edit(mapping=da) app.manage_setLocalRoles(sid, ['Owner',]) #wftool.doActionFor(app,'close') dp_fields = ( 'pume_eng_score', 'pume_gen_score', 'pume_tot_score', ) for f in dp_fields: dp[f] = float(jamb.get(csv_d[f])) pume = student.pume pume.getContent().edit(mapping=dp) #wftool.doActionFor(pume,'close') pume.manage_setLocalRoles(sid, ['Owner',]) # # Study Course # student.invokeFactory('StudentStudyCourse','study_course') study_course = student.study_course dsc = {} from_certificate = ['title', 'max_elect', 'max_pass', 'n_core', 'nr_years', 'probation_credits', 'promotion_credits', 'start_level', ] for f in from_certificate: dsc[f] = getattr(cert_doc,f) cpl = cert_path.split('/') dsc['faculty'] = cpl[-4] dsc['department'] = cpl[-3] dsc['study_course'] = cert_id dsc['entry_session'] = jamb.get(csv_d['session']) study_course.getContent().edit(mapping=dsc) student.getContent().createSubObjects() if dp['pume_tot_score']>49: wftool.doActionFor(student,'pume_pass') wftool.doActionFor(student,'admit') else: wftool.doActionFor(student,'pume_fail') wftool.doActionFor(student,'reject_admission') if len(no_import) > 1: open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( '\n'.join(no_import)) return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) ###) security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsResultsFromCSV") ###( def loadFullTimeStudentsResultsFromCSV(self): """load Fulltime Studentdata from CSV values""" #return level_wf_actions = {} level_wf_actions["SUCCESSFUL STUDENT"] = "pass_A" level_wf_actions["STUDENT WITH CARRYOVER COURSES"] = "pass_B" level_wf_actions["STUDENT FOR PROBATION"] = "probate_C" level_wf_actions["STUDENT ON PROBATION/TRANSFER"] = "reject_D" import transaction wftool = self.portal_workflow tr_count = 0 name = 'short_full_time_results_2004_2005' no_import = False if not no_import: no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") no_import.write('"Matnumber","CosCode","Ansbook","CosStuatus","Session","Mat_Cos","Score","CarryLevel","Grade","Weight","Semster","Verdict","Level","id","GPA"\n') logger = logging.getLogger('import.%s' % name) logger.info('Start loading from %s.csv' % name) students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() try: results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) except: logger.error('Error reading %s.csv' % name) return l = self.portal_catalog({'meta_type': "Course"}) courses = {} for c in l: courses[c.id] = c.getObject() level_changed = False student_changed = False sid = '' #import pdb;pdb.set_trace() for result in results: temp_sid = result.get('Matnumber') if temp_sid != sid: student_changed = True res = self.portal_catalog({'meta_type': "StudentClearance", 'SearchableText': temp_sid }) if not res: em = 'Student with ID %(Matnumber)s not found\n' % result logger.info(em) no_import.write(em) no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result) continue elif len(res) > 1: em = 'More than one Student with ID %(Matnumber)s found\n' % result logger.info(em) no_import.write(em) no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result) continue sid = temp_sid sf = res[0].getObject().aq_parent sc = getattr(sf,'study_course') level = '' else: student_changed = False course = result.get('CosCode') if course not in courses.keys(): em = 'Course with ID %(CosCode)s not found\n' % result logger.info(em) no_import.write(em) no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result) continue course_doc = courses[course].getContent() temp_level = result.get('Level') student_id = sf.getId() result['StudentId'] = student_id if temp_level != level: try: int(temp_level) except: em = 'Result with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % result logger.info(em) no_import.write(em) no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result) continue level_changed = True if 'dlev' in vars().keys(): wftool.doActionFor(l,level_wf_actions[dlev['verdict']]) level = temp_level l = getattr(sc,level,None) if l is None: logger.info('Creating Level %(Level)s for %(StudentId)s %(Matnumber)s' % result) sc.invokeFactory('StudentStudyLevel', level) l = getattr(sc, level) l.manage_setLocalRoles(student_id, ['Owner',]) else: level_changed = False cr = getattr(l,course,None) if cr is None: logger.info('Creating Course %(CosCode)s for %(StudentId)s %(Matnumber)s in Level %(Level)s' % result) l.invokeFactory('StudentCourseResult',course) cr = getattr(l,course) dcr = {} from_course = ['title', 'credits', 'passmark', ] for f in from_course: dcr[f] = getattr(course_doc,f) dlev = {} dcr['ansbook'] = result.get('Ansbook') dcr['semester'] = getInt(result.get('Semster')) dcr['status'] = result.get('CosStuatus') dcr['score'] = getInt(result.get('Score')) dlev['session'] = result.get('Session') dcr['carry_level'] = result.get('CarryLevel') dcr['grade'] = result.get('Grade') dcr['weight'] = result.get('Weight') dlev['verdict'] = result.get('Verdict') dcr['import_id'] = result.get('id') gpa = result.get('GPA').replace(',','.') dlev['imported_gpa'] = getFloat(gpa) cr.getContent().edit(mapping = dcr) cr.manage_setLocalRoles(student_id, ['Owner',]) l.getContent().edit(mapping = dlev) if tr_count > MAX_TRANS: transaction.commit() tr_count = 0 tr_count += 1 wftool.doActionFor(cr,'close') wftool.doActionFor(l,level_wf_actions[dlev['verdict']]) return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) ###) security.declareProtected(ModifyPortalContent,"loadJAMBFromCSV")###( def loadJAMBFromCSV(self): """load JAMB data from CSV values""" #return students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() import transaction tr_count = 0 name = 'SampleJAMBDataII' wftool = self.portal_workflow no_import = False if not no_import: no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") no_import.write('REG-NO,NAME,SEX,STATE,LGA,ENG-SCORE,SUBJ1,SUBJ1-SCORE,SUBJ2,SUBJ2-SCORE,SUBJ3,SUBJ3-SCORE,AGGREGATE,UNIV1,FACULTY1,COURSE1,UNIV2,FACULTY2,COURSE2') logger = logging.getLogger('Import.%s' % name) logger.info('Start loading from %s.csv' % name) try: result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) except: logger.error('Error reading %s.csv' % name) return for jamb in result: logger.info('processing %(REG-NO)s,%(NAME)s,%(SEX)s,%(STATE)s,%(LGA)s,%(ENG-SCORE)s,%(SUBJ1)s,%(SUBJ1-SCORE)s,%(SUBJ2)s,%(SUBJ2-SCORE)s,%(SUBJ3)s,%(SUBJ3-SCORE)s,%(AGGREGATE)s,%(UNIV1)s,%(FACULTY1)s,%(COURSE1)s,%(UNIV2)s,%(FACULTY2)s,%(COURSE2)s\n' % jamb) jamb_reg_no = jamb.get('REG-NO') res = self.portal_catalog({'meta_type': "StudentApplication", 'jamb_reg_no': jamb_reg_no }) if res: em = 'Student with REG-NO %(REG-NO)s already exists\n' % jamb logger.info(em) no_import.write(em) no_import.write('%(REG-NO)s,%(NAME)s,%(SEX)s,%(STATE)s,%(LGA)s,%(ENG-SCORE)s,%(SUBJ1)s,%(SUBJ1-SCORE)s,%(SUBJ2)s,%(SUBJ2-SCORE)s,%(SUBJ3)s,%(SUBJ3-SCORE)s,%(AGGREGATE)s,%(UNIV1)s,%(FACULTY1)s,%(COURSE1)s,%(UNIV2)s,%(FACULTY2)s,%(COURSE2)s\n' % jamb) continue jamb_name = jamb.get("NAME") jamb_name.replace('>','') names = jamb_name.split() letter = names[-1][0].upper() sid = self.generateStudentId(letter) not_created = True while not_created: try: students_folder.invokeFactory('Student', sid) not_created = False except BadRequest: sid = self.generateStudentId(letter) logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) student = getattr(self,sid) student.manage_setLocalRoles(sid, ['Owner',]) student.invokeFactory('StudentApplication','application') da = {'Title': 'Application Data'} da["jamb_reg_no"] = jamb.get("REG-NO") da["jamb_lastname"] = jamb_name da["jamb_sex"] = jamb.get("SEX") da["jamb_state"] = jamb.get("STATE") da["jamb_lga"] = jamb.get("LGA") da["jamb_score"] = jamb.get("AGGREGATE") da["jamb_first_cos"] = jamb.get("COURSE1") da["jamb_second_cos"] = jamb.get("COURSE2") da["jamb_first_uni"] = jamb.get("UNIV1") da["jamb_second_uni"] = jamb.get("UNIV2") app = student.application app_doc = app.getContent() app_doc.edit(mapping=da) #wftool.doActionFor(app,'open',dest_container=app) app.manage_setLocalRoles(sid, ['Owner',]) student.getContent().createSubObjects() return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) ###)