Changeset 3372
- Timestamp:
- 25 Mar 2008, 19:03:53 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPImport.py
r3360 r3372 121 121 ###) 122 122 123 def findStudent(self,mode,student_id=None, matric_no=None, jamb_reg_no=None): ###( 124 student_record = None 125 msg = '' 126 key_used = '' 127 while True: 128 if student_id: 129 key_used = 'student_id' 130 res = self.students_catalog(id = student_id) 131 if not res: 132 msg = "no student with id %s" % student_id 133 break 134 student_record = res[0] 135 if matric_no and student_record.matric_no: 136 if matric_no != student_record.matric_no: 137 msg = "old matric_no %s overwritten with %s" % (student_record.matric_no,matric_no) 138 #logger.info("%s, old matric_no %s overwritten with %s" % (student_record.id,student_record.matric_no,matric_no)) 139 if jamb_reg_no and student_record.jamb_reg_no: 140 if jamb_reg_no != student_record.jamb_reg_no: 141 msg = "old reg_no %s overwritten with %s" % (student_record.jamb_reg_no,jamb_reg_no) 142 #logger.info("%s, old reg_no %s overwritten with %s" % (student_record.id,student_record.jamb_reg_no,jamb_reg_no)) 143 elif jamb_reg_no: 144 key_used = 'jamb_reg_no' 145 res = self.students_catalog(jamb_reg_no = jamb_reg_no) 146 if res: 147 if mode == 'create': 148 msg = "jamb_reg_no exists" 149 break 150 else: 151 if mode == 'edit': 152 msg = "no student with jamb_reg_no %s" % jamb_reg_no 153 break 154 student_record = res[0] 155 elif matric_no: 156 key_used = 'matric_no' 157 res = self.students_catalog(matric_no = matric_no) 158 if not res: 159 msg = "no student with matric_no %s" % matric_no 160 break 161 student_record = res[0] 162 break 163 d = {} 164 d['student_record'] = student_record 165 d['key_used'] = key_used 166 d['msg'] = msg 167 return d 168 ###) 169 123 170 def makeIdLists(self): ###( 124 171 pending_digests = [] … … 362 409 required_modes = ('create','edit','remove') 363 410 364 def getStudentRecord(self,mapping): ###(411 def old_getStudentRecord(self,mapping): ###( 365 412 id_field_found = False 366 413 msg = '' … … 403 450 if getattr(self,'_v_level_created',None) is None: 404 451 self._v_level_created = [] 452 if getattr(self,'_v_student_study_course',None) is None: 453 self._v_student_study_course = {} 405 454 msg = '' 406 455 key = '' 456 matric_no = mapping.get('matric_no','') 457 id = mapping.get('id','') 458 while True: 459 course_id = mapping.get('code') 460 if course_id not in self._v_courses.keys(): 461 msg = "no course with id: %s" % course_id 462 break 463 result = self.findStudent('create',student_id=id,matric_no=matric_no) 464 #student_record,msg = self.getStudentRecord(mapping) 465 msg = result['msg'] 466 if msg: 467 break 468 student_record = result['student_record'] 469 student_id = mapping['student_id'] = student_record.id 470 level_id = mapping.get('level_id','') 471 code = mapping.get('code','') 472 level_ident = "%(student_id)s_%(level_id)s" % vars() 473 if level_ident not in self._v_level_created: 474 context = self._v_student_study_course.get(student_id,None) 475 if context is None: 476 try: 477 context = getattr(getattr(students_folder, 478 "%(student_id)s" % vars()), 479 'study_course') 480 self._v_student_study_course[student_id] = context 481 except: 482 msg = "could not create level %(level_id)s for %(student_id)s" % vars() 483 break 484 if level_id not in context.objectIds(): 485 context.invokeFactory('StudentStudyLevel',"%(level_id)s" % vars()) 486 level = getattr(context,"%(level_id)s" % vars()) 487 self.portal_workflow.doActionFor(level,'open') 488 level.getContent().edit(mapping={'session': "%(session_id)s" % mapping,}) 489 self.portal_workflow.doActionFor(level,'close') 490 self._v_level_created += level_ident, 491 mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars() 492 for k in ('semester','credits',): 493 mapping[k] = getattr(self._v_courses[course_id],k) 494 try: 495 self.course_results.addRecord(**mapping) 496 except ValueError: 497 msg = "course result already exists: %s" % key 498 break 499 return key,msg,mapping 500 ###) 501 502 def create_old(self,mapping):###( 503 students_folder = self.portal_url.getPortalObject().campus.students 504 if getattr(self,'_v_courses',None) is None: 505 res = self.courses_catalog() 506 self._v_courses = {} 507 for brain in res: 508 self._v_courses[brain.code] = brain 509 if getattr(self,'_v_level_created',None) is None: 510 self._v_level_created = [] 511 msg = '' 512 key = '' 513 matric_no = mapping.get('matric_no','') 514 student_id = mapping.get('id','') 407 515 while True: 408 516 course_id = mapping.get('code') … … 454 562 key = '' 455 563 while True: 456 student_record,msg = self.getStudentRecord(mapping) 564 result = self.findStudent('edit',student_id=id,matric_no=matric_no) 565 #student_record,msg = self.getStudentRecord(mapping) 566 msg = result['msg'] 457 567 if msg: 458 568 break 569 student_record = result['student_record'] 459 570 student_id = student_record.id 460 571 level_id = mapping.get('level_id','') … … 488 599 return key,msg,mapping 489 600 ###) 490 491 601 ###) 492 493 494 class StudentStudyLevelImport(WAeUPImport):###(495 """ StudentStudyLevelImport """496 name = "student_study_level"497 plural_name = "%ss" % name498 commit_after = 1000000499 required_modes = ('create','edit','remove')500 602 501 603 class CertificateCourseImport(WAeUPImport):###( … … 926 1028 ###) 927 1029 1030 class StudentStudyLevelImport(WAeUPImport):###( 1031 """ StudentStudyLevelImport """ 1032 name = "student_study_level" 1033 plural_name = "%ss" % name 1034 commit_after = 1000000 1035 required_modes = ('create',) 1036 1037 def create(self,mapping): 1038 "edit student levels and create StudentStudyLevel object if not existent" 1039 wftool = self.portal_workflow 1040 logger = logging.getLogger('WAeUPTool.mass_create_level') 1041 students_folder = self.portal_url.getPortalObject().campus.students 1042 student_id = mapping.get('id',None) 1043 matric_no = mapping.get('matric_no',None) 1044 editable_keys = mapping.keys() 1045 key = '' 1046 msg = '' 1047 while True: 1048 result = self.findStudent('create',student_id=student_id,matric_no=matric_no) 1049 msg = result['msg'] 1050 if msg: 1051 break 1052 student_record = result['student_record'] 1053 student_id = student_record.id 1054 mapping['id'] = student_id 1055 session = mapping.get('session','') 1056 level = key = mapping.get('code','') 1057 if not level.isdigit(): 1058 msg = 'student %s: imported level is empty' % (student_id,) 1059 break 1060 student_course_obj = getattr(getattr(students_folder,student_id),student_obj,'study_course',None) 1061 if study_course_obj is None: 1062 msg = 'student %s: no study_course object' % student_id 1063 break 1064 level_obj = getattr(study_course_obj,level,None) 1065 if level_obj is None: 1066 # The only difference to the edit method is that we create a StudentStudyLevel object 1067 try: 1068 study_course_obj.invokeFactory('StudentStudyLevel',"%s" % level) 1069 level_obj = getattr(context,"%s" % level) 1070 except: 1071 continue 1072 level_obj.getContent().edit(mapping = mapping) 1073 level_review_state = wftool.getInfoFor(level_obj,'review_state',None) 1074 if level_review_state != "closed": 1075 wftool.doActionFor(level_obj,'close') 1076 break 1077 return key,msg,mapping 1078 ###) 1079 1080 def edit(self,mapping): ###( 1081 "edit student levels" 1082 wftool = self.portal_workflow 1083 logger = logging.getLogger('WAeUPTool.mass_edit_level') 1084 students_folder = self.portal_url.getPortalObject().campus.students 1085 student_id = mapping.get('id',None) 1086 matric_no = mapping.get('matric_no',None) 1087 key = '' 1088 msg = '' 1089 while True: 1090 result = self.findStudent('create',student_id=student_id,matric_no=matric_no) 1091 msg = result['msg'] 1092 if msg: 1093 break 1094 student_record = result['student_record'] 1095 student_id = student_record.id 1096 mapping['id'] = student_id 1097 #import pdb;pdb.set_trace() 1098 session = d['session'] = mapping.get('session','') 1099 level = key = mapping.get('level','') 1100 if not level.isdigit(): 1101 msg = 'student %s: imported level is empty' % (student_id,) 1102 break 1103 student_course_obj = getattr(getattr(students_folder,student_id),student_obj,'study_course',None) 1104 if study_course_obj is None: 1105 msg = 'student %s: no study_course object' % student_id 1106 break 1107 level_obj = getattr(study_course_obj,level,None) 1108 if level_obj is None: 1109 msg = 'student %s: no study_level object for level %s' % (student_id,level) 1110 break 1111 level_obj.getContent().edit(mapping = mapping) 1112 break 1113 return key,msg,mapping 1114 ###) 1115 928 1116 class VerdictImport(WAeUPImport):###( 929 1117 """ VerdictImport """ … … 933 1121 required_modes = ('create','edit') 934 1122 935 def create(self,mapping): 1123 def create(self,mapping): ###( 1124 "edit student verdicts and create StudentStudyLevel object if not existent" 1125 wftool = self.portal_workflow 1126 logger = logging.getLogger('WAeUPTool.mass_edit_verdict') 1127 students_folder = self.portal_url.getPortalObject().campus.students 1128 student_id = mapping.get('id',None) 1129 matric_no = mapping.get('matric_no',None) 1130 editable_keys = mapping.keys() 1131 key = '' 1132 while True: 1133 result = self.findStudent('create',student_id=student_id,matric_no=matric_no) 1134 #student_record,msg = self.getStudentRecord(mapping) 1135 msg = result['msg'] 1136 if msg: 1137 break 1138 student_record = result['student_record'] 1139 student_id = student_record.id 1140 mapping['id'] = student_id 1141 d = {} 1142 #import pdb;pdb.set_trace() 1143 any_change = False 1144 #special treatment for StudentStudyLevel 1145 current_session = d['session'] = mapping.get('current_session','') 1146 if current_session and student_record.session != current_session: 1147 msg = 'student %s: imported session %s does not match current_session %s' % (student_id, 1148 current_session, 1149 student_record.session) 1150 break 1151 current_level = mapping.get('current_level','') 1152 if not current_level.isdigit(): 1153 msg = 'student %s: imported level is empty' % (student_id,) 1154 break 1155 if current_level and student_record.level != current_level: 1156 msg = 'student %s: imported level %s does not match current_level %s' % (student_id, 1157 current_level, 1158 student_record.level) 1159 break 1160 student_review_state = student_record.review_state 1161 if student_review_state == 'deactivated': 1162 msg = "student %s in review_state %s" % (student_id, student_review_state) 1163 break 1164 if student_review_state not in ('courses_validated','returning'): 1165 msg = "student %s in wrong review_state %s" % (student_id, student_review_state) 1166 break 1167 student_obj = getattr(students_folder,student_id) 1168 # f2t = self.field2types_student 1169 study_course_obj = getattr(student_obj,'study_course',None) 1170 if study_course_obj is None: 1171 msg = 'student %s: no study_course object' % student_id 1172 break 1173 level_obj = getattr(study_course_obj,current_level,None) 1174 1175 if level_obj is None: 1176 # The only difference to the edit method is that we create a StudentStudyLevel object 1177 try: 1178 study_course_obj.invokeFactory('StudentStudyLevel',"%s" % current_level) 1179 level_obj = getattr(context,"%s" % current_level) 1180 level_obj.portal_workflow.doActionFor(level,'open') 1181 except: 1182 continue 1183 #msg = 'student %s: no study_level object for level %s' % (student_id, 1184 # current_level) 1185 #break 1186 1187 verdict = d['verdict'] = d['current_verdict'] = mapping.get('current_verdict','') 1188 1189 #if verdict == student_record.verdict: 1190 # msg = 'student %s: verdict already set to %s' % (student_id, 1191 # verdict) 1192 1193 level_review_state = wftool.getInfoFor(level_obj,'review_state',None) 1194 if level_review_state != "closed": 1195 wftool.doActionFor(level_obj,'close') 1196 # msg = 'student %s: level %s is not closed' % (student_id, 1197 # current_level) 1198 1199 study_course_obj.getContent().edit(mapping = d) 1200 level_obj.getContent().edit(mapping = d) 1201 if student_review_state != "returning": 1202 wftool.doActionFor(student_obj,'return') 1203 # try: 1204 # wftool.doActionFor(level_obj,'close') 1205 # except: 1206 # pass 1207 break 1208 return student_id,msg,mapping 1209 ###) 1210 1211 def create_old(self,mapping): ###( 936 1212 "edit student verdicts and create StudentStudyLevel object if not existent" 937 1213 wftool = self.portal_workflow … … 1036 1312 break 1037 1313 return student_id,msg,mapping 1038 1039 1040 def edit(self,mapping): 1314 ###) 1315 1316 def edit(self,mapping): ###( 1041 1317 "edit student verdicts" 1042 1318 wftool = self.portal_workflow … … 1046 1322 matric_no = mapping.get('matric_no',None) 1047 1323 editable_keys = mapping.keys() 1048 while True: 1049 key = '' 1324 key = '' 1325 while True: 1326 result = self.findStudent('edit',student_id=student_id,matric_no=matric_no) 1327 #student_record,msg = self.getStudentRecord(mapping) 1328 msg = result['msg'] 1329 if msg: 1330 break 1331 student_record = result['student_record'] 1332 key_used = result['key_used'] 1333 # if student_id: 1334 # student_record = self.students_catalog.getRecordByKey(student_id) 1335 # if student_record is None: 1336 # #return '',"no student with id %s" % student_id 1337 # msg = "no student with id %s" % student_id 1338 # break 1339 # if matric_no and student_record.matric_no and matric_no != student_record.matric_no: 1340 # msg = 'student %s: matric_no %s does not match %s' % (student_record.id, 1341 # student_record.matric_no, 1342 # matric_no) 1343 # break 1344 # mapping['matric_no'] = student_record.matric_no 1345 # elif matric_no: 1346 # res = self.students_catalog(matric_no = matric_no) 1347 # if not res: 1348 # msg = "no student with matric_no %s" % matric_no 1349 # break 1350 # student_record = res[0] 1351 # editable_keys.remove('matric_no') 1352 # else: 1353 # msg = "no id or matric_no specified" 1354 # break 1355 editable_keys.remove(key_used) 1356 student_id = student_record.id 1357 mapping['id'] = student_id 1358 d = {} 1359 #import pdb;pdb.set_trace() 1360 any_change = False 1361 #special treatment for StudentStudyLevel 1362 current_session = d['session'] = mapping.get('current_session','') 1363 if current_session and student_record.session != current_session: 1364 msg = 'student %s: imported session %s does not match current_session %s' % (student_id, 1365 current_session, 1366 student_record.session) 1367 break 1368 current_level = mapping.get('current_level','') 1369 if not current_level.isdigit(): 1370 msg = 'student %s: imported level is empty' % (student_id,) 1371 break 1372 if current_level and student_record.level != current_level: 1373 msg = 'student %s: imported level %s does not match current_level %s' % (student_id, 1374 current_level, 1375 student_record.level) 1376 break 1377 student_review_state = student_record.review_state 1378 if student_review_state == 'deactivated': 1379 msg = "student %s in review_state %s" % (student_id, student_review_state) 1380 break 1381 if student_review_state not in ('courses_validated','returning'): 1382 msg = "student %s in wrong review_state %s" % (student_id, student_review_state) 1383 break 1384 student_obj = getattr(students_folder,student_id) 1385 # f2t = self.field2types_student 1386 study_course_obj = getattr(student_obj,'study_course',None) 1387 if study_course_obj is None: 1388 msg = 'student %s: no study_course object' % student_id 1389 break 1390 level_obj = getattr(study_course_obj,current_level,None) 1391 if level_obj is None: 1392 msg = 'student %s: no study_level object for level %s' % (student_id, 1393 current_level) 1394 break 1395 verdict = d['verdict'] = d['current_verdict'] = mapping.get('current_verdict','') 1396 1397 #if verdict == student_record.verdict: 1398 # msg = 'student %s: verdict already set to %s' % (student_id, 1399 # verdict) 1400 1401 level_review_state = wftool.getInfoFor(level_obj,'review_state',None) 1402 if level_review_state != "closed": 1403 wftool.doActionFor(level_obj,'close') 1404 # msg = 'student %s: level %s is not closed' % (student_id, 1405 # current_level) 1406 1407 study_course_obj.getContent().edit(mapping = d) 1408 level_obj.getContent().edit(mapping = d) 1409 if student_review_state != "returning": 1410 wftool.doActionFor(student_obj,'return') 1411 # try: 1412 # wftool.doActionFor(level_obj,'close') 1413 # except: 1414 # pass 1415 break 1416 return student_id,msg,mapping 1417 ###) 1418 1419 def edit_old(self,mapping): ###( 1420 "edit student verdicts" 1421 wftool = self.portal_workflow 1422 logger = logging.getLogger('WAeUPTool.mass_edit_verdict') 1423 students_folder = self.portal_url.getPortalObject().campus.students 1424 student_id = mapping.get('id',None) 1425 matric_no = mapping.get('matric_no',None) 1426 editable_keys = mapping.keys() 1427 key = '' 1428 while True: 1050 1429 msg = '' 1051 1430 if student_id: … … 1133 1512 return student_id,msg,mapping 1134 1513 ###) 1135 1514 ###)
Note: See TracChangeset for help on using the changeset viewer.