Index: WAeUP_SRP/trunk/Academics.py
===================================================================
--- WAeUP_SRP/trunk/Academics.py	(revision 928)
+++ WAeUP_SRP/trunk/Academics.py	(revision 929)
@@ -360,5 +360,5 @@
             logger.error('Error reading %s.csv' % name)
             return
-        d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})]
+##        d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})]
         c_ids = [c.id for c in self.portal_catalog({'meta_type': "Course"})]
         l = self.portal_catalog({'meta_type': "Certificate"})
@@ -366,13 +366,15 @@
         for f in l:
             ca,ac,fa,depid,co,code = f.relative_path.split('/')
-            pid = "%(depid)s_%(code)s" % vars()
+##            pid = "%(depid)s_%(code)s" % vars()
+            pid = "%(code)s" % vars()
             certs[pid] = f.getObject()
         for cert_course in cert_courses:
             processing = "processing %s" % format
             logger.info(processing % cert_course)
-            depid = cert_course.get('department_code')
+##            depid = cert_course.get('department_code')
             course_code = cert_course.get('code')
             code = cert_course.get('certificate_code')
-            pid = "%(depid)s_%(code)s" % vars()
+##            pid = "%(depid)s_%(code)s" % vars()
+            pid = "%(code)s" % vars()            
             if not pid in certs.keys():
                 em = 'CertCode %(certificate_code)s for %(code)s not found\n' % cert_course
@@ -389,10 +391,10 @@
                 no_import_list.append(format % cert_course + ',"Course"\n')
                 continue
-            if depid not in d_ids:
-                em = 'Department %(department_code)s for %(certificate_code)s not found\n' % cert_course
-                logger.info(em)
-                #no_import_list.append(em)
-                no_import_list.append(format % cert_course + ',"Department"\n')
-                continue
+##            if depid not in d_ids:
+##                em = 'Department %(department_code)s for %(certificate_code)s not found\n' % cert_course
+##                logger.info(em)
+##                #no_import_list.append(em)
+##                no_import_list.append(format % cert_course + ',"Department"\n')
+##                continue
             level = cert_course.get('level')
             l = getattr(certificate,level,None)
@@ -432,42 +434,4 @@
     ###)
 
-    security.declareProtected(ModifyPortalContent,"loadFacultiesFromOrgCSV")###(
-    def loadFacultiesFromOrgCSV(self):
-        """install Universityspecific Faculies from CSV values"""
-        #return
-        name = 'Faculties'
-        no_import = False
-        logger = logging.getLogger('%s_import' % name)
-        logger.info('Start loading from %s.csv' % name)
-        academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject()
-        try:
-            faculties = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
-        except:
-            logger.error('Error reading %s.csv' % name)
-            return
-        l = self.portal_catalog({'meta_type': "Faculty"})
-        facs = {}
-        for f in l:
-            facs[f.id] = f.getObject()
-        for faculty in faculties:
-            logger.info('processing %(Session)s %(FacultyCode)s %(Description)s %(CollegeCode)s %(FacultyKey)s %(Status)s %(degree_grade)s %(Bankcode)s' % faculty)
-            fid = faculty['FacultyCode']
-            f = facs.get(fid,None)
-            if f is None:
-                #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
-                logger.info('Creating Faculty with ID %(FacultyCode)s %(Description)s' % faculty)
-                academics.invokeFactory('Faculty', fid)
-                f = getattr(self,fid)
-                d = {'Title': faculty['Description']}
-            else:
-                d = {}
-            d['bank_code'] = faculty.get("Bankcode")
-            d["degree_grade"] = faculty.get("degree_grade")
-            d['institution_type'] = 'faculty'
-            d['Description'] = ''
-            d['college_code'] = faculty.get('CollegeCode')
-            f.getContent().edit(mapping=d)
-        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
-    ###)
 
     security.declareProtected(ModifyPortalContent,"yamlDumpFaculties")###(
@@ -491,314 +455,4 @@
     ###)
 
