Changeset 1700 for WAeUP_SRP/trunk/WAeUPTables.py
- Timestamp:
- 23 Apr 2007, 21:16:34 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/WAeUPTables.py
r1625 r1700 25 25 from AccessControl import ClassSecurityInfo 26 26 from Products.CMFCore.permissions import ModifyPortalContent 27 27 import urllib 28 28 import DateTime,time 29 29 import csv,re … … 77 77 78 78 def deleteRecord(self, uid): 79 #import pdb;pdb.set_trace()80 79 self.uncatalog_object(uid) 81 80 … … 230 229 name = "students_catalog" 231 230 key = "id" 232 interesting_types = ('Student', 233 'StudentApplication', 234 'StudentCLearance', 235 'StudentPersonal', 236 'StudentStudyCourse', 237 ) 231 affected_types = { ###( 232 'StudentApplication': 233 ('jamb_reg_no', 234 'entry_mode', 235 'entry_session', 236 ), 237 'StudentClearance': 238 ('matric_no', 239 ), 240 'StudentPersonal': 241 ('name', 242 'sex', 243 'email', 244 'phone', 245 ), 246 'StudentStudyCourse': 247 ('course', 248 'faculty', 249 'department', 250 'level', 251 'study_mode', 252 'session', 253 'verdict', 254 ), 255 } 256 ###) 238 257 239 258 def __init__(self): … … 241 260 return 242 261 243 def get_review_state(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): ###( 244 "return the students review_state from portal_catalog" 245 cat_res = self.portal_catalog(id = sid) 246 if len(cat_res) != 1: 247 return None 248 return cat_res[0].review_state 249 250 def get_course(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 251 "return the students study_course" 252 if study_course_doc is None: 253 return None 254 return getattr(study_course_doc,'study_course',None) 255 256 def get_department(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 257 "return the students department" 258 if study_course_doc is None: 259 return None 260 certificate_res = self.portal_catalog(id = study_course_doc.study_course) 261 if len(certificate_res) != 1: 262 return None 263 return certificate_res[0].getPath().split('/')[-3] 264 265 def get_email(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 266 "return the students email from the personal" 267 if personal_doc is None: 268 return None 269 return getattr(personal_doc,'email',None) 270 271 def get_entry_mode(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 272 "return the students entry_mode from the application" 273 if application_doc is None: 274 return None 275 return getattr(application_doc,'entry_mode',None) 276 277 def get_jamb_reg_no(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 278 "return the students jamb_reg_no from the application" 279 if application_doc is None: 280 return None 281 return getattr(application_doc,'jamb_reg_no',None) 282 283 def get_faculty(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 284 "return the students faculty" 285 if study_course_doc is None: 286 return None 287 certificate_res = self.portal_catalog(id = study_course_doc.study_course) 288 if len(certificate_res) != 1: 289 return None 290 return certificate_res[0].getPath().split('/')[-4] 291 292 def get_level(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 293 "return the students study_course" 294 if study_course_doc is None: 295 return None 296 #from pdb import set_trace;set_trace() 297 return getattr(study_course_doc,'current_level',None) 298 299 def get_matric_no(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 300 "return the students matric_no from the clearance " 301 if clearance_doc is None: 302 return None 303 return getattr(clearance_doc,'matric_no',None) 304 305 def get_name(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 306 "return the students name from the personal" 307 if personal_doc is None: 308 return None 309 doc = personal_doc 310 return "%s %s %s" % (doc.firstname,doc.middlename,doc.lastname) 311 312 def get_phone(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 313 "return the students phone from the personal" 314 if personal_doc is None: 315 return None 316 return getattr(personal_doc,'phone',None) 317 318 def get_sex(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 319 "return the students sex from the personal" 320 if personal_doc is None: 321 return None 322 return getattr(personal_doc,'sex',None) 323 324 def get_verdict(self,sid,application_doc,clearance_doc,personal_doc,study_course_doc): 325 "return the students study_course" 326 if study_course_doc is None: 327 return None 328 return getattr(study_course_doc,'current_verdict',None) 329 ###) 330 331 def refreshCatalog(self, clear=0, pghandler=None): ###( 332 """ re-index everything we can find """ 333 students_folder = self.portal_url.getPortalObject().campus.students 334 335 cat = self._catalog 336 paths = self._catalog.uids.items() 337 if clear: 338 paths = tuple(paths) 339 cat.clear() 340 341 num_objects = len(paths) 342 if pghandler: 343 pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) 344 for i in xrange(num_objects): 345 if pghandler: pghandler.report(i) 346 p = paths[i] 347 sid = p[0] 348 pcat_res = self.portal_catalog(id=sid) 349 if len(pcat_res) != 1: 350 continue 351 student_brain = pcat_res[0] 352 student_obj = student_brain.getObject() 353 if student_obj.hasObject('application'): 354 application_doc = getattr(student_obj,'application').getContent() 355 else: 356 application_doc = None 357 if student_obj.hasObject('clearance'): 358 clearance_doc = getattr(student_obj,'clearance').getContent() 359 else: 360 clearance_doc = None 361 if student_obj.hasObject('personal'): 362 personal_doc = getattr(student_obj,'personal').getContent() 363 else: 364 personal_doc = None 365 if student_obj.hasObject('study_course'): 366 study_course_doc = getattr(student_obj,'study_course').getContent() 367 else: 368 study_course_doc = None 369 data = {} 370 data['id'] = sid 371 for field in self.schema(): 372 function = getattr(self,"get_%s" % field, None) 373 if function is None: 374 continue 375 value = function(sid,application_doc,clearance_doc,personal_doc,study_course_doc) 376 if value is not None: 377 data[field] = value 378 self.modifyRecord(**data) 379 if pghandler: pghandler.finish() 380 ###) 381 382 def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): 262 def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None): 263 """ clears the whole enchilada """ 264 self._catalog.clear() 265 266 if REQUEST and RESPONSE: 267 RESPONSE.redirect( 268 URL1 + 269 '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Cleared') 270 271 def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): ###( 383 272 """ clear the catalog, then re-index everything """ 384 273 … … 388 277 pgthreshold = self._getProgressThreshold() 389 278 handler = (pgthreshold > 0) and ZLogHandler(pgthreshold) or None 390 self.refreshCatalog(clear= 0, pghandler=handler)279 self.refreshCatalog(clear=1, pghandler=handler) 391 280 392 281 elapse = time.time() - elapse … … 399 288 'Total time: %s\n' 400 289 'Total CPU time: %s' % (`elapse`, `c_elapse`))) 401 402 403 security.declarePrivate('notify_event_listener') 290 ###) 291 292 def get_from_doc_department(self,doc): ###( 293 "return the students department" 294 if doc is None: 295 return None 296 certificate_res = self.portal_catalog(id = doc.study_course) 297 if len(certificate_res) != 1: 298 return None 299 return certificate_res[0].getPath().split('/')[-3] 300 301 def get_from_doc_faculty(self,doc): 302 "return the students faculty" 303 if doc is None: 304 return None 305 certificate_res = self.portal_catalog(id = doc.study_course) 306 if len(certificate_res) != 1: 307 return None 308 return certificate_res[0].getPath().split('/')[-4] 309 310 def get_from_doc_level(self,doc): 311 "return the students level" 312 if doc is None: 313 return None 314 return getattr(doc,'current_level',None) 315 316 def get_from_doc_study_mode(self,doc): 317 "return the students study_mode" 318 if doc is None: 319 return None 320 return getattr(doc,'current_study_mode',None) 321 322 def get_from_doc_entry_session(self,doc): 323 "return the students entry_session" 324 if doc is None: 325 return None 326 try: 327 digit = int(doc.jamb_reg_no[0]) 328 except: 329 return "xx" 330 if digit < 8: 331 return "0%c" % doc.jamb_reg_no[0] 332 return "9%c" % doc.jamb_reg_no[0] 333 334 def get_from_doc_session(self,doc): 335 "return the students session" 336 if doc is None: 337 return None 338 return getattr(doc,'current_session',None) 339 340 def get_from_doc_course(self,doc): 341 "return the students study_course" 342 if doc is None: 343 return None 344 return getattr(doc,'study_course',None) 345 346 def get_from_doc_name(self,doc): 347 "return the students name from the personal" 348 if doc is None: 349 return None 350 return "%s %s %s" % (doc.firstname,doc.middlename,doc.lastname) 351 352 def get_from_doc_verdict(self,doc): 353 "return the students study_course" 354 if doc is None: 355 return None 356 return getattr(doc,'current_verdict',None) 357 358 ###) 359 360 def refreshCatalog(self, clear=0, pghandler=None): ###( 361 """ re-index everything we can find """ 362 students_folder = self.portal_url.getPortalObject().campus.students 363 364 cat = self._catalog 365 paths = self._catalog.uids.items() 366 if clear: 367 paths = tuple(paths) 368 cat.clear() 369 students = self.portal_catalog(portal_type="Student") 370 num_objects = len(students) 371 if pghandler: 372 pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) 373 for i in xrange(num_objects): 374 if pghandler: pghandler.report(i) 375 student_brain = students[i] 376 spath = student_brain.getPath() 377 student_obj = student_brain.getObject() 378 data = {} 379 sid = data['id'] = student_brain.getId 380 data['review_state'] = student_brain.review_state 381 sub_brains = self.portal_catalog(path = spath) 382 if len(sub_brains) > 1: 383 for sub_brain in sub_brains: 384 if not sub_brain.portal_type in self.affected_types.keys(): 385 continue 386 doc = sub_brain.getObject().getContent() 387 for field in self.affected_types[sub_brain.portal_type]: 388 if hasattr(self,'get_from_doc_%s' % field): 389 data[field] = getattr(self,'get_from_doc_%s' % field)(doc) 390 else: 391 data[field] = getattr(doc,field) 392 elif len(sub_brains) == 1: 393 #import pdb;pdb.set_trace() 394 import_res = self.returning_import(id = sid) 395 if not import_res: 396 continue 397 import_record = import_res[0] 398 data['matric_no'] = import_record.matric_no 399 data['sex'] = import_record.Sex == 'F' 400 data['name'] = "%s %s %s" % (import_record.Firstname, 401 import_record.Middlename, 402 import_record.Lastname) 403 data['matric_no'] = import_record.Entryregno 404 study_course = getattr(student_obj,'study_course',None) 405 current_level = data.get('level',None) 406 data['registered_courses'] = [] 407 if study_course and current_level and current_level in study_course.objectIds(): 408 level_obj = getattr(study_course,current_level) 409 courses = [] 410 for c in level_obj.objectIds(): 411 if c.endswith('_co'): 412 courses.append(c[:-3]) 413 else: 414 courses.append(c) 415 data['registered_courses'] = courses 416 self.addRecord(**data) 417 if pghandler: pghandler.finish() 418 ###) 419 420 421 security.declarePrivate('notify_event_listener') ###( 404 422 def notify_event_listener(self,event_type,object,infos): 405 423 "listen for events" … … 407 425 mt = object.meta_type 408 426 students_catalog = self.students_catalog 409 #if pt not in self.interesting_types: 410 # return 411 #print "%(pt)s\n %(event_type)s \n %(infos)s\n" % vars() 427 if pt not in self.affected_types.keys(): 428 return 412 429 if not infos.has_key('rpath'): 413 430 return 414 if pt == 'Student' and event_type == "workflow": 415 pass 416 elif mt == 'StudentApplication': 417 if event_type not in ('sys_modify_object'): 418 return 419 print "%(pt)s\n %(event_type)s \n %(infos)s\n" % vars() 431 rpl = infos['rpath'].split('/') 432 if pt == 'Student' and event_type == "sys_add_object": 433 student_id = object.id 434 try: 435 self.addRecord(id = student_id) 436 except ValueError: 437 pass 438 return 439 elif pt == 'CourseResult' and mt == 'CPS Proxy Folder': 420 440 from pdb import set_trace;set_trace() 421 jamb_reg_no = getattr(object,'jamb_reg_no',None) 422 if jamb_reg_no is None: 423 return 424 student_id = infos['rpath'].split('/')[2] 425 self.fixName(student_id) 426 student_entry = students_catalog(id = student_id)[0] 427 if student_entry.jamb_reg_no == jamb_reg_no: 428 return 429 students_catalog.modifyRecord(id = student_id, 430 jamb_reg_no = jamb_reg_no) 431 elif mt == 'StudentPersonal': 432 if event_type not in ('sys_modify_object'): 433 return 434 print "%(pt)s\n %(event_type)s \n %(infos)s\n" % vars() 435 student_id = infos['rpath'].split('/')[2] 436 self.fixName(student_id) 441 442 if event_type not in ('sys_modify_object'): 443 return 444 data = {} 445 if mt == 'CPS Proxy Folder': 446 return 447 #from pdb import set_trace;set_trace() 448 for field in self.affected_types[pt]: 449 if hasattr(self,'get_from_doc_%s' % field): 450 data[field] = getattr(self,'get_from_doc_%s' % field)(object) 451 else: 452 data[field] = getattr(object,field) 453 data['id'] = rpl[2] 454 students_catalog.modifyRecord(**data) 455 ###) 437 456 438 457
Note: See TracChangeset for help on using the changeset viewer.