- Timestamp:
- 28 Nov 2006, 12:41:54 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r927 r958 23 23 MAX_TRANS = 1000 24 24 25 def getInt(s): 25 def makeCertificateCode(code): ###( 26 code = code.replace('.','') 27 code = code.replace('(','') 28 code = code.replace(')','') 29 code = code.replace('/','') 30 code = code.replace(' ','') 31 code = code.replace('_','') 32 return code 33 34 ###) 35 36 def getInt(s): ###( 26 37 try: 27 38 return int(s) … … 34 45 except: 35 46 return 0.0 47 48 ###) 36 49 37 50 def getStudentByRegNo(self,reg_no): ###( … … 235 248 import transaction 236 249 import random 250 from pdb import set_trace 237 251 wftool = self.portal_workflow 238 252 students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() 239 csv_d = {'jamb_reg_no': "Matnumber", 240 'jamb_lastname': "Surname", 253 csv_d = {'jamb_reg_no': "JAMBRegno", 254 'jamb_lastname': "Name", 255 #'pume_options': "Options", 256 #'session': "Session", 257 #'days': "Days", 258 #'response': "Responce", 259 #'wrong': "Wrong", 260 #'pume_eng_score': "EngScore", 261 #'pume_gen_score': "GenScore", 262 'pume_tot_score': "Score", 263 #'batch': "Batch", 264 #'serial': "SerialNo", 265 #'jamb_score': "JambScore", 266 #'omitted':"Omitted", 267 #'search_key': "SearchKey", 268 'jamb_sex': "Sex", 269 'fac1': "Faculty", 270 'dep': "Dept", 271 #'fac2': "Fac2", 272 'jamb_first_cos': "Course Code", 273 'stud_status':"Admission Status", 274 #'registered': "Registered", 275 #'jamb_state': "State", 276 #'eng_fail': "EngFail", 277 #'gen_fail': "GenFail", 278 #'un_ans_eng': "UnAnsEng", 279 #'un_ans_eng': "UnAnsGen", 280 #'total_ans': "TotalUnAns", 281 #'dept': "Dept", 282 #'jamb_second_cos': "Course2", 283 #'jamb_third_cos': "course3", 284 } 285 csv_fields = [f[1] for f in csv_d.items()] 286 tr_count = 0 287 #name = 'pume_results' 288 name = 'pup' 289 no_import = [] 290 s = ','.join(['"(%s)"' % fn for fn in csv_fields]) 291 no_import.append('%s\n' % s) 292 logger = logging.getLogger('%s_import' % name) 293 logger.info('Start loading from %s.csv' % name) 294 #set_trace() 295 try: 296 result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) 297 except: 298 logger.error('Error reading %s.csv' % name) 299 return 300 for jamb in result: 301 format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) 302 processing = "processing %s" % format 303 logger.info(processing % jamb) 304 jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) 305 #import pdb;pdb.set_trace() 306 res = self.portal_catalog({'portal_type': "StudentApplication", 307 'jamb_reg_no': jamb_reg_no }) 308 if res: 309 em = 'Student with REG-NO %s already exists\n' % jamb_reg_no 310 logger.info(em) 311 no_import.append(em) 312 no_import.append(format % jamb) 313 continue 314 cert_id = makeCertificateCode(jamb.get(csv_d['jamb_first_cos'])) 315 res = self.portal_catalog({'portal_type': "Certificate", 316 'id': cert_id }) 317 if len(res) < 1: 318 em = 'No Certificate with ID %s \n' % cert_id 319 logger.info(em) 320 no_import.append(em) 321 no_import.append(format % jamb) 322 continue 323 cert = res[0].getObject() 324 cert_path = res[0].getPath() 325 cert_doc = cert.getContent() 326 jamb_name = jamb.get(csv_d['jamb_lastname']) 327 jamb_name.replace('>','') 328 names = jamb_name.split() 329 letter = names[-1][0].upper() 330 sid = self.generateStudentId(letter) 331 not_created = True 332 while not_created: 333 try: 334 students_folder.invokeFactory('Student', sid) 335 not_created = False 336 except BadRequest: 337 sid = self.generateStudentId(letter) 338 tr_count += 1 339 logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) 340 student = getattr(self,sid) 341 student.manage_setLocalRoles(sid, ['Owner',]) 342 student.invokeFactory('StudentClearance','clearance') 343 #wftool.doActionFor(student.clearance,'open') 344 dp = {'Title': 'Clearance/Eligibility Record'} 345 student.clearance.manage_setLocalRoles(sid, ['Owner',]) 346 student.invokeFactory('StudentPume','pume') 347 dp = {'Title': 'Pume Data'} 348 student.invokeFactory('StudentApplication','application') 349 da = {'Title': 'Application Data'} 350 da["jamb_lastname"] = jamb_name 351 da_fields = ('jamb_reg_no', 352 'jamb_sex', 353 #'jamb_state', 354 #'jamb_score', 355 'jamb_first_cos', 356 'jamb_sex', 357 #'jamb_state', 358 #'jamb_first_cos', 359 #'jamb_second_cos', 360 ) 361 for f in da_fields: 362 da[f] = jamb.get(csv_d[f]) 363 app = student.application 364 app.getContent().edit(mapping=da) 365 app.manage_setLocalRoles(sid, ['Owner',]) 366 #wftool.doActionFor(app,'close') 367 dp_fields = ( 368 #'pume_eng_score', 369 #'pume_gen_score', 370 'pume_tot_score', 371 ) 372 for f in dp_fields: 373 try: 374 dp[f] = float(jamb.get(csv_d[f])) 375 except ValueError: 376 dp[f] = 0.0 377 pume = student.pume 378 pume.getContent().edit(mapping=dp) 379 #wftool.doActionFor(pume,'close') 380 pume.manage_setLocalRoles(sid, ['Owner',]) 381 # 382 # Study Course 383 # 384 if jamb.get(csv_d['stud_status']) == "Admitted": 385 wftool.doActionFor(student,'pume_pass') 386 wftool.doActionFor(student,'admit') 387 else: 388 wftool.doActionFor(student,'pume_fail') 389 wftool.doActionFor(student,'reject_admission') 390 continue 391 student.invokeFactory('StudentStudyCourse','study_course') 392 study_course = student.study_course 393 dsc = {} 394 from_certificate = ['title', 395 'max_elect', 396 'max_pass', 397 'n_core', 398 'nr_years', 399 'probation_credits', 400 'promotion_credits', 401 'start_level', 402 ] 403 for f in from_certificate: 404 dsc[f] = getattr(cert_doc,f) 405 cpl = cert_path.split('/') 406 dsc['faculty'] = cpl[-4] 407 dsc['department'] = cpl[-3] 408 dsc['study_course'] = cert_id 409 dsc['entry_session'] = "2006/2007" #jamb.get(csv_d['session']) 410 study_course.getContent().edit(mapping=dsc) 411 student.getContent().createSubObjects() 412 if tr_count > MAX_TRANS: 413 transaction.commit() 414 em = '%d transactions commited\n' % tr_count 415 logger.info(em) 416 tr_count = 0 417 if len(no_import) > 1: 418 open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( 419 '\n'.join(no_import)) 420 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 421 ###) 422 423 security.declareProtected(ModifyPortalContent,"OLDloadPumeResultsFromCSV")###( 424 def OLDloadPumeResultsFromCSV(self): 425 """load Fulltime Studentdata from CSV values""" 426 import transaction 427 import random 428 wftool = self.portal_workflow 429 students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() 430 csv_d = {'jamb_reg_no': "JAMBRegno", 431 'jamb_lastname': "Name", 241 432 'pume_options': "Options", 242 433 'session': "Session", … … 246 437 'pume_eng_score': "EngScore", 247 438 'pume_gen_score': "GenScore", 248 'pume_tot_score': " Right",439 'pume_tot_score': "Score", 249 440 'batch': "Batch", 250 441 'serial': "SerialNo",
Note: See TracChangeset for help on using the changeset viewer.