Changeset 2078
- Timestamp:
- 30 Jul 2007, 14:10:40 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/WAeUPTables.py
r2069 r2078 313 313 ###) 314 314 315 def get_from_doc_department(self,doc): ###( 315 def fill_certificates_dict(self): 316 "return certificate data in dict" 317 certificates_brains = self.portal_catalog(portal_type ='Certificate') 318 d = {} 319 for cb in certificates_brains: 320 certificate_doc = cb.getObject().getContent() 321 cb_path = cb.getPath().split('/') 322 ld = {} 323 ld['faculty'] = cb_path[-4] 324 ld['department'] = cb_path[-3] 325 ld['end_level'] = getattr(certificate_doc,'end_level','999') 326 d[cb.getId] = ld 327 return d 328 329 def get_from_doc_department(self,doc,cached_data={}): ###( 316 330 "return the students department" 317 331 if doc is None: 318 332 return None 333 if cached_data.has_key(doc.study_course): 334 return cached_data[doc.study_course]['department'] 319 335 certificate_res = self.portal_catalog(id = doc.study_course) 320 336 if len(certificate_res) != 1: … … 322 338 return certificate_res[0].getPath().split('/')[-3] 323 339 324 def get_from_doc_faculty(self,doc ):340 def get_from_doc_faculty(self,doc,cached_data={}): 325 341 "return the students faculty" 326 342 if doc is None: 327 343 return None 344 if cached_data.has_key(doc.study_course): 345 return cached_data[doc.study_course]['faculty'] 328 346 certificate_res = self.portal_catalog(id = doc.study_course) 329 347 if len(certificate_res) != 1: … … 331 349 return certificate_res[0].getPath().split('/')[-4] 332 350 333 def get_from_doc_end_level(self,doc ): ###(351 def get_from_doc_end_level(self,doc,cached_data={}): 334 352 "return the students end_level" 335 353 if doc is None: 336 354 return None 355 if cached_data.has_key(doc.study_course): 356 return cached_data[doc.study_course]['end_level'] 337 357 certificate_res = self.portal_catalog(id = doc.study_course) 338 358 if len(certificate_res) != 1: … … 340 360 return getattr(certificate_res[0].getObject().getContent(),'end_level','unknown') 341 361 342 def get_from_doc_level(self,doc ):362 def get_from_doc_level(self,doc,cached_data={}): 343 363 "return the students level" 344 364 if doc is None: … … 346 366 return getattr(doc,'current_level',None) 347 367 348 def get_from_doc_mode(self,doc ):368 def get_from_doc_mode(self,doc,cached_data={}): 349 369 "return the students mode" 350 370 if doc is None: … … 354 374 355 375 356 def get_from_doc_session(self,doc ):376 def get_from_doc_session(self,doc,cached_data={}): 357 377 "return the students current_session" 358 378 if doc is None: … … 360 380 return getattr(doc,'current_session',None) 361 381 362 def get_from_doc_entry_session(self,doc ):382 def get_from_doc_entry_session(self,doc,cached_data={}): 363 383 "return the students entry_session" 364 384 if doc is None: … … 375 395 return "9%c" % doc.jamb_reg_no[0] 376 396 377 def get_from_doc_course(self,doc ):397 def get_from_doc_course(self,doc,cached_data={}): 378 398 "return the students study_course" 379 399 if doc is None: … … 381 401 return getattr(doc,'study_course',None) 382 402 383 def get_from_doc_name(self,doc ):403 def get_from_doc_name(self,doc,cached_data={}): 384 404 "return the students name from the personal" 385 405 if doc is None: … … 387 407 return "%s %s %s" % (doc.firstname,doc.middlename,doc.lastname) 388 408 389 def get_from_doc_verdict(self,doc ):409 def get_from_doc_verdict(self,doc,cached_data={}): 390 410 "return the students study_course" 391 411 if doc is None: … … 410 430 reindextypes[pt]= [n] 411 431 break 432 cached_data = {} 433 if set(name).intersection(set(('faculty','department','end_level'))): 434 cached_data = self.fill_certificates_dict() 412 435 students = self.portal_catalog(portal_type="Student") 413 436 if hasattr(self,'portal_catalog_real'): … … 439 462 for field in self.affected_types[pt]['fields']: 440 463 if hasattr(self,'get_from_doc_%s' % field): 441 data[field] = getattr(self,'get_from_doc_%s' % field)(doc) 464 data[field] = getattr(self,'get_from_doc_%s' % field)(doc, 465 cached_data=cached_data) 442 466 else: 443 467 data[field] = getattr(doc,field) … … 483 507 students = self.portal_catalog(portal_type="Student") 484 508 num_objects = len(students) 509 cached_data = self.fill_certificates_dict() 485 510 if pghandler: 486 511 pghandler.init('Refreshing catalog: %s' % self.absolute_url(1), num_objects) … … 504 529 for field in self.affected_types[pt]['fields']: 505 530 if hasattr(self,'get_from_doc_%s' % field): 506 data[field] = getattr(self,'get_from_doc_%s' % field)(doc) 531 data[field] = getattr(self,'get_from_doc_%s' % field)(doc, 532 cached_data=cached_data) 507 533 else: 508 534 data[field] = getattr(doc,field,None)
Note: See TracChangeset for help on using the changeset viewer.