[1571] | 1 | security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsFromCSV")###(
|
---|
| 2 | def loadFullTimeStudentsFromCSV(self):
|
---|
| 3 | """load Fulltime Studentdata from CSV values"""
|
---|
| 4 | import transaction
|
---|
| 5 | import random
|
---|
| 6 | tr_count = 0
|
---|
| 7 | name = 'short_full_time'
|
---|
| 8 | no_import = False
|
---|
| 9 | if not no_import:
|
---|
| 10 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
|
---|
| 11 | 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')
|
---|
| 12 | logger = logging.getLogger('Import.%s' % name)
|
---|
| 13 | logger.info('Start loading from %s.csv' % name)
|
---|
| 14 | pwlist = []
|
---|
| 15 | pwlist.append('"student_id","firstname","middlename","lastname","matric_no","jamb_reg_no","access_code"')
|
---|
| 16 | pwl_template = Template('"$student_id","$firstname","$middlename","$lastname","$matric_no","$jamb_reg_no","$access_code"')
|
---|
| 17 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
|
---|
| 18 | try:
|
---|
| 19 | students = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
|
---|
| 20 | except:
|
---|
| 21 | logger.error('Error reading %s.csv' % name)
|
---|
| 22 | return
|
---|
| 23 | l = self.portal_catalog({'meta_type': "StudentClearance",})
|
---|
| 24 | matrics = []
|
---|
| 25 | for s in l:
|
---|
| 26 | matrics.append(s.getObject().getContent().matric_no)
|
---|
| 27 | print matrics
|
---|
| 28 | l = self.portal_catalog({'meta_type': "Certificate"})
|
---|
| 29 | certs = {}
|
---|
| 30 | for c in l:
|
---|
| 31 | ca,ac,fa,dep_id,co,certcode = c.relative_path.split('/')
|
---|
| 32 | cid = "%(dep_id)s_%(certcode)s" % vars()
|
---|
| 33 | certs[cid] = c.getObject()
|
---|
| 34 | for student in students:
|
---|
| 35 | 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)
|
---|
| 36 | sid = student.get('MatricNo')
|
---|
| 37 | if sid == "":
|
---|
| 38 | em = 'Empty MatricNo\n'
|
---|
| 39 | logger.info(em)
|
---|
| 40 | no_import.write(em)
|
---|
| 41 | 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)
|
---|
| 42 | continue
|
---|
| 43 | certcode = makeCertificateCode(student.get('CourseMajor'))
|
---|
| 44 | dep_id = student.get('Dept')
|
---|
| 45 | fac_id = student.get('Faculty')
|
---|
| 46 | cid = "%(dep_id)s_%(certcode)s" % vars()
|
---|
| 47 | if cid not in certs.keys():
|
---|
| 48 | em = 'Certificate with ID %s %s not found\n' % (certcode, student.get('CourseMajor'))
|
---|
| 49 | logger.info(em)
|
---|
| 50 | no_import.write(em)
|
---|
| 51 | 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)
|
---|
| 52 | continue
|
---|
| 53 | certificate_doc = certs[cid].getContent()
|
---|
| 54 | level = student.get('StudentLevel')
|
---|
| 55 | try:
|
---|
| 56 | int(level)
|
---|
| 57 | except:
|
---|
| 58 | em = 'Student with ID %(MatricNo)s StudentLevel is empty\n' % student
|
---|
| 59 | logger.info(em)
|
---|
| 60 | no_import.write(em)
|
---|
| 61 | 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)
|
---|
| 62 | continue
|
---|
| 63 | matric_no = student.get('MatricNo')
|
---|
| 64 | if matric_no not in matrics:
|
---|
| 65 | matrics.append(matric_no)
|
---|
| 66 | sid = self.generateStudentId(student.get('Lastname')[0])
|
---|
| 67 | #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
|
---|
| 68 | students_folder.invokeFactory('Student', sid)
|
---|
| 69 | logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars())
|
---|
| 70 | student_obj = getattr(self,sid)
|
---|
| 71 | access_code = "%d" % random.randint(1000000000,9999999999)
|
---|
| 72 | student_obj.getContent().makeStudentMember(sid,access_code,)
|
---|
| 73 | pwl_dict = {'student_id': sid,'access_code':access_code}
|
---|
| 74 | student_obj.invokeFactory('StudentApplication','application')
|
---|
| 75 | application = student_obj.application
|
---|
| 76 | da = {'Title': 'Application Data'}
|
---|
| 77 | student_obj.invokeFactory('StudentPersonal','personal')
|
---|
| 78 | da['jamb_reg_no'] = student.get('EntryRegNo')
|
---|
| 79 | personal = student_obj.personal
|
---|
| 80 | dp = {'Title': 'Personal Data'}
|
---|
| 81 | student_obj.invokeFactory('StudentClearance','clearance')
|
---|
| 82 | clearance = student_obj.clearance
|
---|
| 83 | dc = {'Title': 'Clearance/Eligibility Record'}
|
---|
| 84 | dc['matric_no'] = matric_no
|
---|
| 85 | state = student.get('State')
|
---|
| 86 | lga = student.get('LGA')
|
---|
| 87 | if state and lga:
|
---|
| 88 | lga = state + ' / ' + lga
|
---|
| 89 | else:
|
---|
| 90 | lga = "None"
|
---|
| 91 | dc['lga'] = lga
|
---|
| 92 | dc['nationality'] = student.get('Nationality')
|
---|
| 93 | dc['email'] = student.get('Emailaddress')
|
---|
| 94 | dp['firstname'] = student.get('FirstName')
|
---|
| 95 | dp['middlename'] = student.get('MiddleName')
|
---|
| 96 | dp['lastname'] = student.get('Lastname')
|
---|
| 97 | dp['former_surname'] = student.get('FormerSurname')
|
---|
| 98 | dp['sex'] = student.get('Sex') == 'F'
|
---|
| 99 | dp['perm_address'] = student.get('PermanentAddress')
|
---|
| 100 | dp['perm_city'] = student.get('PermanentAddressCity')
|
---|
| 101 | dp['campus_address'] = student.get('CampusAddress')
|
---|
| 102 | dp['phone'] = student.get('PhoneNumber')
|
---|
| 103 | application.getContent().edit(mapping=da)
|
---|
| 104 | personal.getContent().edit(mapping=dp)
|
---|
| 105 | clearance.getContent().edit(mapping=dc)
|
---|
| 106 | #
|
---|
| 107 | # Study Course
|
---|
| 108 | #
|
---|
| 109 | student_obj.invokeFactory('StudentStudyCourse','study_course')
|
---|
| 110 | studycourse = student_obj.study_course
|
---|
| 111 | dsc = {}
|
---|
| 112 | from_certificate = ['title',
|
---|
| 113 | 'max_elect',
|
---|
| 114 | 'max_pass',
|
---|
| 115 | 'n_core',
|
---|
| 116 | 'nr_years',
|
---|
| 117 | 'probation_credits',
|
---|
| 118 | 'promotion_credits',
|
---|
| 119 | 'start_level',
|
---|
| 120 | ]
|
---|
| 121 | for f in from_certificate:
|
---|
| 122 | dsc[f] = getattr(certificate_doc,f)
|
---|
| 123 | dsc['faculty'] = fac_id
|
---|
| 124 | dsc['department'] = dep_id
|
---|
| 125 | dsc['study_course'] = certcode
|
---|
| 126 | css = student.get('CurrentSession') or '2004-2005'
|
---|
| 127 | cs = int(css.split('-')[0]) - 2000
|
---|
| 128 | cl = int(student.get('StudentLevel') or '100')/100
|
---|
| 129 | dsc['entry_session'] = "200%s" % (cs - cl)
|
---|
| 130 | dsc['clr_ac_pin'] = access_code
|
---|
| 131 | studycourse.getContent().edit(mapping=dsc)
|
---|
| 132 | #
|
---|
| 133 | # Level
|
---|
| 134 | #
|
---|
| 135 | ## l = getattr(studycourse,level,None)
|
---|
| 136 | ## if 0 and l is None:
|
---|
| 137 | ## #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
|
---|
| 138 | ## logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student)
|
---|
| 139 | ## studycourse.invokeFactory('StudentStudyLevel', level)
|
---|
| 140 | ## l = getattr(studycourse, level)
|
---|
| 141 | ## certificate = certs[certcode]
|
---|
| 142 | ## cert_level = getattr(certificate,level,None)
|
---|
| 143 | ## if cert_level is None:
|
---|
| 144 | ## logger.info('Level %(level)s not in %(certcode)s' % vars())
|
---|
| 145 | ## l.getContent().edit(mapping={'Title': "Level %s" % level})
|
---|
| 146 | else:
|
---|
| 147 | em = 'Student with ID %(MatricNo)s %(fullname)s already exists\n' % student
|
---|
| 148 | logger.info(em)
|
---|
| 149 | no_import.write(em)
|
---|
| 150 | 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)
|
---|
| 151 | continue
|
---|
| 152 | if tr_count > MAX_TRANS:
|
---|
| 153 | transaction.commit()
|
---|
| 154 | em = 'Transaction commited\n' % student
|
---|
| 155 | logger.info(em)
|
---|
| 156 | tr_count = 0
|
---|
| 157 | tr_count += 1
|
---|
| 158 | pwl_dict.update(dc)
|
---|
| 159 | pwl_dict.update(da)
|
---|
| 160 | pwl_dict.update(dp)
|
---|
| 161 | wftool = self.portal_workflow
|
---|
| 162 | pwlist.append(pwl_template.substitute(pwl_dict))
|
---|
| 163 | wftool.doActionFor(student_obj,'clear_and_validate')
|
---|
| 164 | student_obj.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 165 | wftool.doActionFor(application,'close')
|
---|
| 166 | application.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 167 | wftool.doActionFor(clearance,'close')
|
---|
| 168 | clearance.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 169 | wftool.doActionFor(personal,'close')
|
---|
| 170 | personal.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 171 | wftool.doActionFor(studycourse,'close_for_edit')
|
---|
| 172 | studycourse.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 173 | open("%s/import/pwlist-%s.csv" % (i_home,name),"w+").write('\n'.join(pwlist))
|
---|
| 174 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
|
---|
| 175 | ###)
|
---|
| 176 |
|
---|
| 177 | security.declareProtected(ModifyPortalContent,"loadPumeResultsFromCSV")###(
|
---|
| 178 | def loadPumeResultsFromCSV(self):
|
---|
| 179 | """load Fulltime Studentdata from CSV values into pumeresults catalog"""
|
---|
| 180 | import transaction
|
---|
| 181 | import random
|
---|
| 182 | ## csv_d = {'jamb_reg_no': "RegNumber", ###(
|
---|
| 183 | ## 'status': "Admission Status",
|
---|
| 184 | ## 'name': "Name",
|
---|
| 185 | ## 'score': "Score",
|
---|
| 186 | ## 'sex': "Sex",
|
---|
| 187 | ## 'faculty': "Faculty",
|
---|
| 188 | ## 'department': "Dept",
|
---|
| 189 | ## 'course': "Course",
|
---|
| 190 | ## 'course_code_org': "Course Code",
|
---|
| 191 | ## }
|
---|
| 192 | ###)
|
---|
| 193 | csv_d = {'jamb_reg_no': "JAMBRegno",
|
---|
| 194 | 'name': "Name",
|
---|
| 195 | 'score': "Score",
|
---|
| 196 | 'sex': "Sex",
|
---|
| 197 | 'course': "Course",
|
---|
| 198 | 'faculty': "Faculty",
|
---|
| 199 | 'department': "Dept",
|
---|
| 200 | 'course_code_org': "Course Code",
|
---|
| 201 | 'status': "Admission Status",
|
---|
| 202 | 'result_type': None,
|
---|
| 203 | }
|
---|
| 204 | csv_fields = [f[1] for f in csv_d.items() if f[1]]
|
---|
| 205 | tr_count = 0
|
---|
| 206 | total = 0
|
---|
| 207 | #name = 'pup_new'
|
---|
| 208 | name = 'pup_update'
|
---|
| 209 | update = name.endswith('update')
|
---|
| 210 | no_import = []
|
---|
| 211 | ok_import = []
|
---|
| 212 | ok_import.append('%s' % ','.join(['"%s"' % fn for fn in csv_d.keys()]))
|
---|
| 213 | no_import.append('%s' % ','.join(['"%s"' % fn for fn in csv_fields]))
|
---|
| 214 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
|
---|
| 215 | ok_import_name = "%s/import/%s_imported_%s.csv" % (i_home,name,current)
|
---|
| 216 | #open(ok_import_name,"w").write('\n'.join(no_import))
|
---|
| 217 | no_import_name = "%s/import/%s_not_imported_%s.csv" % (i_home,name,current)
|
---|
| 218 | #open(no_import_name,"w").write('\n'.join(no_import))
|
---|
| 219 | logger = logging.getLogger('Import.%s' % name)
|
---|
| 220 | starttime = DateTime.now()
|
---|
| 221 | logger.info('Start loading from %s.csv' % name)
|
---|
| 222 | try:
|
---|
| 223 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
|
---|
| 224 | except:
|
---|
| 225 | logger.error('Error reading %s.csv' % name)
|
---|
| 226 | return
|
---|
| 227 | pume = self.portal_pumeresults
|
---|
| 228 | format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
|
---|
| 229 | import_format = ','.join(['"%%(%s)s"' % fn for fn in csv_d.keys()])
|
---|
| 230 | eduplicate = '%s,"duplicate"' % format
|
---|
| 231 | einvalidjamb = '%s,"invalid JambRegNo"' % format
|
---|
| 232 | added = 'added ,%s' % format
|
---|
| 233 | #from pdb import set_trace;set_trace()
|
---|
| 234 | for jamb in result:
|
---|
| 235 | dict = {}
|
---|
| 236 | for f,fn in csv_d.items():
|
---|
| 237 | dict[f] = jamb.get(csv_d[f])
|
---|
| 238 | dict['result_type'] = 'DE'
|
---|
| 239 | jnr = jamb.get(csv_d['jamb_reg_no'])
|
---|
| 240 | if not checkJambNo(jnr):
|
---|
| 241 | logger.info(einvalidjamb % jamb)
|
---|
| 242 | dd = {}
|
---|
| 243 | for f,fn in csv_d.items():
|
---|
| 244 | dd[fn] = getattr(data,f)
|
---|
| 245 | no_import.append(eduplicate % dd)
|
---|
| 246 | no_import.append(eduplicate % jamb)
|
---|
| 247 | continue
|
---|
| 248 | res = pume(jamb_reg_no=jnr)
|
---|
| 249 | if len(res) > 0:
|
---|
| 250 | if update:
|
---|
| 251 | try:
|
---|
| 252 | pume.modifyRecord(**dict)
|
---|
| 253 | except ValueError:
|
---|
| 254 | logger.info(eduplicate % jamb)
|
---|
| 255 | continue
|
---|
| 256 | except KeyError:
|
---|
| 257 | pume.addRecord(**dict)
|
---|
| 258 | logger.info(added % jamb)
|
---|
| 259 | continue
|
---|
| 260 | else:
|
---|
| 261 | data = res[0]
|
---|
| 262 | if data.name != jamb.get(csv_d['name']):
|
---|
| 263 | #set_trace()
|
---|
| 264 | logger.info(eduplicate % jamb)
|
---|
| 265 | #em = 'Student with REG-NO %(jamb_reg_no)s already exists\n' % dict
|
---|
| 266 | #logger.info(em)
|
---|
| 267 | dd = {}
|
---|
| 268 | for f,fn in csv_d.items():
|
---|
| 269 | dd[fn] = getattr(data,f)
|
---|
| 270 | no_import.append(eduplicate % dd)
|
---|
| 271 | no_import.append(eduplicate % jamb)
|
---|
| 272 | continue
|
---|
| 273 | try:
|
---|
| 274 | pume.addRecord(**dict)
|
---|
| 275 | ok_import.append(import_format % dict)
|
---|
| 276 | except ValueError:
|
---|
| 277 | logger.info(eduplicate % jamb)
|
---|
| 278 | #em = 'Student with REG-NO %(jamb_reg_no)s already exists\n' % dict
|
---|
| 279 | #logger.info(em)
|
---|
| 280 | no_import.append(eduplicate % jamb)
|
---|
| 281 | logger.info('End loading from %s.csv' % name)
|
---|
| 282 | if len(no_import) > 1:
|
---|
| 283 | open(no_import_name,"w+").write('\n'.join(no_import))
|
---|
| 284 | open(ok_import_name,"w+").write('\n'.join(ok_import))
|
---|
| 285 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
|
---|
| 286 | ###)
|
---|
| 287 |
|
---|
| 288 |
|
---|
| 289 | security.declareProtected(ModifyPortalContent,"OLDloadPumeResultsFromCSV")###(
|
---|
| 290 | def OLDloadPumeResultsFromCSV(self):
|
---|
| 291 | """load Fulltime Studentdata from CSV values"""
|
---|
| 292 | import transaction
|
---|
| 293 | import random
|
---|
| 294 | wftool = self.portal_workflow
|
---|
| 295 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
|
---|
| 296 | csv_d = {'jamb_reg_no': "JAMBRegno",
|
---|
| 297 | 'jamb_lastname': "Name",
|
---|
| 298 | 'pume_options': "Options",
|
---|
| 299 | 'session': "Session",
|
---|
| 300 | 'days': "Days",
|
---|
| 301 | 'response': "Responce",
|
---|
| 302 | 'wrong': "Wrong",
|
---|
| 303 | 'pume_eng_score': "EngScore",
|
---|
| 304 | 'pume_gen_score': "GenScore",
|
---|
| 305 | 'pume_tot_score': "Score",
|
---|
| 306 | 'batch': "Batch",
|
---|
| 307 | 'serial': "SerialNo",
|
---|
| 308 | 'jamb_score': "JambScore",
|
---|
| 309 | 'omitted':"Omitted",
|
---|
| 310 | 'search_key': "SearchKey",
|
---|
| 311 | 'jamb_sex': "Sex",
|
---|
| 312 | 'fac1': "Fac1",
|
---|
| 313 | 'fac2': "Fac2",
|
---|
| 314 | 'jamb_first_cos': "CourseofStudy",
|
---|
| 315 | 'stud_status':"StudStatus",
|
---|
| 316 | 'registered': "Registered",
|
---|
| 317 | 'jamb_state': "State",
|
---|
| 318 | 'eng_fail': "EngFail",
|
---|
| 319 | 'gen_fail': "GenFail",
|
---|
| 320 | 'un_ans_eng': "UnAnsEng",
|
---|
| 321 | 'un_ans_eng': "UnAnsGen",
|
---|
| 322 | 'total_ans': "TotalUnAns",
|
---|
| 323 | 'dept': "Dept",
|
---|
| 324 | 'jamb_second_cos': "Course2",
|
---|
| 325 | 'jamb_third_cos': "course3",
|
---|
| 326 | }
|
---|
| 327 | csv_fields = [f[1] for f in csv_d.items()]
|
---|
| 328 | tr_count = 0
|
---|
| 329 | name = 'pume_results'
|
---|
| 330 | no_import = []
|
---|
| 331 | s = ','.join(['"%s"' % fn for fn in csv_fields])
|
---|
| 332 | no_import.append('%s\n' % s)
|
---|
| 333 | logger = logging.getLogger('Import.%s' % name)
|
---|
| 334 | logger.info('Start loading from %s.csv' % name)
|
---|
| 335 | try:
|
---|
| 336 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
|
---|
| 337 | except:
|
---|
| 338 | logger.error('Error reading %s.csv' % name)
|
---|
| 339 | return
|
---|
| 340 | for jamb in result:
|
---|
| 341 | format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
|
---|
| 342 | processing = "processing %s" % format
|
---|
| 343 | logger.info(processing % jamb)
|
---|
| 344 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no'])
|
---|
| 345 | #import pdb;pdb.set_trace()
|
---|
| 346 | res = self.portal_catalog({'portal_type': "StudentApplication",
|
---|
| 347 | 'jamb_reg_no': jamb_reg_no })
|
---|
| 348 | if res:
|
---|
| 349 | em = 'Student with REG-NO %s already exists\n' % jamb_reg_no
|
---|
| 350 | logger.info(em)
|
---|
| 351 | no_import.append(em)
|
---|
| 352 | no_import.append(format % jamb)
|
---|
| 353 | continue
|
---|
| 354 | cert_id = jamb.get(csv_d['jamb_first_cos']).upper()
|
---|
| 355 | res = self.portal_catalog({'portal_type': "Certificate",
|
---|
| 356 | 'id': cert_id })
|
---|
| 357 | if len(res) < 1:
|
---|
| 358 | em = 'No Certificate with ID %s \n' % cert_id
|
---|
| 359 | logger.info(em)
|
---|
| 360 | no_import.append(em)
|
---|
| 361 | no_import.append(format % jamb)
|
---|
| 362 | continue
|
---|
| 363 | cert = res[0].getObject()
|
---|
| 364 | cert_path = res[0].getPath()
|
---|
| 365 | cert_doc = cert.getContent()
|
---|
| 366 | jamb_name = jamb.get(csv_d['jamb_lastname'])
|
---|
| 367 | jamb_name.replace('>','')
|
---|
| 368 | names = jamb_name.split()
|
---|
| 369 | letter = names[-1][0].upper()
|
---|
| 370 | sid = self.generateStudentId(letter)
|
---|
| 371 | not_created = True
|
---|
| 372 | while not_created:
|
---|
| 373 | try:
|
---|
| 374 | students_folder.invokeFactory('Student', sid)
|
---|
| 375 | not_created = False
|
---|
| 376 | except BadRequest:
|
---|
| 377 | sid = self.generateStudentId(letter)
|
---|
| 378 | logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
|
---|
| 379 | student = getattr(self,sid)
|
---|
| 380 | student.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 381 | student.invokeFactory('StudentClearance','clearance')
|
---|
| 382 | #wftool.doActionFor(student.clearance,'open')
|
---|
| 383 | dp = {'Title': 'Clearance/Eligibility Record'}
|
---|
| 384 | student.clearance.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 385 | student.invokeFactory('StudentPume','pume')
|
---|
| 386 | dp = {'Title': 'Pume Data'}
|
---|
| 387 | student.invokeFactory('StudentApplication','application')
|
---|
| 388 | da = {'Title': 'Application Data'}
|
---|
| 389 | da["jamb_lastname"] = jamb_name
|
---|
| 390 | da_fields = ('jamb_reg_no',
|
---|
| 391 | 'jamb_sex',
|
---|
| 392 | 'jamb_state',
|
---|
| 393 | 'jamb_score',
|
---|
| 394 | 'jamb_first_cos',
|
---|
| 395 | 'jamb_sex',
|
---|
| 396 | 'jamb_state',
|
---|
| 397 | 'jamb_first_cos',
|
---|
| 398 | 'jamb_second_cos',
|
---|
| 399 | )
|
---|
| 400 | for f in da_fields:
|
---|
| 401 | da[f] = jamb.get(csv_d[f])
|
---|
| 402 | app = student.application
|
---|
| 403 | app.getContent().edit(mapping=da)
|
---|
| 404 | app.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 405 | #wftool.doActionFor(app,'close')
|
---|
| 406 | dp_fields = (
|
---|
| 407 | 'pume_eng_score',
|
---|
| 408 | 'pume_gen_score',
|
---|
| 409 | 'pume_tot_score',
|
---|
| 410 | )
|
---|
| 411 | for f in dp_fields:
|
---|
| 412 | dp[f] = float(jamb.get(csv_d[f]))
|
---|
| 413 | pume = student.pume
|
---|
| 414 | pume.getContent().edit(mapping=dp)
|
---|
| 415 | #wftool.doActionFor(pume,'close')
|
---|
| 416 | pume.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 417 | #
|
---|
| 418 | # Study Course
|
---|
| 419 | #
|
---|
| 420 | student.invokeFactory('StudentStudyCourse','study_course')
|
---|
| 421 | study_course = student.study_course
|
---|
| 422 | dsc = {}
|
---|
| 423 | from_certificate = ['title',
|
---|
| 424 | 'max_elect',
|
---|
| 425 | 'max_pass',
|
---|
| 426 | 'n_core',
|
---|
| 427 | 'nr_years',
|
---|
| 428 | 'probation_credits',
|
---|
| 429 | 'promotion_credits',
|
---|
| 430 | 'start_level',
|
---|
| 431 | ]
|
---|
| 432 | for f in from_certificate:
|
---|
| 433 | dsc[f] = getattr(cert_doc,f)
|
---|
| 434 | cpl = cert_path.split('/')
|
---|
| 435 | dsc['faculty'] = cpl[-4]
|
---|
| 436 | dsc['department'] = cpl[-3]
|
---|
| 437 | dsc['study_course'] = cert_id
|
---|
| 438 | dsc['entry_session'] = jamb.get(csv_d['session'])
|
---|
| 439 | study_course.getContent().edit(mapping=dsc)
|
---|
| 440 | student.getContent().createSubObjects()
|
---|
| 441 | if dp['pume_tot_score']>49:
|
---|
| 442 | wftool.doActionFor(student,'pume_pass')
|
---|
| 443 | wftool.doActionFor(student,'admit')
|
---|
| 444 | else:
|
---|
| 445 | wftool.doActionFor(student,'pume_fail')
|
---|
| 446 | wftool.doActionFor(student,'reject_admission')
|
---|
| 447 | if len(no_import) > 1:
|
---|
| 448 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write(
|
---|
| 449 | '\n'.join(no_import))
|
---|
| 450 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
|
---|
| 451 | ###)
|
---|
| 452 |
|
---|
| 453 | security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsResultsFromCSV") ###(
|
---|
| 454 | def loadFullTimeStudentsResultsFromCSV(self):
|
---|
| 455 | """load Fulltime Studentdata from CSV values"""
|
---|
| 456 | #return
|
---|
| 457 | level_wf_actions = {}
|
---|
| 458 | level_wf_actions["SUCCESSFUL STUDENT"] = "pass_A"
|
---|
| 459 | level_wf_actions["STUDENT WITH CARRYOVER COURSES"] = "pass_B"
|
---|
| 460 | level_wf_actions["STUDENT FOR PROBATION"] = "probate_C"
|
---|
| 461 | level_wf_actions["STUDENT ON PROBATION/TRANSFER"] = "reject_D"
|
---|
| 462 | import transaction
|
---|
| 463 | wftool = self.portal_workflow
|
---|
| 464 | tr_count = 0
|
---|
| 465 | name = 'short_full_time_results_2004_2005'
|
---|
| 466 | no_import = False
|
---|
| 467 | if not no_import:
|
---|
| 468 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
|
---|
| 469 | no_import.write('"Matnumber","CosCode","Ansbook","CosStuatus","Session","Mat_Cos","Score","CarryLevel","Grade","Weight","Semster","Verdict","Level","id","GPA"\n')
|
---|
| 470 | logger = logging.getLogger('import.%s' % name)
|
---|
| 471 | logger.info('Start loading from %s.csv' % name)
|
---|
| 472 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
|
---|
| 473 | try:
|
---|
| 474 | results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
|
---|
| 475 | except:
|
---|
| 476 | logger.error('Error reading %s.csv' % name)
|
---|
| 477 | return
|
---|
| 478 | l = self.portal_catalog({'meta_type': "Course"})
|
---|
| 479 | courses = {}
|
---|
| 480 | for c in l:
|
---|
| 481 | courses[c.id] = c.getObject()
|
---|
| 482 | level_changed = False
|
---|
| 483 | student_changed = False
|
---|
| 484 | sid = ''
|
---|
| 485 | #import pdb;pdb.set_trace()
|
---|
| 486 | for result in results:
|
---|
| 487 | temp_sid = result.get('Matnumber')
|
---|
| 488 | if temp_sid != sid:
|
---|
| 489 | student_changed = True
|
---|
| 490 | res = self.portal_catalog({'meta_type': "StudentClearance",
|
---|
| 491 | 'SearchableText': temp_sid })
|
---|
| 492 | if not res:
|
---|
| 493 | em = 'Student with ID %(Matnumber)s not found\n' % result
|
---|
| 494 | logger.info(em)
|
---|
| 495 | no_import.write(em)
|
---|
| 496 | 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)
|
---|
| 497 | continue
|
---|
| 498 | elif len(res) > 1:
|
---|
| 499 | em = 'More than one Student with ID %(Matnumber)s found\n' % result
|
---|
| 500 | logger.info(em)
|
---|
| 501 | no_import.write(em)
|
---|
| 502 | 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)
|
---|
| 503 | continue
|
---|
| 504 | sid = temp_sid
|
---|
| 505 | sf = res[0].getObject().aq_parent
|
---|
| 506 | sc = getattr(sf,'study_course')
|
---|
| 507 | level = ''
|
---|
| 508 | else:
|
---|
| 509 | student_changed = False
|
---|
| 510 | course = result.get('CosCode')
|
---|
| 511 | if course not in courses.keys():
|
---|
| 512 | em = 'Course with ID %(CosCode)s not found\n' % result
|
---|
| 513 | logger.info(em)
|
---|
| 514 | no_import.write(em)
|
---|
| 515 | 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)
|
---|
| 516 | continue
|
---|
| 517 | course_doc = courses[course].getContent()
|
---|
| 518 | temp_level = result.get('Level')
|
---|
| 519 | student_id = sf.getId()
|
---|
| 520 | result['StudentId'] = student_id
|
---|
| 521 | if temp_level != level:
|
---|
| 522 | try:
|
---|
| 523 | int(temp_level)
|
---|
| 524 | except:
|
---|
| 525 | em = 'Result with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % result
|
---|
| 526 | logger.info(em)
|
---|
| 527 | no_import.write(em)
|
---|
| 528 | 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)
|
---|
| 529 | continue
|
---|
| 530 | level_changed = True
|
---|
| 531 | if 'dlev' in vars().keys():
|
---|
| 532 | wftool.doActionFor(l,level_wf_actions[dlev['verdict']])
|
---|
| 533 | level = temp_level
|
---|
| 534 | l = getattr(sc,level,None)
|
---|
| 535 | if l is None:
|
---|
| 536 | logger.info('Creating Level %(Level)s for %(StudentId)s %(Matnumber)s' % result)
|
---|
| 537 | sc.invokeFactory('StudentStudyLevel', level)
|
---|
| 538 | l = getattr(sc, level)
|
---|
| 539 | l.manage_setLocalRoles(student_id, ['Owner',])
|
---|
| 540 | else:
|
---|
| 541 | level_changed = False
|
---|
| 542 | cr = getattr(l,course,None)
|
---|
| 543 | if cr is None:
|
---|
| 544 | logger.info('Creating Course %(CosCode)s for %(StudentId)s %(Matnumber)s in Level %(Level)s' % result)
|
---|
| 545 | l.invokeFactory('StudentCourseResult',course)
|
---|
| 546 | cr = getattr(l,course)
|
---|
| 547 | dcr = {}
|
---|
| 548 | from_course = ['title',
|
---|
| 549 | 'credits',
|
---|
| 550 | 'passmark',
|
---|
| 551 | ]
|
---|
| 552 | for f in from_course:
|
---|
| 553 | dcr[f] = getattr(course_doc,f)
|
---|
| 554 | dlev = {}
|
---|
| 555 | dcr['ansbook'] = result.get('Ansbook')
|
---|
| 556 | dcr['semester'] = getInt(result.get('Semster'))
|
---|
| 557 | dcr['status'] = result.get('CosStuatus')
|
---|
| 558 | dcr['score'] = getInt(result.get('Score'))
|
---|
| 559 | dlev['session'] = result.get('Session')
|
---|
| 560 | dcr['carry_level'] = result.get('CarryLevel')
|
---|
| 561 | dcr['grade'] = result.get('Grade')
|
---|
| 562 | dcr['weight'] = result.get('Weight')
|
---|
| 563 | dlev['verdict'] = result.get('Verdict')
|
---|
| 564 | dcr['import_id'] = result.get('id')
|
---|
| 565 | gpa = result.get('GPA').replace(',','.')
|
---|
| 566 | dlev['imported_gpa'] = getFloat(gpa)
|
---|
| 567 | cr.getContent().edit(mapping = dcr)
|
---|
| 568 | cr.manage_setLocalRoles(student_id, ['Owner',])
|
---|
| 569 | l.getContent().edit(mapping = dlev)
|
---|
| 570 | if tr_count > MAX_TRANS:
|
---|
| 571 | transaction.commit()
|
---|
| 572 | tr_count = 0
|
---|
| 573 | tr_count += 1
|
---|
| 574 | wftool.doActionFor(cr,'close')
|
---|
| 575 | wftool.doActionFor(l,level_wf_actions[dlev['verdict']])
|
---|
| 576 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
|
---|
| 577 |
|
---|
| 578 | ###)
|
---|
| 579 |
|
---|
| 580 | security.declareProtected(ModifyPortalContent,"loadJAMBFromCSV")###(
|
---|
| 581 | def loadJAMBFromCSV(self):
|
---|
| 582 | """load JAMB data from CSV values"""
|
---|
| 583 | #return
|
---|
| 584 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
|
---|
| 585 | import transaction
|
---|
| 586 | tr_count = 0
|
---|
| 587 | name = 'SampleJAMBDataII'
|
---|
| 588 | wftool = self.portal_workflow
|
---|
| 589 | no_import = False
|
---|
| 590 | if not no_import:
|
---|
| 591 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
|
---|
| 592 | 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')
|
---|
| 593 | logger = logging.getLogger('Import.%s' % name)
|
---|
| 594 | logger.info('Start loading from %s.csv' % name)
|
---|
| 595 | try:
|
---|
| 596 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
|
---|
| 597 | except:
|
---|
| 598 | logger.error('Error reading %s.csv' % name)
|
---|
| 599 | return
|
---|
| 600 | for jamb in result:
|
---|
| 601 | 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)
|
---|
| 602 | jamb_reg_no = jamb.get('REG-NO')
|
---|
| 603 | res = self.portal_catalog({'meta_type': "StudentApplication",
|
---|
| 604 | 'jamb_reg_no': jamb_reg_no })
|
---|
| 605 | if res:
|
---|
| 606 | em = 'Student with REG-NO %(REG-NO)s already exists\n' % jamb
|
---|
| 607 | logger.info(em)
|
---|
| 608 | no_import.write(em)
|
---|
| 609 | 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)
|
---|
| 610 | continue
|
---|
| 611 | jamb_name = jamb.get("NAME")
|
---|
| 612 | jamb_name.replace('>','')
|
---|
| 613 | names = jamb_name.split()
|
---|
| 614 | letter = names[-1][0].upper()
|
---|
| 615 | sid = self.generateStudentId(letter)
|
---|
| 616 | not_created = True
|
---|
| 617 | while not_created:
|
---|
| 618 | try:
|
---|
| 619 | students_folder.invokeFactory('Student', sid)
|
---|
| 620 | not_created = False
|
---|
| 621 | except BadRequest:
|
---|
| 622 | sid = self.generateStudentId(letter)
|
---|
| 623 | logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
|
---|
| 624 | student = getattr(self,sid)
|
---|
| 625 | student.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 626 | student.invokeFactory('StudentApplication','application')
|
---|
| 627 | da = {'Title': 'Application Data'}
|
---|
| 628 | da["jamb_reg_no"] = jamb.get("REG-NO")
|
---|
| 629 | da["jamb_lastname"] = jamb_name
|
---|
| 630 | da["jamb_sex"] = jamb.get("SEX")
|
---|
| 631 | da["jamb_state"] = jamb.get("STATE")
|
---|
| 632 | da["jamb_lga"] = jamb.get("LGA")
|
---|
| 633 | da["jamb_score"] = jamb.get("AGGREGATE")
|
---|
| 634 | da["jamb_first_cos"] = jamb.get("COURSE1")
|
---|
| 635 | da["jamb_second_cos"] = jamb.get("COURSE2")
|
---|
| 636 | da["jamb_first_uni"] = jamb.get("UNIV1")
|
---|
| 637 | da["jamb_second_uni"] = jamb.get("UNIV2")
|
---|
| 638 | app = student.application
|
---|
| 639 | app_doc = app.getContent()
|
---|
| 640 | app_doc.edit(mapping=da)
|
---|
| 641 | #wftool.doActionFor(app,'open',dest_container=app)
|
---|
| 642 | app.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 643 | student.getContent().createSubObjects()
|
---|
| 644 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
|
---|
| 645 | ###)
|
---|
[1775] | 646 |
|
---|
| 647 |
|
---|
| 648 | security.declareProtected(ModifyPortalContent,"importPreviousSessionStudents")###(
|
---|
| 649 | def importPreviousSessionStudents(self):
|
---|
| 650 | """load and create previous session students from CSV"""
|
---|
| 651 | import transaction
|
---|
| 652 | import random
|
---|
| 653 | wftool = self.portal_workflow
|
---|
| 654 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
|
---|
| 655 | students_folder = self.portal_url.getPortalObject().campus.students
|
---|
| 656 | tr_count = 1
|
---|
| 657 | total = 0
|
---|
| 658 | #name = 'pume_results'
|
---|
| 659 | name = 'Previous'
|
---|
| 660 | keys = self.portal_schemas.import_student.keys()
|
---|
| 661 | keys += self.portal_schemas.import_student_level_data.keys()
|
---|
| 662 | not_imported = []
|
---|
| 663 | imported = []
|
---|
| 664 | certificates = {}
|
---|
| 665 | logger = logging.getLogger('Students.StudentsFolder.importPreviousSessionStudents')
|
---|
| 666 | try:
|
---|
| 667 | records = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
|
---|
| 668 | except:
|
---|
| 669 | logger.error('Error reading %s.csv' % name)
|
---|
| 670 | return
|
---|
| 671 | start = True
|
---|
| 672 | for record in records:
|
---|
| 673 | if start:
|
---|
| 674 | start = False
|
---|
| 675 | logger.info('Start loading from %s.csv' % name)
|
---|
| 676 | false_keys = [k for k in record.keys() if k not in keys]
|
---|
| 677 | right_keys = [k for k in record.keys() if k in keys]
|
---|
| 678 | if false_keys:
|
---|
| 679 | logger.info('Fields %s not in schema' % false_keys)
|
---|
| 680 | s = ','.join(['"%s"' % k for k in right_keys])
|
---|
| 681 | imported.append(s)
|
---|
| 682 | not_imported.append('%s,"error"' % s)
|
---|
| 683 | format = ','.join(['"%%(%s)s"' % k for k in right_keys])
|
---|
| 684 | format_error = format + ',"%(error)s"'
|
---|
| 685 | study_course = makeCertificateCode(record.get('study_course'))
|
---|
| 686 | matric_no = record.get('matric_no')
|
---|
| 687 | student_res = self.students_catalog(matric_no = matric_no)
|
---|
| 688 | if student_res:
|
---|
| 689 | record['error'] = "Student exists"
|
---|
| 690 | not_imported.append(format_error % record)
|
---|
| 691 | continue
|
---|
| 692 | if study_course not in certificates.keys():
|
---|
| 693 | cert_res = self.portal_catalog(portal_type='Certificate',
|
---|
| 694 | id = study_course)
|
---|
| 695 | if not cert_res:
|
---|
| 696 | record['error'] = "No such studycourse"
|
---|
| 697 | not_imported.append(format_error % record)
|
---|
| 698 | continue
|
---|
| 699 | certificates[cert_res[0].id] = cert_res[0]
|
---|
| 700 | sid = self.generateStudentId('x',students_folder)
|
---|
| 701 | students_folder.invokeFactory('Student', sid)
|
---|
| 702 | #from pdb import set_trace;set_trace()
|
---|
| 703 | record['student_id'] = sid
|
---|
| 704 | student = getattr(self,sid)
|
---|
| 705 | student.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 706 | student.invokeFactory('StudentApplication','application')
|
---|
| 707 | app = student.application
|
---|
| 708 | app_doc = app.getContent()
|
---|
| 709 | dict = {'Title': 'Application Data'}
|
---|
| 710 | dict["jamb_lastname"] = "%(firstname)s %(lastname)s %(middlename)s" % record
|
---|
| 711 | r2d = [
|
---|
| 712 | ('entry_mode','entry_mode'),
|
---|
| 713 | ('sex','jamb_sex'),
|
---|
| 714 | ('jamb_score','jamb_score'),
|
---|
| 715 | ('jamb_reg_no','jamb_reg_no'),
|
---|
| 716 | ]
|
---|
| 717 | for r,d in r2d:
|
---|
| 718 | dict[d] = record[r]
|
---|
| 719 | app_doc.edit(mapping=dict)
|
---|
| 720 | app.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 721 | wftool.doActionFor(app,'close')
|
---|
| 722 | record['sex'] = record['sex'] == 'F'
|
---|
| 723 | student.invokeFactory('StudentPersonal','personal')
|
---|
| 724 | dict = {}
|
---|
| 725 | r2d = [('firstname','firstname'),
|
---|
| 726 | ('middlename','middlename'),
|
---|
| 727 | ('lastname','lastname'),
|
---|
| 728 | ('sex','sex'),
|
---|
| 729 | ('email','email'),
|
---|
| 730 | ('phone','phone'),
|
---|
| 731 | ('address','perm_address'),
|
---|
| 732 | ]
|
---|
| 733 | for r,d in r2d:
|
---|
| 734 | dict[d] = record[r]
|
---|
| 735 | per = student.personal
|
---|
| 736 | per_doc = per.getContent()
|
---|
| 737 | per_doc.edit(mapping = dict)
|
---|
| 738 | per.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 739 | #
|
---|
| 740 | # Clearance
|
---|
| 741 | #
|
---|
| 742 | student.invokeFactory('StudentClearance','clearance')
|
---|
| 743 | #wftool.doActionFor(student.clearance,'open')
|
---|
| 744 | clearance = getattr(student,'clearance')
|
---|
| 745 | dict = {'Title': 'Clearance/Eligibility Record'}
|
---|
| 746 | clearance.getContent().edit(mapping = dict)
|
---|
| 747 | student.clearance.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 748 | #
|
---|
| 749 | # Study Course
|
---|
| 750 | #
|
---|
| 751 | student.invokeFactory('StudentStudyCourse','study_course')
|
---|
| 752 | study_course = student.study_course
|
---|
| 753 | dict = {}
|
---|
| 754 | r2d = [('session','current_session'),
|
---|
| 755 | ('level','current_level'),
|
---|
| 756 | ('verdict','current_verdict'),
|
---|
| 757 | ('study_course','study_course'),
|
---|
| 758 | ]
|
---|
| 759 | for r,d in r2d:
|
---|
| 760 | dict[d] = record[r]
|
---|
| 761 | study_course.getContent().edit(mapping=dict)
|
---|
| 762 | #
|
---|
| 763 | # Study Level
|
---|
| 764 | #
|
---|
| 765 | level = record['level']
|
---|
| 766 | study_course.invokeFactory('StudentStudyLevel',level)
|
---|
| 767 | study_level = getattr(study_course,level)
|
---|
| 768 | dict = {}
|
---|
| 769 | r2d = [('session','session'),
|
---|
| 770 | ('level','code'),
|
---|
| 771 | ('verdict','verdict'),
|
---|
| 772 | ]
|
---|
| 773 | for r,d in r2d:
|
---|
| 774 | dict[d] = record[r]
|
---|
| 775 | study_level.getContent().edit(mapping=dict)
|
---|
| 776 | wftool.doActionFor(student,'return')
|
---|
| 777 | imported.append(format % record)
|
---|
| 778 | tr_count += 1
|
---|
| 779 | record['tr_count'] = tr_count
|
---|
| 780 | record['total'] = total
|
---|
| 781 | logger.info('%(total)s+%(tr_count)s: Creating Student %(student_id)s %(matric_no)s %(jamb_reg_no)s' % record)
|
---|
| 782 | if tr_count > 1000:
|
---|
| 783 | if len(not_imported) > 0:
|
---|
| 784 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write(
|
---|
| 785 | '\n'.join(not_imported)+'\n')
|
---|
| 786 | not_imported = []
|
---|
| 787 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write(
|
---|
| 788 | '\n'.join(imported) + '\n')
|
---|
| 789 | imported = []
|
---|
| 790 | em = '%d transactions commited total %s' % (tr_count,total)
|
---|
| 791 | transaction.commit()
|
---|
| 792 | logger.info(em)
|
---|
| 793 | regs = []
|
---|
| 794 | total += tr_count
|
---|
| 795 | tr_count = 0
|
---|
| 796 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write(
|
---|
| 797 | '\n'.join(imported))
|
---|
| 798 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write(
|
---|
| 799 | '\n'.join(not_imported))
|
---|
| 800 | em = '%d transactions commited total %d' % (tr_count,total)
|
---|
| 801 | logger.info(em)
|
---|
| 802 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
|
---|
| 803 | ###)
|
---|
| 804 |
|
---|
| 805 |
|
---|
| 806 | security.declareProtected(ModifyPortalContent,"createDEStudents")###(
|
---|
| 807 | def createDEStudents(self):
|
---|
| 808 | """load Fulltime Studentdata from CSV values"""
|
---|
| 809 | import transaction
|
---|
| 810 | import random
|
---|
| 811 | #from pdb import set_trace
|
---|
| 812 | wftool = self.portal_workflow
|
---|
| 813 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
|
---|
| 814 | csv_d = {'jamb_reg_no': "RegNumber",
|
---|
| 815 | 'jamb_lastname': "Name",
|
---|
| 816 | 'session': "Session",
|
---|
| 817 | 'pume_tot_score': "PUDE SCORE",
|
---|
| 818 | ##'jamb_score': "JambScore",
|
---|
| 819 | 'entry_mode': "EntryMode",
|
---|
| 820 | 'jamb_sex': "Sex",
|
---|
| 821 | 'jamb_state': "State",
|
---|
| 822 | 'jamb_first_cos': "AdminCourse",
|
---|
| 823 | 'faculty': "AdminFaculty",
|
---|
| 824 | 'course_code': "AdmitCoscode",
|
---|
| 825 | 'stud_status':"AdmitStatus",
|
---|
| 826 | 'department': "AdmitDept",
|
---|
| 827 | 'jamb_lga': "LGA",
|
---|
| 828 | 'app_email': "email",
|
---|
| 829 | 'app_mobile': "PhoneNumbers",
|
---|
| 830 | }
|
---|
| 831 | csv_fields = [f[1] for f in csv_d.items()]
|
---|
| 832 | tr_count = 0
|
---|
| 833 | total = 0
|
---|
| 834 | #name = 'pume_results'
|
---|
| 835 | name = 'DE_Admitted'
|
---|
| 836 | no_import = []
|
---|
| 837 | s = ','.join(['"%s"' % fn for fn in csv_fields])
|
---|
| 838 | no_import.append('"Error",%s' % s)
|
---|
| 839 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
|
---|
| 840 | no_certificate = "no certificate %s" % format
|
---|
| 841 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import))
|
---|
| 842 | logger = logging.getLogger('Students.StudentsFolder.createDEStudents')
|
---|
| 843 | logger.info('Start loading from %s.csv' % name)
|
---|
| 844 | l = self.portal_catalog({'meta_type': "Certificate"})
|
---|
| 845 | certs = {}
|
---|
| 846 | cert_docs = {}
|
---|
| 847 | for f in l:
|
---|
| 848 | certs[f.getId] = f.getObject().getContent()
|
---|
| 849 | try:
|
---|
| 850 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
|
---|
| 851 | except:
|
---|
| 852 | logger.error('Error reading %s.csv' % name)
|
---|
| 853 | return
|
---|
| 854 | for jamb in result:
|
---|
| 855 | jamb['Error'] = "Processing"
|
---|
| 856 | logger.info(format % jamb)
|
---|
| 857 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no'])
|
---|
| 858 | res = self.portal_catalog({'portal_type': "StudentApplication",
|
---|
| 859 | 'SearchableText': jamb_reg_no })
|
---|
| 860 | if res:
|
---|
| 861 | em = 'Student with RegNo %s already exists\n' % jamb_reg_no
|
---|
| 862 | logger.info(em)
|
---|
| 863 | jamb['Error'] = "Student exists"
|
---|
| 864 | no_import.append(format % jamb)
|
---|
| 865 | continue
|
---|
| 866 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code']))
|
---|
| 867 | if cert_id not in certs.keys():
|
---|
| 868 | em = 'No Certificate with ID %s \n' % cert_id
|
---|
| 869 | logger.info(em)
|
---|
| 870 | jamb['Error'] = "No Certificate %s" % cert_id
|
---|
| 871 | no_import.append( format % jamb)
|
---|
| 872 | continue
|
---|
| 873 | jamb_reg_no =jamb.get(csv_d['jamb_reg_no'])
|
---|
| 874 | cert_doc = certs[cert_id]
|
---|
| 875 | catalog_entry = {}
|
---|
| 876 | catalog_entry['jamb_reg_no'] = jamb_reg_no
|
---|
| 877 | jamb_name = jamb.get(csv_d['jamb_lastname'])
|
---|
| 878 | jamb_name.replace('>','')
|
---|
| 879 | jamb_name.replace('<','')
|
---|
| 880 | names = jamb_name.split()
|
---|
| 881 | letter = names[-1][0].upper()
|
---|
| 882 | sid = self.generateStudentId(letter)
|
---|
| 883 | not_created = True
|
---|
| 884 | while not_created:
|
---|
| 885 | try:
|
---|
| 886 | students_folder.invokeFactory('Student', sid)
|
---|
| 887 | not_created = False
|
---|
| 888 | except BadRequest:
|
---|
| 889 | sid = self.generateStudentId(letter)
|
---|
| 890 | catalog_entry['id'] = sid
|
---|
| 891 | tr_count += 1
|
---|
| 892 | logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
|
---|
| 893 | student = getattr(self,sid)
|
---|
| 894 | student.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 895 | student.invokeFactory('StudentPume','pume')
|
---|
| 896 | dp = {'Title': 'Pume Data'}
|
---|
| 897 | student.invokeFactory('StudentApplication','application')
|
---|
| 898 | da = {'Title': 'Application Data'}
|
---|
| 899 | da["jamb_lastname"] = jamb_name
|
---|
| 900 | da_fields = ('jamb_reg_no',
|
---|
| 901 | 'jamb_sex',
|
---|
| 902 | 'entry_mode',
|
---|
| 903 | #'jamb_score',
|
---|
| 904 | 'jamb_first_cos',
|
---|
| 905 | 'jamb_sex',
|
---|
| 906 | 'jamb_state',
|
---|
| 907 | 'jamb_lga',
|
---|
| 908 | 'app_email',
|
---|
| 909 | 'app_mobile',
|
---|
| 910 | )
|
---|
| 911 | for f in da_fields:
|
---|
| 912 | da[f] = jamb.get(csv_d[f])
|
---|
| 913 | catalog_entry['email'] = jamb.get(csv_d['app_email'])
|
---|
| 914 | app = student.application
|
---|
| 915 | app_doc = app.getContent()
|
---|
| 916 | picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no)
|
---|
| 917 | #import pdb;pdb.set_trace()
|
---|
| 918 | if os.path.exists(picture):
|
---|
| 919 | file = open(picture)
|
---|
| 920 | if False:
|
---|
| 921 | img = PIL.Image.open(file)
|
---|
| 922 | img.thumbnail((150,200),
|
---|
| 923 | resample=PIL.Image.ANTIALIAS)
|
---|
| 924 | # We now need a buffer to write to. It can't be the same
|
---|
| 925 | # as the inbuffer as the PNG writer will write over itself.
|
---|
| 926 | outfile = StringIO()
|
---|
| 927 | img.save(outfile, format=img.format)
|
---|
| 928 | else:
|
---|
| 929 | outfile = file.read()
|
---|
| 930 | app_doc.manage_addFile('passport',
|
---|
| 931 | file=outfile,
|
---|
| 932 | title="%s.jpg" % jamb_reg_no)
|
---|
| 933 | app.getContent().edit(mapping=da)
|
---|
| 934 | app.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 935 | #wftool.doActionFor(app,'close')
|
---|
| 936 | dp_fields = (
|
---|
| 937 | #'pume_eng_score',
|
---|
| 938 | #'pume_gen_score',
|
---|
| 939 | 'pume_tot_score',
|
---|
| 940 | )
|
---|
| 941 | dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded"
|
---|
| 942 | pume = student.pume
|
---|
| 943 | pume.getContent().edit(mapping=dp)
|
---|
| 944 | #wftool.doActionFor(pume,'close')
|
---|
| 945 | pume.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 946 | #student.getContent().createSubObjects()
|
---|
| 947 | dp = {}
|
---|
| 948 | if len(names) == 3:
|
---|
| 949 | dp['firstname'] = names[0].capitalize()
|
---|
| 950 | dp['middlename'] = names[1].capitalize()
|
---|
| 951 | dp['lastname'] = names[2].capitalize()
|
---|
| 952 | elif len(names) == 2:
|
---|
| 953 | dp['firstname'] = names[0].capitalize()
|
---|
| 954 | dp['middlename'] = ''
|
---|
| 955 | dp['lastname'] = names[1].capitalize()
|
---|
| 956 | else:
|
---|
| 957 | dp['firstname'] = ''
|
---|
| 958 | dp['middlename'] = ''
|
---|
| 959 | dp['lastname'] = jamb_name
|
---|
| 960 | dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F'
|
---|
| 961 | catalog_entry['sex'] = dp['sex']
|
---|
| 962 | catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp
|
---|
| 963 | student.invokeFactory('StudentPersonal','personal')
|
---|
| 964 | per = student.personal
|
---|
| 965 | per_doc = per.getContent()
|
---|
| 966 | per_doc.edit(mapping = dp)
|
---|
| 967 | per.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 968 | if jamb.get(csv_d['stud_status']) == "Admitted":
|
---|
| 969 | wftool.doActionFor(student,'pume_pass')
|
---|
| 970 | wftool.doActionFor(student,'admit')
|
---|
| 971 | else:
|
---|
| 972 | wftool.doActionFor(student,'pume_fail')
|
---|
| 973 | wftool.doActionFor(student,'reject_admission')
|
---|
| 974 | continue
|
---|
| 975 | #
|
---|
| 976 | # Clearance
|
---|
| 977 | #
|
---|
| 978 | student.invokeFactory('StudentClearance','clearance')
|
---|
| 979 | #wftool.doActionFor(student.clearance,'open')
|
---|
| 980 | dp = {'Title': 'Clearance/Eligibility Record'}
|
---|
| 981 | student.clearance.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 982 | #
|
---|
| 983 | # Study Course
|
---|
| 984 | #
|
---|
| 985 | student.invokeFactory('StudentStudyCourse','study_course')
|
---|
| 986 | study_course = student.study_course
|
---|
| 987 | dsc = {}
|
---|
| 988 | #from_certificate = ['title',
|
---|
| 989 | # 'max_elect',
|
---|
| 990 | # 'max_pass',
|
---|
| 991 | # 'n_core',
|
---|
| 992 | # 'nr_years',
|
---|
| 993 | # 'probation_credits',
|
---|
| 994 | # 'promotion_credits',
|
---|
| 995 | # 'start_level',
|
---|
| 996 | # ]
|
---|
| 997 | #for f in from_certificate:
|
---|
| 998 | # dsc[f] = getattr(cert_doc,f)
|
---|
| 999 | #dsc['faculty'] = jamb.get(csv_d['faculty'])
|
---|
| 1000 | #dsc['department'] = jamb.get(csv_d['department'])
|
---|
| 1001 | catalog_entry['faculty'] = jamb.get(csv_d['faculty'])
|
---|
| 1002 | catalog_entry['department'] = jamb.get(csv_d['department'])
|
---|
| 1003 | catalog_entry['course'] = cert_id
|
---|
| 1004 | #catalog_entry['level'] = getattr(cert_doc,'start_level')
|
---|
| 1005 | catalog_entry['level'] = '200'
|
---|
| 1006 | dsc['study_course'] = cert_id
|
---|
| 1007 | dsc['current_level'] = '200'
|
---|
| 1008 | #dsc['entry_session'] = jamb.get(csv_d['session'])
|
---|
| 1009 | study_course.getContent().edit(mapping=dsc)
|
---|
| 1010 | self.students_catalog.addRecord(**catalog_entry)
|
---|
| 1011 | if tr_count > 10:
|
---|
| 1012 | if len(no_import) > 1:
|
---|
| 1013 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write(
|
---|
| 1014 | '\n'.join(no_import)+'\n')
|
---|
| 1015 | no_import = []
|
---|
| 1016 | em = '%d transactions commited\n' % tr_count
|
---|
| 1017 | transaction.commit()
|
---|
| 1018 | logger.info(em)
|
---|
| 1019 | total += tr_count
|
---|
| 1020 | tr_count = 0
|
---|
| 1021 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write(
|
---|
| 1022 | '\n'.join(no_import))
|
---|
| 1023 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
|
---|
| 1024 | ###)
|
---|
| 1025 |
|
---|
| 1026 | security.declareProtected(ModifyPortalContent,"createNewStudents")###(
|
---|
| 1027 | def createNewStudents(self):
|
---|
| 1028 | """load Fulltime Studentdata from CSV values"""
|
---|
| 1029 | import transaction
|
---|
| 1030 | import random
|
---|
| 1031 | #from pdb import set_trace
|
---|
| 1032 | wftool = self.portal_workflow
|
---|
| 1033 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
|
---|
| 1034 | csv_d = {'jamb_reg_no': "RegNumber",
|
---|
| 1035 | 'jamb_lastname': "Name",
|
---|
| 1036 | 'session': "Session",
|
---|
| 1037 | 'pume_tot_score': "PUME SCORE",
|
---|
| 1038 | 'jamb_score': "JambScore",
|
---|
| 1039 | 'jamb_sex': "Sex",
|
---|
| 1040 | 'jamb_state': "State",
|
---|
| 1041 | ## 'jamb_first_cos': "AdminCourse",
|
---|
| 1042 | 'faculty': "AdminFaculty",
|
---|
| 1043 | 'course_code': "AdmitCoscode",
|
---|
| 1044 | 'stud_status':"AdmitStatus",
|
---|
| 1045 | 'department': "AdmitDept",
|
---|
| 1046 | 'jamb_lga': "LGA",
|
---|
| 1047 | 'app_email': "email",
|
---|
| 1048 | 'app_mobile': "PhoneNumbers",
|
---|
| 1049 | }
|
---|
| 1050 | csv_fields = [f[1] for f in csv_d.items()]
|
---|
| 1051 | tr_count = 0
|
---|
| 1052 | total = 0
|
---|
| 1053 | #name = 'pume_results'
|
---|
| 1054 | name = 'Admitted'
|
---|
| 1055 | no_import = []
|
---|
| 1056 | s = ','.join(['"%s"' % fn for fn in csv_fields])
|
---|
| 1057 | no_import.append('"Error",%s' % s)
|
---|
| 1058 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
|
---|
| 1059 | no_certificate = "no certificate %s" % format
|
---|
| 1060 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import))
|
---|
| 1061 | logger = logging.getLogger('Students.StudentsFolder.createNewStudents')
|
---|
| 1062 | logger.info('Start loading from %s.csv' % name)
|
---|
| 1063 | l = self.portal_catalog({'meta_type': "Certificate"})
|
---|
| 1064 | certs = {}
|
---|
| 1065 | cert_docs = {}
|
---|
| 1066 | for f in l:
|
---|
| 1067 | certs[f.getId] = f.getObject().getContent()
|
---|
| 1068 | try:
|
---|
| 1069 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
|
---|
| 1070 | except:
|
---|
| 1071 | logger.error('Error reading %s.csv' % name)
|
---|
| 1072 | return
|
---|
| 1073 | for jamb in result:
|
---|
| 1074 | jamb['Error'] = "Processing "
|
---|
| 1075 | logger.info(format % jamb)
|
---|
| 1076 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no'])
|
---|
| 1077 | res = self.portal_catalog({'portal_type': "StudentApplication",
|
---|
| 1078 | 'SearchableText': jamb_reg_no })
|
---|
| 1079 | if res:
|
---|
| 1080 | em = 'Student with RegNo %s already exists\n' % jamb_reg_no
|
---|
| 1081 | logger.info(em)
|
---|
| 1082 | jamb['Error'] = "Student exists"
|
---|
| 1083 | no_import.append(format % jamb)
|
---|
| 1084 | continue
|
---|
| 1085 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code']))
|
---|
| 1086 | if cert_id not in certs.keys():
|
---|
| 1087 | em = 'No Certificate with ID %s \n' % cert_id
|
---|
| 1088 | logger.info(em)
|
---|
| 1089 | jamb['Error'] = "No Certificate %s" % cert_id
|
---|
| 1090 | no_import.append( format % jamb)
|
---|
| 1091 | continue
|
---|
| 1092 | res = self.portal_pumeresults(jamb_reg_no = jamb_reg_no)
|
---|
| 1093 | if len(res) == 1:
|
---|
| 1094 | self.portal_pumeresults.modifyRecord(jamb_reg_no = jamb_reg_no,
|
---|
| 1095 | status = jamb.get(csv_d['stud_status']),
|
---|
| 1096 | )
|
---|
| 1097 | jamb_reg_no =jamb.get(csv_d['jamb_reg_no'])
|
---|
| 1098 | cert_doc = certs[cert_id]
|
---|
| 1099 | catalog_entry = {}
|
---|
| 1100 | catalog_entry['jamb_reg_no'] = jamb_reg_no
|
---|
| 1101 | jamb_name = jamb.get(csv_d['jamb_lastname'])
|
---|
| 1102 | jamb_name.replace('>','')
|
---|
| 1103 | jamb_name.replace('<','')
|
---|
| 1104 | names = jamb_name.split()
|
---|
| 1105 | letter = names[-1][0].upper()
|
---|
| 1106 | sid = self.generateStudentId(letter)
|
---|
| 1107 | not_created = True
|
---|
| 1108 | while not_created:
|
---|
| 1109 | try:
|
---|
| 1110 | students_folder.invokeFactory('Student', sid)
|
---|
| 1111 | not_created = False
|
---|
| 1112 | except BadRequest:
|
---|
| 1113 | sid = self.generateStudentId(letter)
|
---|
| 1114 | catalog_entry['id'] = sid
|
---|
| 1115 | tr_count += 1
|
---|
| 1116 | logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s reg_no %(jamb_reg_no)s ' % vars())
|
---|
| 1117 | student = getattr(self,sid)
|
---|
| 1118 | student.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 1119 | student.invokeFactory('StudentPume','pume')
|
---|
| 1120 | dp = {'Title': 'Pume Data'}
|
---|
| 1121 | student.invokeFactory('StudentApplication','application')
|
---|
| 1122 | da = {'Title': 'Application Data'}
|
---|
| 1123 | da["jamb_lastname"] = jamb_name
|
---|
| 1124 | da_fields = ('jamb_reg_no',
|
---|
| 1125 | 'jamb_sex',
|
---|
| 1126 | #'jamb_state',
|
---|
| 1127 | 'jamb_score',
|
---|
| 1128 | ## 'jamb_first_cos',
|
---|
| 1129 | 'jamb_sex',
|
---|
| 1130 | 'jamb_state',
|
---|
| 1131 | 'jamb_lga',
|
---|
| 1132 | 'app_email',
|
---|
| 1133 | 'app_mobile',
|
---|
| 1134 | )
|
---|
| 1135 | for f in da_fields:
|
---|
| 1136 | da[f] = jamb.get(csv_d[f])
|
---|
| 1137 | catalog_entry['email'] = jamb.get(csv_d['app_email'])
|
---|
| 1138 | app = student.application
|
---|
| 1139 | app_doc = app.getContent()
|
---|
| 1140 | #import pdb;pdb.set_trace()
|
---|
| 1141 | picture ="%s/import/pictures/%s.jpg" % (i_home,picture_id)
|
---|
| 1142 | if os.path.exists(picture):
|
---|
| 1143 | file = open(picture)
|
---|
| 1144 | if False:
|
---|
| 1145 | img = PIL.Image.open(file)
|
---|
| 1146 | img.thumbnail((150,200),
|
---|
| 1147 | resample=PIL.Image.ANTIALIAS)
|
---|
| 1148 | # We now need a buffer to write to. It can't be the same
|
---|
| 1149 | # as the inbuffer as the PNG writer will write over itself.
|
---|
| 1150 | outfile = StringIO()
|
---|
| 1151 | img.save(outfile, format=img.format)
|
---|
| 1152 | else:
|
---|
| 1153 | outfile = file.read()
|
---|
| 1154 | app_doc.manage_addFile('passport',
|
---|
| 1155 | file=outfile,
|
---|
| 1156 | title="%s.jpg" % jamb_reg_no)
|
---|
| 1157 | app.getContent().edit(mapping=da)
|
---|
| 1158 | app.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 1159 | #wftool.doActionFor(app,'close')
|
---|
| 1160 | dp_fields = (
|
---|
| 1161 | #'pume_eng_score',
|
---|
| 1162 | #'pume_gen_score',
|
---|
| 1163 | 'pume_tot_score',
|
---|
| 1164 | )
|
---|
| 1165 | dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded"
|
---|
| 1166 | pume = student.pume
|
---|
| 1167 | pume.getContent().edit(mapping=dp)
|
---|
| 1168 | #wftool.doActionFor(pume,'close')
|
---|
| 1169 | pume.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 1170 | #student.getContent().createSubObjects()
|
---|
| 1171 | dp = {}
|
---|
| 1172 | if len(names) == 3:
|
---|
| 1173 | dp['firstname'] = names[0].capitalize()
|
---|
| 1174 | dp['middlename'] = names[1].capitalize()
|
---|
| 1175 | dp['lastname'] = names[2].capitalize()
|
---|
| 1176 | elif len(names) == 2:
|
---|
| 1177 | dp['firstname'] = names[0].capitalize()
|
---|
| 1178 | dp['middlename'] = ''
|
---|
| 1179 | dp['lastname'] = names[1].capitalize()
|
---|
| 1180 | else:
|
---|
| 1181 | dp['firstname'] = ''
|
---|
| 1182 | dp['middlename'] = ''
|
---|
| 1183 | dp['lastname'] = jamb_name
|
---|
| 1184 | dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F'
|
---|
| 1185 | catalog_entry['sex'] = dp['sex']
|
---|
| 1186 | catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp
|
---|
| 1187 | student.invokeFactory('StudentPersonal','personal')
|
---|
| 1188 | per = student.personal
|
---|
| 1189 | per_doc = per.getContent()
|
---|
| 1190 | per_doc.edit(mapping = dp)
|
---|
| 1191 | per.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 1192 | if jamb.get(csv_d['stud_status']) == "Admitted":
|
---|
| 1193 | wftool.doActionFor(student,'pume_pass')
|
---|
| 1194 | wftool.doActionFor(student,'admit')
|
---|
| 1195 | else:
|
---|
| 1196 | wftool.doActionFor(student,'pume_fail')
|
---|
| 1197 | wftool.doActionFor(student,'reject_admission')
|
---|
| 1198 | continue
|
---|
| 1199 | #
|
---|
| 1200 | # Clearance
|
---|
| 1201 | #
|
---|
| 1202 | student.invokeFactory('StudentClearance','clearance')
|
---|
| 1203 | #wftool.doActionFor(student.clearance,'open')
|
---|
| 1204 | dp = {'Title': 'Clearance/Eligibility Record'}
|
---|
| 1205 | student.clearance.manage_setLocalRoles(sid, ['Owner',])
|
---|
| 1206 | #
|
---|
| 1207 | # Study Course
|
---|
| 1208 | #
|
---|
| 1209 | student.invokeFactory('StudentStudyCourse','study_course')
|
---|
| 1210 | study_course = student.study_course
|
---|
| 1211 | dsc = {}
|
---|
| 1212 | #from_certificate = ['title',
|
---|
| 1213 | # 'max_elect',
|
---|
| 1214 | # 'max_pass',
|
---|
| 1215 | # 'n_core',
|
---|
| 1216 | # 'nr_years',
|
---|
| 1217 | # 'probation_credits',
|
---|
| 1218 | # 'promotion_credits',
|
---|
| 1219 | # 'start_level',
|
---|
| 1220 | # ]
|
---|
| 1221 | #for f in from_certificate:
|
---|
| 1222 | # dsc[f] = getattr(cert_doc,f)
|
---|
| 1223 | #dsc['faculty'] = jamb.get(csv_d['faculty'])
|
---|
| 1224 | #dsc['department'] = jamb.get(csv_d['department'])
|
---|
| 1225 | catalog_entry['faculty'] = jamb.get(csv_d['faculty'])
|
---|
| 1226 | catalog_entry['department'] = jamb.get(csv_d['department'])
|
---|
| 1227 | catalog_entry['course'] = cert_id
|
---|
| 1228 | #catalog_entry['level'] = getattr(cert_doc,'start_level')
|
---|
| 1229 | catalog_entry['level'] = '100'
|
---|
| 1230 | dsc['study_course'] = cert_id
|
---|
| 1231 | #dsc['entry_level'] = '100'
|
---|
| 1232 | #dsc['entry_session'] = jamb.get(csv_d['session'])
|
---|
| 1233 | study_course.getContent().edit(mapping=dsc)
|
---|
| 1234 | self.students_catalog.addRecord(**catalog_entry)
|
---|
| 1235 | if tr_count > 10:
|
---|
| 1236 | if len(no_import) > 0:
|
---|
| 1237 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write(
|
---|
| 1238 | '\n'.join(no_import) + "\n")
|
---|
| 1239 | no_import = []
|
---|
| 1240 | em = '%d transactions commited\n' % tr_count
|
---|
| 1241 | transaction.commit()
|
---|
| 1242 | logger.info(em)
|
---|
| 1243 | total += tr_count
|
---|
| 1244 | tr_count = 0
|
---|
| 1245 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write(
|
---|
| 1246 | '\n'.join(no_import))
|
---|
| 1247 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
|
---|
| 1248 | ###)
|
---|
[1783] | 1249 |
|
---|
| 1250 |
|
---|
| 1251 | security.declareProtected(ModifyPortalContent,"fixVerdicts")###(
|
---|
| 1252 | def fixVerdicts(self,csv_file=None):
|
---|
| 1253 | """fix wrong uploaded verdicts"""
|
---|
| 1254 | import transaction
|
---|
| 1255 | import random
|
---|
| 1256 | wftool = self.portal_workflow
|
---|
| 1257 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
|
---|
| 1258 | students_folder = self.portal_url.getPortalObject().campus.students
|
---|
| 1259 | tr_count = 1
|
---|
| 1260 | total = 0
|
---|
| 1261 | if csv_file is None:
|
---|
| 1262 | name = 'Verdicts'
|
---|
| 1263 | else:
|
---|
| 1264 | name = csv_file
|
---|
| 1265 | st_cat = self.students_catalog
|
---|
| 1266 | no_import = []
|
---|
| 1267 | verdicts_voc = self.portal_vocabularies.verdicts
|
---|
| 1268 | rverdicts = {}
|
---|
| 1269 | for k,v in verdicts_voc.items():
|
---|
| 1270 | rverdicts[v.upper()] = k
|
---|
| 1271 | rverdicts['STUDENT ON PROBATION'] = 'C'
|
---|
| 1272 | logger = logging.getLogger('Students.StudentsFolder.fixVerdicts')
|
---|
| 1273 | try:
|
---|
| 1274 | verdicts = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
|
---|
| 1275 | except:
|
---|
| 1276 | logger.error('Error reading %s.csv' % name)
|
---|
| 1277 | return
|
---|
| 1278 | start = True
|
---|
| 1279 | #import pdb;pdb.set_trace()
|
---|
| 1280 | for verdict in verdicts:
|
---|
| 1281 | if start:
|
---|
| 1282 | start = False
|
---|
| 1283 | logger.info('Start loading from %s.csv' % name)
|
---|
| 1284 | s = ','.join(['"%s"' % fn for fn in verdict.keys()])
|
---|
| 1285 | no_import.append('%s,"Error"' % s)
|
---|
| 1286 | format = ','.join(['"%%(%s)s"' % fn for fn in verdict.keys()])
|
---|
| 1287 | format_error = format + ',"%(Error)s"'
|
---|
| 1288 | matric_no = verdict.get('MAT NO')
|
---|
| 1289 | if not matric_no:
|
---|
| 1290 | continue
|
---|
| 1291 | matric_no = matric_no.upper()
|
---|
| 1292 | if matric_no == '':
|
---|
| 1293 | continue
|
---|
| 1294 | verdict_code = rverdicts.get(verdict.get('CATEGORY'),None)
|
---|
| 1295 | if verdict_code is None:
|
---|
| 1296 | continue
|
---|
| 1297 | sres = st_cat(matric_no = matric_no)
|
---|
| 1298 | if sres:
|
---|
| 1299 | student_id = sres[0].id
|
---|
| 1300 | student_obj = getattr(students_folder,student_id,None)
|
---|
| 1301 | if student_obj:
|
---|
| 1302 | study_course = getattr(student_obj,'study_course',None)
|
---|
| 1303 | if study_course is None:
|
---|
| 1304 | verdict['Error'] = "Student did not yet log in"
|
---|
| 1305 | no_import.append( format_error % verdict)
|
---|
| 1306 | continue
|
---|
| 1307 | st_cat.modifyRecord(id = student_id,
|
---|
| 1308 | verdict=verdict_code)
|
---|
| 1309 |
|
---|
| 1310 | dsc = {}
|
---|
| 1311 | dsc['current_verdict'] = verdict_code
|
---|
| 1312 | study_course.getContent().edit(mapping=dsc)
|
---|
| 1313 | else:
|
---|
| 1314 | verdict['Error'] = "Not found in students_catalog"
|
---|
| 1315 | no_import.append( format_error % verdict)
|
---|
| 1316 | continue
|
---|
| 1317 | tr_count += 1
|
---|
| 1318 | if tr_count > 1000:
|
---|
| 1319 | if len(no_import) > 0:
|
---|
| 1320 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write(
|
---|
| 1321 | '\n'.join(no_import) + '\n')
|
---|
| 1322 | no_import = []
|
---|
| 1323 | em = '%d transactions commited total %s\n' % (tr_count,total)
|
---|
| 1324 | transaction.commit()
|
---|
| 1325 | regs = []
|
---|
| 1326 | logger.info(em)
|
---|
| 1327 | total += tr_count
|
---|
| 1328 | tr_count = 0
|
---|
| 1329 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write(
|
---|
| 1330 | '\n'.join(no_import))
|
---|
| 1331 | total += tr_count
|
---|
| 1332 | em = '%d total transactions commited' % (total)
|
---|
| 1333 | logger.info(em)
|
---|
| 1334 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
|
---|
| 1335 | ###)
|
---|
| 1336 |
|
---|
| 1337 |
|
---|
| 1338 | security.declareProtected(ModifyPortalContent,"fixAllEntryModeForReturning")###(
|
---|
| 1339 | def fixAllEntryModeForReturning(self):
|
---|
| 1340 | "read all Returning*.csv"
|
---|
| 1341 | ipath = "%s/import/" % i_home
|
---|
| 1342 | names = os.listdir(ipath)
|
---|
| 1343 | for name in names:
|
---|
| 1344 | head,tail = os.path.splitext(name)
|
---|
| 1345 | if head.startswith('Returning')\
|
---|
| 1346 | and tail == '.csv'\
|
---|
| 1347 | and name.find('imported') < 0:
|
---|
| 1348 | self.fixEntryModeForReturning(csv_file=head)
|
---|
| 1349 | ###)
|
---|
| 1350 |
|
---|
| 1351 | security.declareProtected(ModifyPortalContent,"fixEntryModeForReturning")###(
|
---|
| 1352 | def fixEntryModeForReturning(self,csv_file=None):
|
---|
| 1353 | """load Returning Studentdata from CSV values"""
|
---|
| 1354 | import transaction
|
---|
| 1355 | import random
|
---|
| 1356 | wftool = self.portal_workflow
|
---|
| 1357 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
|
---|
| 1358 | students_folder = self.portal_url.getPortalObject().campus.students
|
---|
| 1359 | tr_count = 1
|
---|
| 1360 | total = 0
|
---|
| 1361 | if csv_file is None:
|
---|
| 1362 | name = 'Returning'
|
---|
| 1363 | else:
|
---|
| 1364 | name = csv_file
|
---|
| 1365 | table = self.returning_import
|
---|
| 1366 | st_cat = self.students_catalog
|
---|
| 1367 | no_import = []
|
---|
| 1368 | logger = logging.getLogger('Students.StudentsFolder.fixEntryModeForReturning')
|
---|
| 1369 | try:
|
---|
| 1370 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
|
---|
| 1371 | except:
|
---|
| 1372 | logger.error('Error reading %s.csv' % name)
|
---|
| 1373 | return
|
---|
| 1374 | start = True
|
---|
| 1375 | for student in returning:
|
---|
| 1376 | if start:
|
---|
| 1377 | start = False
|
---|
| 1378 | logger.info('Start loading from %s.csv' % name)
|
---|
| 1379 | s = ','.join(['"%s"' % fn for fn in student.keys()])
|
---|
| 1380 | no_import.append('%s,"Error"' % s)
|
---|
| 1381 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()])
|
---|
| 1382 | format_error = format + ',"%(Error)s"'
|
---|
| 1383 | matric_no = student.get('matric_no')
|
---|
| 1384 | if not matric_no:
|
---|
| 1385 | continue
|
---|
| 1386 | matric_no = matric_no.upper()
|
---|
| 1387 | student['matric_no'] = matric_no
|
---|
| 1388 | if matric_no == '':
|
---|
| 1389 | continue
|
---|
| 1390 | if not table(matric_no = matric_no):
|
---|
| 1391 | student['Error'] = "Not imported yet"
|
---|
| 1392 | no_import.append( format_error % student)
|
---|
| 1393 | continue
|
---|
| 1394 | student_id = None
|
---|
| 1395 | app = None
|
---|
| 1396 | per = None
|
---|
| 1397 | if st_cat(matric_no = matric_no):
|
---|
| 1398 | student_id = st_cat(matric_no = matric_no)[0].id
|
---|
| 1399 | student_obj = getattr(students_folder,student_id,None)
|
---|
| 1400 | if student_obj:
|
---|
| 1401 | app = getattr(student_obj,'application',None)
|
---|
| 1402 | if app is not None:
|
---|
| 1403 | app_doc = app.getContent()
|
---|
| 1404 | per = getattr(student_obj,'personal',None)
|
---|
| 1405 | if per is not None:
|
---|
| 1406 | per_doc = per.getContent()
|
---|
| 1407 | student['Mode_of_Entry'] = entry_mode = student.get('Mode of Entry').upper()
|
---|
| 1408 | student['Permanent_Address'] = perm_address = student.get('Permanent Address')
|
---|
| 1409 | #import pdb;pdb.set_trace()
|
---|
| 1410 | if not entry_mode:
|
---|
| 1411 | student['Error'] = "'Mode of Entry' empty"
|
---|
| 1412 | no_import.append( format_error % student)
|
---|
| 1413 | continue
|
---|
| 1414 | try:
|
---|
| 1415 | table.modifyRecord(matric_no = matric_no,
|
---|
| 1416 | Mode_of_Entry = entry_mode,
|
---|
| 1417 | Permanent_Address = perm_address)
|
---|
| 1418 | except KeyError:
|
---|
| 1419 | student['Error'] = "Not found in returning_import"
|
---|
| 1420 | no_import.append( format_error % student)
|
---|
| 1421 | continue
|
---|
| 1422 | if student_id is not None:
|
---|
| 1423 | try:
|
---|
| 1424 | st_cat.modifyRecord(id = student_id,
|
---|
| 1425 | entry_mode=entry_mode)
|
---|
| 1426 | except KeyError:
|
---|
| 1427 | student['Error'] = "Not found in students_catalog"
|
---|
| 1428 | no_import.append( format_error % student)
|
---|
| 1429 | continue
|
---|
| 1430 | if app is not None:
|
---|
| 1431 | da = {}
|
---|
| 1432 | da['entry_mode'] = entry_mode
|
---|
| 1433 | app_doc.edit(mapping=da)
|
---|
| 1434 | if per is not None:
|
---|
| 1435 | dp = {}
|
---|
| 1436 | dp['perm_address'] = perm_address
|
---|
| 1437 | per_doc.edit(mapping=dp)
|
---|
| 1438 | tr_count += 1
|
---|
| 1439 | if tr_count > 1000:
|
---|
| 1440 | if len(no_import) > 0:
|
---|
| 1441 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write(
|
---|
| 1442 | '\n'.join(no_import) + '\n')
|
---|
| 1443 | no_import = []
|
---|
| 1444 | em = '%d transactions commited total %s\n' % (tr_count,total)
|
---|
| 1445 | transaction.commit()
|
---|
| 1446 | regs = []
|
---|
| 1447 | logger.info(em)
|
---|
| 1448 | total += tr_count
|
---|
| 1449 | tr_count = 0
|
---|
| 1450 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write(
|
---|
| 1451 | '\n'.join(no_import))
|
---|
| 1452 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
|
---|
| 1453 | ###) |
---|