-    security.declareProtected(ModifyPortalContent,"loadDepartmentsFromOrgCSV")###(
-    def loadDepartmentsFromOrgCSV(self):
-        """install Universityspecific Faculies from CSV values"""
-        #return
-        name = 'Departments'
-        no_import = False
-        logger = logging.getLogger('loaddepartments')
-        try:
-            deps = csv.DictReader(open("%s/import/departments.csv" % i_home,"rb"))
-        except:
-            logger.error('Error reading departments.csv')
-            return
-        l = self.portal_catalog({'meta_type': "Faculty"})
-        facs = {}
-        for f in l:
-            facs[f.id] = f.getObject()
-        for dep in deps:
-            logger.info('Processing %(Session)s %(DeptCode)s %(Description)s %(FacultyCode)s' % dep)
-            fid = dep['FacultyCode']
-            f = facs.get(fid,None)
-            if f is None:
-                logger.info( "No Faculty with ID: %s" % fid)
-                if not no_import:
-                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
-                    no_import.write('"Session","DeptCode","Description","FacultyCode"\n')
-                no_import.write( "No Faculty with ID: %s\n" % fid)
-                no_import.write('"%(Session)s","%(DeptCode)s","%(Description)s","%(FacultyCode)s"\n' % dep)
-            else:
-                did = dep.get('DeptCode')
-                d = getattr(f,did,None)
-                if d is None or d.portal_type == "Faculty":
-                    logger.info('Creating Department %(DeptCode)s = %(Description)s' % dep)
-                    f.invokeFactory('Department', did)
-                    d = getattr(f,did)
-                    dict = {'Title': dep['Description']}
-                    d.getContent().edit(mapping=dict)
-                    d.invokeFactory('CoursesFolder','courses')
-                    courses = getattr(d,'courses')
-                    dict = {'Title': 'Courses'}
-                    courses.getContent().edit(mapping=dict)
-                    d.invokeFactory('CertificatesFolder','certificates')
-                    certificates = getattr(d,'certificates')
-                    dict = {'Title': 'Certificates'}
-                    certificates.getContent().edit(mapping=dict)
-        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
-    ###)
-
-    security.declareProtected(ModifyPortalContent,"loadCoursesFromOrgCSV")###(
-    def loadCoursesFromOrgCSV(self):
-        """install Universityspecific Courses from CSV values"""
-        #return
-        name = 'Courses'
-        no_import = False
-        logger = logging.getLogger('loadcourses')
-        try:
-            courses = csv.DictReader(open("%s/import/courses.csv" % i_home,"rb"))
-        except:
-            logger.error('Error reading courses.csv')
-            return
-        l = self.portal_catalog({'meta_type': "Faculty"})
-        facs = {}
-        for f in l:
-            facs[f.id] = f.getObject()
-        dl = self.portal_catalog({'meta_type': "Department"})
-        deps = {}
-        for d in dl:
-            deps[d.id] = d.getObject()
-        cl = self.portal_catalog({'meta_type': "Course"})
-        course_list = [ c.id for c in cl]
-        for course in courses:
-            logger.info('Processing %(CourseCode)s %(Description)s %(Credits)s %(Dept)s %(Semester)s %(Session)s %(PassMark)s %(Category)s %(AdmStatus)s' % course)
-##            if course.get("FORMERCODE").endswith('BITS'):
-##                continue
-            depid = course.get('Dept').upper()
-            if depid in deps.keys():
-                dept= deps.get(depid)
-    ##        elif depid in facs.keys():
-    ##            dept= facs.get(depid)
-            else:
-                logger.info("Dep %(Dept)s for Course %(CourseCode)s not found" % course)
-                if not no_import:
-                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
-                    no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n')
-                no_import.write("Dep %(Dept)s for Course %(CourseCode)s not found\n" % course)
-                no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course)
-                continue
-            course_id = ''.join(re.split('\W+',course.get('CourseCode')))
-            if len(course_id) == 3:
-                course_id = "%s000" % course_id
-            elif len(course_id) > 10:
-                logger.info("invalid course_code %(CourseCode)s" % course)
-                if not no_import:
-                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
-                    no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n')
-                no_import.write("invalid course_code %(CourseCode)s\n" % course)
-                no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course)
-                continue
-            courses = dept.courses
-            c = getattr(courses,course_id,None)
-            if c is None:
-                logger.info('Creating Course %(CourseCode)s  %(Description)s in Department %(Dept)s' % course)
-                courses.invokeFactory('Course', course_id)
-                c = getattr(courses,course_id)
-            dict = {'Title': course['Description']}
-            dict['code'] = course_id
-            dict['org_code'] = course.get('CourseCode')
-            dict['credits'] = course.get('Credits')
-            dict['semester'] = course.get('Semester')
-            dict['session'] = course.get('Session')
-            dict['category'] = course.get('Category')
-            dict['adm_status'] = course.get('AdmStatus')
-            dict['former_code'] = course.get('FORMERCODE')
-            pm = course.get('PassMark')
-            if pm.find(',') > -1:
-                pm.replace(',','.')
-            elif pm == "":
-                pm = "0.0"
-            try:
-                dict['passmark'] = int(float(pm))
-            except:
-                dict['passmark'] = 0
-            c.getContent().edit(mapping=dict)
-        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
-    ###)
-
-    security.declareProtected(ModifyPortalContent,"loadCertificatesFromOrgCSV")###(
-
-    def loadCertificatesFromOrgCSV(self):
-        """install Universityspecific Certificates from CSV values"""
-        #return
-        name = 'Certificates'
-        no_import = False
-        logger = logging.getLogger('loadcertificates')
-        try:
-            certificates = csv.DictReader(open("%s/import/certificates.csv" % i_home,"rb"))
-        except:
-            logger.error('Error reading certificates.csv')
-            return
-        f_ids = [f.id for f in self.portal_catalog({'meta_type': "Faculty"})]
-        #d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})]
-        dl = self.portal_catalog({'meta_type': "Department"})
-        deps = {}
-        for d in dl:
-            deps[d.id] = d.getObject()
-        for certificate in certificates:
-            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)
-            depid = certificate.get('Dept')
-            facid = certificate.get('Faculty')
-            if facid not in f_ids:
-                logger.info('Faculty %(Faculty)s for %(CertCode)s %(Description)s not found' % certificate)
-                if not no_import:
-                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
-                    no_import.write('"CertCode","Description","Faculty","MaxPass","MaxLoad","session","PromotionCredits","Probationcredits","StartLevel","endLevel","Nyears","Ncore","MaxElect","MPREFIX","Dept","Admstatus","category"\n')
-                no_import.write('Faculty %(Faculty)s for %(CertCode)s %(Description)s not found\n' % certificate)
-                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)
-                continue
-            if not deps.has_key(depid):
-                logger.info('Department %(Dept)s for %(CertCode)s %(Description)s not found' % certificate)
-                if not no_import:
-                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
-                    no_import.write('"CertCode","Description","Faculty","MaxPass","MaxLoad","session","PromotionCredits","Probationcredits","StartLevel","endLevel","Nyears","Ncore","MaxElect","MPREFIX","Dept","Admstatus","category"\n')
-                no_import.write('Department %(Dept)s for %(CertCode)s %(Description)s not found\n' % certificate)
-                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)
-                continue
-            #certificate_id = "%(category)s_%(Admstatus)s_%(Dept)s" % certificate
-            dep = deps[depid]
-            certificates = dep.certificates
-            code = makeCertificateCode(certificate.get('CertCode'))
-            certificate_id = code
-            c = getattr(certificates,certificate_id,None)
-            if c is None:
-                #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
-                logger.info('Creating certificate %(CertCode)s  %(Description)s in Department %(Dept)s' % certificate)
-                certificates.invokeFactory('Certificate', certificate_id)
-                c = getattr(certificates,certificate_id)
-                dict = {'Title': certificate['Description']}
-                dict['code'] = code
-                dict['faculty'] = certificate.get('Faculty')
-                dict['department'] = certificate.get('Dept')
-                dict['max_pass'] = certificate.get('MaxPass')
-                dict['max_load'] = certificate.get('MaxLoad')
-                dict['admin_status'] = certificate.get('Admstatus')
-                dict['category'] = certificate.get('category')
-                dict['m_prefix'] = certificate.get('MPREFIX')
-                dict['nr_years'] = int(certificate.get('Nyears'))
-                nc = certificate.get('Ncore','1')
-                try:
-                    dict['n_core'] = int(nc)
-                except:
-                    dict['n_core'] = 1
-                dict['start_level'] = certificate.get('StartLevel')
-                dict['end_level'] = certificate.get('endLevel')
-                dict['promotion_credits'] = certificate.get('PromotionCredits')
-                dict['probation_credits'] = certificate.get('ProbationCredits')
-            else:
-                dict = {}
-            dict['original_code'] = certificate.get('CertCode')
-            print
-            c.getContent().edit(mapping=dict)
-        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
-    ###)
-
-    security.declareProtected(ModifyPortalContent,"loadCertificateCoursesFromOrgCSV")###(
-    def loadCertificateCoursesFromOrgCSV(self):
-        """install Certificate Courses from CSV values"""
-        #return
-        logger = logging.getLogger('loadcertificatecourses')
-        name = 'Certificate_courses'
-        no_import = False
-        try:
-            cert_courses = csv.DictReader(open("%s/import/course_level_courses.csv" % i_home,"rb"))
-        except:
-            logger.error('Error reading course_level_courses.csv')
-            return
-        d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})]
-        c_ids = [c.id for c in self.portal_catalog({'meta_type': "Course"})]
-        l = self.portal_catalog({'meta_type': "Certificate"})
-        certs = {}
-        for f in l:
-            certs[f.id] = f.getObject()
-        for cert_course in cert_courses:
-            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)
-            depid = cert_course.get('Dept')
-            course_code = cert_course.get('CosCode')
-            code = cert_course.get('CertCode')
-            code = code.replace('.','')
-            code = code.replace('(','')
-            code = code.replace(')','')
-            code = code.replace('/','')
-            code = code.replace(' ','')
-            code = code.replace('_','')
-##            if cert_course.get('Session') != '2002/2003':
-##                continue
-##            certificate = self.portal_catalog({'meta_type': "Certificate",
-##                                               'SearchableText': code})
-##            if not certificate:
-            if not code in certs.keys():
-                #print code
-                em = 'CertCode %(CertCode)s for %(CosCode)s not found\n' % cert_course
-                logger.info(em)
-                if not no_import:
-                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
-                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
-                no_import.write(em)
-                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)
-                continue
-            certificate = certs[code]
-            certificate_code = certificate.getId()
-            if course_code not in c_ids:
-                em = 'CorseCode %(CosCode)s for %(CertCode)s not found in Courses\n' % cert_course
-                logger.info(em)
-                if not no_import:
-                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
-                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
-                no_import.write(em)
-                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)
-                continue
-            if depid not in d_ids:
-                em = 'Department %(Dept)s for %(CertCode)s not found\n' % cert_course
-                logger.info(em)
-                if not no_import:
-                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
-                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
-                no_import.write(em)
-                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)
-                continue
-            level = cert_course.get('Level')
-            l = getattr(certificate,level,None)
-            if l is None:
-                #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
-                logger.info('Creating Level %(Level)s in certificate %(CertCode)s' % cert_course)
-                certificate.invokeFactory('StudyLevel', level)
-                l = getattr(certificate, level)
-                l.getContent().edit(mapping={'Title': "Level %s" % level})
-                l.invokeFactory('Semester','first')
-                l.invokeFactory('Semester','second')
-            certificate.orderObjects('id')
-            first_s = getattr(l,'first')
-            first_s.getContent().edit(mapping={'Title': 'First Semester'})
-            second_s = getattr(l,'second')
-            second_s.getContent().edit(mapping={'Title': 'Second Semester'})
-            if cert_course.get('Semester') == '1':
-                semester = first_s
-            else:
-                semester = second_s
-            if hasattr(semester,course_code):
-                logger.info('Duplicate %(CosCode)s in Level %(Level)s' % cert_course)
-                if not no_import:
-                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
-                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
-##                no_import.write('Duplicate %(CosCode)s in Level %(Level)s' % cert_course)
-##                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)
-                continue
-            semester.invokeFactory('CertificateCourse',course_code)
-            cc = getattr(semester,course_code)
-            dict = {}
-            dict['code'] = cert_course.get('CosCode')
-            dict['certificate_code'] = code
-            dict['certificate_code_org'] = cert_course.get('CertCode')
-            dict['department'] = cert_course.get('Dept')
-            dict['admin_status'] = cert_course.get('Admstatus')
-            dict['session'] = cert_course.get('Session')
-            if cert_course.get('Core') != '':
-                dict['core_or_elective'] = True
-            else:
-                dict['core_or_elective'] = False
-            dict['level'] = cert_course.get('Level')
-            cc.getContent().edit(mapping=dict)
-        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
-    ###)
 
     def exportLocalRoles(self,portal_type): ###(
