Changeset 929
- Timestamp:
- 23 Nov 2006, 21:09:39 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Academics.py
r928 r929 360 360 logger.error('Error reading %s.csv' % name) 361 361 return 362 d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})]362 ## d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})] 363 363 c_ids = [c.id for c in self.portal_catalog({'meta_type': "Course"})] 364 364 l = self.portal_catalog({'meta_type': "Certificate"}) … … 366 366 for f in l: 367 367 ca,ac,fa,depid,co,code = f.relative_path.split('/') 368 pid = "%(depid)s_%(code)s" % vars() 368 ## pid = "%(depid)s_%(code)s" % vars() 369 pid = "%(code)s" % vars() 369 370 certs[pid] = f.getObject() 370 371 for cert_course in cert_courses: 371 372 processing = "processing %s" % format 372 373 logger.info(processing % cert_course) 373 depid = cert_course.get('department_code')374 ## depid = cert_course.get('department_code') 374 375 course_code = cert_course.get('code') 375 376 code = cert_course.get('certificate_code') 376 pid = "%(depid)s_%(code)s" % vars() 377 ## pid = "%(depid)s_%(code)s" % vars() 378 pid = "%(code)s" % vars() 377 379 if not pid in certs.keys(): 378 380 em = 'CertCode %(certificate_code)s for %(code)s not found\n' % cert_course … … 389 391 no_import_list.append(format % cert_course + ',"Course"\n') 390 392 continue 391 if depid not in d_ids:392 em = 'Department %(department_code)s for %(certificate_code)s not found\n' % cert_course393 logger.info(em)394 #no_import_list.append(em)395 no_import_list.append(format % cert_course + ',"Department"\n')396 continue393 ## if depid not in d_ids: 394 ## em = 'Department %(department_code)s for %(certificate_code)s not found\n' % cert_course 395 ## logger.info(em) 396 ## #no_import_list.append(em) 397 ## no_import_list.append(format % cert_course + ',"Department"\n') 398 ## continue 397 399 level = cert_course.get('level') 398 400 l = getattr(certificate,level,None) … … 432 434 ###) 433 435 434 security.declareProtected(ModifyPortalContent,"loadFacultiesFromOrgCSV")###(435 def loadFacultiesFromOrgCSV(self):436 """install Universityspecific Faculies from CSV values"""437 #return438 name = 'Faculties'439 no_import = False440 logger = logging.getLogger('%s_import' % name)441 logger.info('Start loading from %s.csv' % name)442 academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject()443 try:444 faculties = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))445 except:446 logger.error('Error reading %s.csv' % name)447 return448 l = self.portal_catalog({'meta_type': "Faculty"})449 facs = {}450 for f in l:451 facs[f.id] = f.getObject()452 for faculty in faculties:453 logger.info('processing %(Session)s %(FacultyCode)s %(Description)s %(CollegeCode)s %(FacultyKey)s %(Status)s %(degree_grade)s %(Bankcode)s' % faculty)454 fid = faculty['FacultyCode']455 f = facs.get(fid,None)456 if f is None:457 #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)458 logger.info('Creating Faculty with ID %(FacultyCode)s %(Description)s' % faculty)459 academics.invokeFactory('Faculty', fid)460 f = getattr(self,fid)461 d = {'Title': faculty['Description']}462 else:463 d = {}464 d['bank_code'] = faculty.get("Bankcode")465 d["degree_grade"] = faculty.get("degree_grade")466 d['institution_type'] = 'faculty'467 d['Description'] = ''468 d['college_code'] = faculty.get('CollegeCode')469 f.getContent().edit(mapping=d)470 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))471 ###)472 436 473 437 security.declareProtected(ModifyPortalContent,"yamlDumpFaculties")###( … … 491 455 ###) 492 456 493 security.declareProtected(ModifyPortalContent,"loadDepartmentsFromOrgCSV")###(494 def loadDepartmentsFromOrgCSV(self):495 """install Universityspecific Faculies from CSV values"""496 #return497 name = 'Departments'498 no_import = False499 logger = logging.getLogger('loaddepartments')500 try:501 deps = csv.DictReader(open("%s/import/departments.csv" % i_home,"rb"))502 except:503 logger.error('Error reading departments.csv')504 return505 l = self.portal_catalog({'meta_type': "Faculty"})506 facs = {}507 for f in l:508 facs[f.id] = f.getObject()509 for dep in deps:510 logger.info('Processing %(Session)s %(DeptCode)s %(Description)s %(FacultyCode)s' % dep)511 fid = dep['FacultyCode']512 f = facs.get(fid,None)513 if f is None:514 logger.info( "No Faculty with ID: %s" % fid)515 if not no_import:516 no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")517 no_import.write('"Session","DeptCode","Description","FacultyCode"\n')518 no_import.write( "No Faculty with ID: %s\n" % fid)519 no_import.write('"%(Session)s","%(DeptCode)s","%(Description)s","%(FacultyCode)s"\n' % dep)520 else:521 did = dep.get('DeptCode')522 d = getattr(f,did,None)523 if d is None or d.portal_type == "Faculty":524 logger.info('Creating Department %(DeptCode)s = %(Description)s' % dep)525 f.invokeFactory('Department', did)526 d = getattr(f,did)527 dict = {'Title': dep['Description']}528 d.getContent().edit(mapping=dict)529 d.invokeFactory('CoursesFolder','courses')530 courses = getattr(d,'courses')531 dict = {'Title': 'Courses'}532 courses.getContent().edit(mapping=dict)533 d.invokeFactory('CertificatesFolder','certificates')534 certificates = getattr(d,'certificates')535 dict = {'Title': 'Certificates'}536 certificates.getContent().edit(mapping=dict)537 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))538 ###)539 540 security.declareProtected(ModifyPortalContent,"loadCoursesFromOrgCSV")###(541 def loadCoursesFromOrgCSV(self):542 """install Universityspecific Courses from CSV values"""543 #return544 name = 'Courses'545 no_import = False546 logger = logging.getLogger('loadcourses')547 try:548 courses = csv.DictReader(open("%s/import/courses.csv" % i_home,"rb"))549 except:550 logger.error('Error reading courses.csv')551 return552 l = self.portal_catalog({'meta_type': "Faculty"})553 facs = {}554 for f in l:555 facs[f.id] = f.getObject()556 dl = self.portal_catalog({'meta_type': "Department"})557 deps = {}558 for d in dl:559 deps[d.id] = d.getObject()560 cl = self.portal_catalog({'meta_type': "Course"})561 course_list = [ c.id for c in cl]562 for course in courses:563 logger.info('Processing %(CourseCode)s %(Description)s %(Credits)s %(Dept)s %(Semester)s %(Session)s %(PassMark)s %(Category)s %(AdmStatus)s' % course)564 ## if course.get("FORMERCODE").endswith('BITS'):565 ## continue566 depid = course.get('Dept').upper()567 if depid in deps.keys():568 dept= deps.get(depid)569 ## elif depid in facs.keys():570 ## dept= facs.get(depid)571 else:572 logger.info("Dep %(Dept)s for Course %(CourseCode)s not found" % course)573 if not no_import:574 no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")575 no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n')576 no_import.write("Dep %(Dept)s for Course %(CourseCode)s not found\n" % course)577 no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course)578 continue579 course_id = ''.join(re.split('\W+',course.get('CourseCode')))580 if len(course_id) == 3:581 course_id = "%s000" % course_id582 elif len(course_id) > 10:583 logger.info("invalid course_code %(CourseCode)s" % course)584 if not no_import:585 no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")586 no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n')587 no_import.write("invalid course_code %(CourseCode)s\n" % course)588 no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course)589 continue590 courses = dept.courses591 c = getattr(courses,course_id,None)592 if c is None:593 logger.info('Creating Course %(CourseCode)s %(Description)s in Department %(Dept)s' % course)594 courses.invokeFactory('Course', course_id)595 c = getattr(courses,course_id)596 dict = {'Title': course['Description']}597 dict['code'] = course_id598 dict['org_code'] = course.get('CourseCode')599 dict['credits'] = course.get('Credits')600 dict['semester'] = course.get('Semester')601 dict['session'] = course.get('Session')602 dict['category'] = course.get('Category')603 dict['adm_status'] = course.get('AdmStatus')604 dict['former_code'] = course.get('FORMERCODE')605 pm = course.get('PassMark')606 if pm.find(',') > -1:607 pm.replace(',','.')608 elif pm == "":609 pm = "0.0"610 try:611 dict['passmark'] = int(float(pm))612 except:613 dict['passmark'] = 0614 c.getContent().edit(mapping=dict)615 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))616 ###)617 618 security.declareProtected(ModifyPortalContent,"loadCertificatesFromOrgCSV")###(619 620 def loadCertificatesFromOrgCSV(self):621 """install Universityspecific Certificates from CSV values"""622 #return623 name = 'Certificates'624 no_import = False625 logger = logging.getLogger('loadcertificates')626 try:627 certificates = csv.DictReader(open("%s/import/certificates.csv" % i_home,"rb"))628 except:629 logger.error('Error reading certificates.csv')630 return631 f_ids = [f.id for f in self.portal_catalog({'meta_type': "Faculty"})]632 #d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})]633 dl = self.portal_catalog({'meta_type': "Department"})634 deps = {}635 for d in dl:636 deps[d.id] = d.getObject()637 for certificate in certificates:638 logger.info('Processing %(CertCode)s %(Description)s %(Faculty)s %(MaxPass)s %(MaxLoad)s %(session)s %(PromotionCredits)s %(Probationcredits)s %(StartLevel)s %(endLevel)s %(Nyears)s %(Ncore)s %(MaxElect)s %(MPREFIX)s %(Dept)s %(Admstatus)s %(category)s' % certificate)639 depid = certificate.get('Dept')640 facid = certificate.get('Faculty')641 if facid not in f_ids:642 logger.info('Faculty %(Faculty)s for %(CertCode)s %(Description)s not found' % certificate)643 if not no_import:644 no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")645 no_import.write('"CertCode","Description","Faculty","MaxPass","MaxLoad","session","PromotionCredits","Probationcredits","StartLevel","endLevel","Nyears","Ncore","MaxElect","MPREFIX","Dept","Admstatus","category"\n')646 no_import.write('Faculty %(Faculty)s for %(CertCode)s %(Description)s not found\n' % certificate)647 no_import.write('"%(CertCode)s","%(Description)s","%(Faculty)s","%(MaxPass)s","%(MaxLoad)s","%(session)s","%(PromotionCredits)s","%(Probationcredits)s","%(StartLevel)s","%(endLevel)s","%(Nyears)s","%(Ncore)s","%(MaxElect)s","%(MPREFIX)s","%(Dept)s","%(Admstatus)s","%(category)s"\n' % certificate)648 continue649 if not deps.has_key(depid):650 logger.info('Department %(Dept)s for %(CertCode)s %(Description)s not found' % certificate)651 if not no_import:652 no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")653 no_import.write('"CertCode","Description","Faculty","MaxPass","MaxLoad","session","PromotionCredits","Probationcredits","StartLevel","endLevel","Nyears","Ncore","MaxElect","MPREFIX","Dept","Admstatus","category"\n')654 no_import.write('Department %(Dept)s for %(CertCode)s %(Description)s not found\n' % certificate)655 no_import.write('"%(CertCode)s","%(Description)s","%(Faculty)s","%(MaxPass)s","%(MaxLoad)s","%(session)s","%(PromotionCredits)s","%(Probationcredits)s","%(StartLevel)s","%(endLevel)s","%(Nyears)s","%(Ncore)s","%(MaxElect)s","%(MPREFIX)s","%(Dept)s","%(Admstatus)s","%(category)s"\n' % certificate)656 continue657 #certificate_id = "%(category)s_%(Admstatus)s_%(Dept)s" % certificate658 dep = deps[depid]659 certificates = dep.certificates660 code = makeCertificateCode(certificate.get('CertCode'))661 certificate_id = code662 c = getattr(certificates,certificate_id,None)663 if c is None:664 #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)665 logger.info('Creating certificate %(CertCode)s %(Description)s in Department %(Dept)s' % certificate)666 certificates.invokeFactory('Certificate', certificate_id)667 c = getattr(certificates,certificate_id)668 dict = {'Title': certificate['Description']}669 dict['code'] = code670 dict['faculty'] = certificate.get('Faculty')671 dict['department'] = certificate.get('Dept')672 dict['max_pass'] = certificate.get('MaxPass')673 dict['max_load'] = certificate.get('MaxLoad')674 dict['admin_status'] = certificate.get('Admstatus')675 dict['category'] = certificate.get('category')676 dict['m_prefix'] = certificate.get('MPREFIX')677 dict['nr_years'] = int(certificate.get('Nyears'))678 nc = certificate.get('Ncore','1')679 try:680 dict['n_core'] = int(nc)681 except:682 dict['n_core'] = 1683 dict['start_level'] = certificate.get('StartLevel')684 dict['end_level'] = certificate.get('endLevel')685 dict['promotion_credits'] = certificate.get('PromotionCredits')686 dict['probation_credits'] = certificate.get('ProbationCredits')687 else:688 dict = {}689 dict['original_code'] = certificate.get('CertCode')690 print691 c.getContent().edit(mapping=dict)692 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))693 ###)694 695 security.declareProtected(ModifyPortalContent,"loadCertificateCoursesFromOrgCSV")###(696 def loadCertificateCoursesFromOrgCSV(self):697 """install Certificate Courses from CSV values"""698 #return699 logger = logging.getLogger('loadcertificatecourses')700 name = 'Certificate_courses'701 no_import = False702 try:703 cert_courses = csv.DictReader(open("%s/import/course_level_courses.csv" % i_home,"rb"))704 except:705 logger.error('Error reading course_level_courses.csv')706 return707 d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})]708 c_ids = [c.id for c in self.portal_catalog({'meta_type': "Course"})]709 l = self.portal_catalog({'meta_type': "Certificate"})710 certs = {}711 for f in l:712 certs[f.id] = f.getObject()713 for cert_course in cert_courses:714 logger.info('Processing %(CosCode)s %(CertCode)s %(Session)s %(Level)s %(Core)s %(Elective)s %(Mandatory)s %(AdmStatus)s %(Dept)s %(Semester)s' % cert_course)715 depid = cert_course.get('Dept')716 course_code = cert_course.get('CosCode')717 code = cert_course.get('CertCode')718 code = code.replace('.','')719 code = code.replace('(','')720 code = code.replace(')','')721 code = code.replace('/','')722 code = code.replace(' ','')723 code = code.replace('_','')724 ## if cert_course.get('Session') != '2002/2003':725 ## continue726 ## certificate = self.portal_catalog({'meta_type': "Certificate",727 ## 'SearchableText': code})728 ## if not certificate:729 if not code in certs.keys():730 #print code731 em = 'CertCode %(CertCode)s for %(CosCode)s not found\n' % cert_course732 logger.info(em)733 if not no_import:734 no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")735 no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')736 no_import.write(em)737 no_import.write('"%(CosCode)s","%(CertCode)s","%(Session)s","%(Level)s","%(Core)s","%(Elective)s","%(Mandatory)s","%(AdmStatus)s","%(Dept)s","%(Semester)s"\n' % cert_course)738 continue739 certificate = certs[code]740 certificate_code = certificate.getId()741 if course_code not in c_ids:742 em = 'CorseCode %(CosCode)s for %(CertCode)s not found in Courses\n' % cert_course743 logger.info(em)744 if not no_import:745 no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")746 no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')747 no_import.write(em)748 no_import.write('"%(CosCode)s","%(CertCode)s","%(Session)s","%(Level)s","%(Core)s","%(Elective)s","%(Mandatory)s","%(AdmStatus)s","%(Dept)s","%(Semester)s"\n' % cert_course)749 continue750 if depid not in d_ids:751 em = 'Department %(Dept)s for %(CertCode)s not found\n' % cert_course752 logger.info(em)753 if not no_import:754 no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")755 no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')756 no_import.write(em)757 no_import.write('"%(CosCode)s","%(CertCode)s","%(Session)s","%(Level)s","%(Core)s","%(Elective)s","%(Mandatory)s","%(AdmStatus)s","%(Dept)s","%(Semester)s"\n' % cert_course)758 continue759 level = cert_course.get('Level')760 l = getattr(certificate,level,None)761 if l is None:762 #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)763 logger.info('Creating Level %(Level)s in certificate %(CertCode)s' % cert_course)764 certificate.invokeFactory('StudyLevel', level)765 l = getattr(certificate, level)766 l.getContent().edit(mapping={'Title': "Level %s" % level})767 l.invokeFactory('Semester','first')768 l.invokeFactory('Semester','second')769 certificate.orderObjects('id')770 first_s = getattr(l,'first')771 first_s.getContent().edit(mapping={'Title': 'First Semester'})772 second_s = getattr(l,'second')773 second_s.getContent().edit(mapping={'Title': 'Second Semester'})774 if cert_course.get('Semester') == '1':775 semester = first_s776 else:777 semester = second_s778 if hasattr(semester,course_code):779 logger.info('Duplicate %(CosCode)s in Level %(Level)s' % cert_course)780 if not no_import:781 no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")782 no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')783 ## no_import.write('Duplicate %(CosCode)s in Level %(Level)s' % cert_course)784 ## no_import.write('"%(CosCode)s","%(CertCode)s","%(Session)s","%(Level)s","%(Core)s","%(Elective)s","%(Mandatory)s","%(AdmStatus)s","%(Dept)s","%(Semester)s"\n' % cert_course)785 continue786 semester.invokeFactory('CertificateCourse',course_code)787 cc = getattr(semester,course_code)788 dict = {}789 dict['code'] = cert_course.get('CosCode')790 dict['certificate_code'] = code791 dict['certificate_code_org'] = cert_course.get('CertCode')792 dict['department'] = cert_course.get('Dept')793 dict['admin_status'] = cert_course.get('Admstatus')794 dict['session'] = cert_course.get('Session')795 if cert_course.get('Core') != '':796 dict['core_or_elective'] = True797 else:798 dict['core_or_elective'] = False799 dict['level'] = cert_course.get('Level')800 cc.getContent().edit(mapping=dict)801 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))802 ###)803 457 804 458 def exportLocalRoles(self,portal_type): ###(
Note: See TracChangeset for help on using the changeset viewer.