Changeset 3178
- Timestamp:
- 18 Feb 2008, 16:03:26 (17 years ago)
- Location:
- WAeUP_SRP/base
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPImport.py
r3177 r3178 64 64 self.portal_workflow = getToolByName(waeup_tool, 'portal_workflow') 65 65 self.portal_url = getToolByName(waeup_tool, 'portal_url') 66 self.portal_catalog = waeup_tool.portal_catalog 66 67 self.students_catalog = waeup_tool.students_catalog 67 68 self.courses_catalog = waeup_tool.courses_catalog … … 72 73 if self.import_method is None: 73 74 errors.append('No importer method %s' % mode) 74 self.pending_path = "%s/import/%s _pending.csv" % (i_home,self.plural_name)75 self.pending_tmp = "%s/import/%s _pending.csv.tmp" % (i_home,self.plural_name)76 self.pending_backup = "%s/import/%s _pending.csv.backup" % (i_home,self.plural_name)75 self.pending_path = "%s/import/%s.pending" % (i_home,self.plural_name) 76 self.pending_tmp = "%s/import/%s.pending.tmp" % (i_home,self.plural_name) 77 self.pending_backup = "%s/import/%s.pending.old" % (i_home,self.plural_name) 77 78 self.pending_fn = os.path.split(self.pending_path)[1] 78 self.imported_path = "%s/import/%s _imported.csv" % (i_home,self.plural_name)79 self.imported_path = "%s/import/%s.imported" % (i_home,self.plural_name) 79 80 self.imported_fn = os.path.split(self.imported_path)[1] 80 81 iname = "import_%s" % self.name … … 97 98 info['import_mode'] = mode 98 99 info['error'] = '' 100 info['digest'] = '' 99 101 self.info = info 100 102 self.csv_keys.extend(self.info) … … 119 121 pending_digests += digest, 120 122 pending += item, 123 datafile.close() 121 124 copy2(self.pending_path,self.pending_backup) 122 pending_at_start = len(pending)123 datafile.close()124 125 return pending, pending_digests 125 126 ###) … … 442 443 name = "department" 443 444 plural_name = "%ss" % name 444 commit_after = 1000 00445 commit_after = 1000 445 446 446 447 447 def create(self,mapping):###( 448 448 "create a department in the correct faculty" 449 f id = mapping['faculty_code']449 faculty_id = mapping['faculty_code'] 450 450 msg = '' 451 451 if getattr(self,'_v_faculties',None) is None: 452 res = self.portal_catalog(portal_type = " Faculty")452 res = self.portal_catalog(portal_type = "Department") 453 453 self._v_faculties = {} 454 454 for f in res: 455 455 self._v_faculties[f.getId] = f.getObject() 456 while True: 457 f = self._v_faculties.get(fid,None) 458 if f is None: 459 msg = "No Faculty with ID: %s" % fid 456 department_id = mapping.get('code','') 457 while True: 458 faculty = self._v_faculties.get(faculty_id,None) 459 if faculty is None: 460 msg = "No Faculty with ID: %s" % faculty_id 460 461 break 461 462 else: 462 did = mapping.get('code') 463 d = getattr(f,did,None) 463 d = getattr(faculty,department_id,None) 464 464 if d is None or d.portal_type == "Faculty": 465 #logger.info('Creating Department %(code)s, %(title)s' % mapping)466 465 try: 467 f .invokeFactory('Department', did)466 faculty.invokeFactory('Department', department_id) 468 467 except BadRequest,E: 469 468 msg = "%s" % E 470 469 break 471 d = getattr(f ,did)470 d = getattr(faculty,department_id) 472 471 d.invokeFactory('CoursesFolder','courses') 473 472 courses = getattr(d,'courses') … … 480 479 d.getContent().edit(mapping=mapping) 481 480 break 482 return d id,msg,mapping481 return department_id,msg,mapping 483 482 ###) 484 483 485 484 def edit(self,mapping): ###( 486 " createa department in the correct faculty"485 "edit a department in the correct faculty" 487 486 academics_folder = self.portal_url.getPortalObject().campus.academics 488 f id = mapping['faculty_code']489 d id = mapping.get('code')487 faculty_id = mapping['faculty_code'] 488 department_id = mapping.get('code','') 490 489 msg = '' 491 490 while True: 492 491 try: 493 d = getattr(getattr(academics_folder,f id),did,None)492 d = getattr(getattr(academics_folder,faculty_id),department_id,None) 494 493 except KeyError: 495 msg = "Department %s or Faculty %s wrong" % (d id,fid)496 break 497 else:498 if d is None or d.portal_type == "Faculty":499 #logger.info('Editing Department %(code)s, %(title)s' % mapping)500 501 break 502 return d id,msg,mapping494 msg = "Department %s or Faculty %s wrong" % (department_id,faculty_id) 495 break 496 if d is None or d.portal_type == "Faculty": 497 msg = "Department %s not found" % (department_id) 498 break 499 d.getContent().edit(mapping=mapping) 500 break 501 return department_id,msg,mapping 503 502 ###) 504 503 ###) … … 512 511 "create a faculty" 513 512 academics_folder = self.portal_url.getPortalObject().campus.academics 514 f id = mapping['code']515 msg = '' 516 while True: 517 if getattr(academics_folder,fid,None) is not None:518 msg = "Faculty with ID: %s exists" % f id513 faculty_id = mapping.get('code','') 514 msg = '' 515 while True: 516 if faculty_id in academics_folder.objectIds(): 517 msg = "Faculty with ID: %s exists" % faculty_id 519 518 break 520 519 logger.info('Creating Faculty %(code)s, %(title)s' % mapping) 521 520 try: 522 academics_folder.invokeFactory('Faculty', f id)521 academics_folder.invokeFactory('Faculty', faculty_id) 523 522 except BadRequest,E: 524 523 msg = "%s" % E 525 524 break 526 f = getattr(academics_folder,f id,None)525 f = getattr(academics_folder,faculty_id,None) 527 526 f.getContent().edit(mapping=mapping) 528 527 break 529 return f id,msg,mapping528 return faculty_id,msg,mapping 530 529 ###) 531 530 … … 533 532 "edit a faculty" 534 533 academics_folder = self.portal_url.getPortalObject().campus.academics 535 f id = mapping['code']536 msg = '' 537 while True: 538 f = getattr(academics_folder,f id,None)534 faculty_id = mapping['code'] 535 msg = '' 536 while True: 537 f = getattr(academics_folder,faculty_id,None) 539 538 if f is None: 540 msg = "Faculty with ID: %s does not exist" % f id539 msg = "Faculty with ID: %s does not exist" % faculty_id 541 540 f.getContent().edit(mapping=mapping) 542 541 break 543 return f id,msg,mapping542 return faculty_id,msg,mapping 544 543 ###) 545 544 ###) -
WAeUP_SRP/base/WAeUPTool.py
r3177 r3178 1496 1496 info['error'] = error 1497 1497 mapping.update(info) 1498 log_list = [] 1498 1499 if error: 1499 1500 digest = makeDigest(mapping,data_keys) 1500 1501 with_error_count += 1 1501 percent_finished = (with_error_count + imported_count)/tti_float*1001502 #percent_finished = (with_error_count + imported_count)/tti_float*100 1502 1503 if digest not in pending_digests: 1503 1504 pending_digests += digest, 1504 1505 pending.append(mapping) 1505 1506 if not pending_only: 1506 logger.info("%(percent_finished)6.3f %% done added to %(pending_fn)s %(data_string)s" % vars()) 1507 log_list += "added to %(pending_fn)s %(data_string)s" % vars(), 1508 #logger.info("%(percent_finished)6.3f %% done added to %(pending_fn)s %(data_string)s" % vars()) 1507 1509 else: 1508 1510 already_in += 1 … … 1512 1514 imported_count += 1 1513 1515 imported += mapping, 1516 log_list += "imported and added to %(imported_fn)s %(data_string)s" % vars(), 1517 #percent_finished = (with_error_count + imported_count)/tti_float*100 1518 #logger.info("%(percent_finished)6.3f %% done imported and added to %(imported_fn)s %(data_string)s" % vars()) 1519 if log_list: 1520 time_till_now = time.time() - elapse 1514 1521 percent_finished = (with_error_count + imported_count)/tti_float*100 1515 logger.info("%(percent_finished)6.3f %% done imported and added to %(imported_fn)s %(data_string)s" % vars()) 1522 log_list.insert(0,("%(percent_finished)6.3f %% done in %(time_till_now)3.2f secs" % vars()),) 1523 logger.info(' '.join(log_list)) 1516 1524 finished = count > total_to_import - 1 1517 1525 must_commit = False … … 1557 1565 msg += " total %(total_pending)d; " % vars() 1558 1566 logger.info(msg) 1567 os.remove(pending_tmp) 1559 1568 return msg 1560 1569 ###) -
WAeUP_SRP/base/utils.py
r3172 r3178 26 26 for key in data_keys: 27 27 d[key] = str(item.get(key,'')) 28 return md5.new(str(d)). digest()28 return md5.new(str(d)).hexdigest() 29 29
Note: See TracChangeset for help on using the changeset viewer.