[68] | 1 | #-*- mode: python; mode: fold -*- |
---|
| 2 | from Globals import InitializeClass |
---|
| 3 | from AccessControl import ClassSecurityInfo |
---|
| 4 | |
---|
| 5 | from Products.CMFCore.utils import UniqueObject, getToolByName |
---|
| 6 | from Products.CMFCore.permissions import View |
---|
| 7 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
[319] | 8 | from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder |
---|
| 9 | #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument |
---|
| 10 | from Products.CPSDocument.CPSDocument import CPSDocument |
---|
| 11 | #from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder |
---|
| 12 | #from Products.CPSCore.CPSBase import CPSBaseBTreeDocument as BaseBTreeDocument |
---|
[200] | 13 | #from Products.CMFCore.DirectoryView import registerDirectory |
---|
[68] | 14 | |
---|
[200] | 15 | #registerDirectory('skins', globals()) |
---|
| 16 | #registerDirectory('skins/waeup_default', globals()) |
---|
| 17 | #registerDirectory('skins/waeup_faculty', globals()) |
---|
[68] | 18 | |
---|
[279] | 19 | import csv,re |
---|
| 20 | import logging |
---|
| 21 | import Globals |
---|
| 22 | p_home = Globals.package_home(globals()) |
---|
| 23 | i_home = Globals.INSTANCE_HOME |
---|
| 24 | |
---|
[361] | 25 | def makeCertificateCode(code): |
---|
| 26 | code = code.replace('.','') |
---|
| 27 | code = code.replace('(','') |
---|
| 28 | code = code.replace(')','') |
---|
| 29 | code = code.replace('/','') |
---|
| 30 | code = code.replace(' ','') |
---|
| 31 | code = code.replace('_','') |
---|
| 32 | return code |
---|
| 33 | |
---|
[278] | 34 | class AcademicsFolder(CPSDocument): ###( |
---|
| 35 | """ |
---|
[319] | 36 | WAeUP AcademicsFolder containing StudyCourses |
---|
[278] | 37 | """ |
---|
| 38 | meta_type = 'AcademicsFolder' |
---|
| 39 | portal_type = meta_type |
---|
| 40 | security = ClassSecurityInfo() |
---|
[440] | 41 | use_catalog_for_folder_contents = True |
---|
[278] | 42 | |
---|
[364] | 43 | security.declareProtected(View,"Title") |
---|
| 44 | def Title(self): |
---|
| 45 | """compose title""" |
---|
[382] | 46 | return "Academic Section" |
---|
[256] | 47 | |
---|
[351] | 48 | security.declareProtected(ModifyPortalContent,"loadFacultiesFromCSV")###( |
---|
[319] | 49 | def loadFacultiesFromCSV(self): |
---|
[278] | 50 | """install Universityspecific Faculies from CSV values""" |
---|
| 51 | #return |
---|
[282] | 52 | name = 'faculty' |
---|
| 53 | no_import = False |
---|
| 54 | logger = logging.getLogger('%s_import' % name) |
---|
| 55 | logger.info('Start loading from %s.csv' % name) |
---|
[278] | 56 | academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject() |
---|
| 57 | try: |
---|
[282] | 58 | faculties = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
[278] | 59 | except: |
---|
[282] | 60 | logger.error('Error reading %s.csv' % name) |
---|
[278] | 61 | return |
---|
| 62 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
| 63 | facs = {} |
---|
| 64 | for f in l: |
---|
| 65 | facs[f.id] = f.getObject() |
---|
| 66 | for faculty in faculties: |
---|
| 67 | logger.info('processing %(Session)s %(FacultyCode)s %(Description)s %(CollegeCode)s %(FacultyKey)s %(Status)s %(degree_grade)s %(Bankcode)s' % faculty) |
---|
| 68 | fid = faculty['FacultyCode'] |
---|
| 69 | f = facs.get(fid,None) |
---|
| 70 | if f is None: |
---|
| 71 | #self.log('Creating Faculty %(id)s = %(Title)s' % faculty) |
---|
| 72 | logger.info('Creating Faculty with ID %(FacultyCode)s %(Description)s' % faculty) |
---|
| 73 | academics.invokeFactory('Faculty', fid) |
---|
| 74 | f = getattr(self,fid) |
---|
[282] | 75 | d = {'Title': faculty['Description']} |
---|
| 76 | else: |
---|
[369] | 77 | d = {} |
---|
| 78 | ## if not no_import: |
---|
| 79 | ## no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
| 80 | ## no_import.write('"Session","FacultyCode","Description","CollegeCode","FacultyKey","Status","degree_grade","Bankcode"\n') |
---|
| 81 | ## logger.info('Faculty with ID %(FacultyCode)s %(Description)s already exists' % faculty) |
---|
| 82 | ## no_import.write('"%(Session)s","%(FacultyCode)s","%(Description)s","%(CollegeCode)s","%(FacultyKey)s","%(Status)s","%(degree_grade)s","%(Bankcode)s"\n' % faculty) |
---|
| 83 | d['bank_code'] = faculty.get("Bankcode") |
---|
| 84 | d["degree_grade"] = faculty.get("degree_grade") |
---|
[371] | 85 | d['institution_type'] = 'faculty' |
---|
[379] | 86 | d['Description'] = '' |
---|
| 87 | d['college_code'] = faculty.get('CollegeCode') |
---|
[369] | 88 | f.getContent().edit(mapping=d) |
---|
[296] | 89 | return self.academics.academics_contents() |
---|
[278] | 90 | ###) |
---|
| 91 | |
---|
| 92 | security.declareProtected(ModifyPortalContent,"yamlDumpFaculties")###( |
---|
[319] | 93 | def yamlDumpFaculties(self): |
---|
[278] | 94 | """dump Faculies to Yaml""" |
---|
| 95 | #return |
---|
| 96 | import yaml |
---|
| 97 | logger = logging.getLogger('dumpfaculties') |
---|
| 98 | logger.info('Start dumping Faculties') |
---|
| 99 | academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject() |
---|
| 100 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
| 101 | facs = {} |
---|
| 102 | for f in l: |
---|
| 103 | facs[f.id] = f.getObject() |
---|
| 104 | for fid in facs.keys(): |
---|
| 105 | faculty = facs.get(fid).aq_self |
---|
| 106 | logger.info('dumping %s %s ' % (faculty.id, faculty.title)) |
---|
| 107 | print yaml.dump(faculty) |
---|
[290] | 108 | return self.academics.temporary_view_all() |
---|
| 109 | return self.temporary_view_all() |
---|
[319] | 110 | |
---|
[278] | 111 | ###) |
---|
| 112 | |
---|
| 113 | security.declareProtected(ModifyPortalContent,"loadDepartmentsFromCSV")###( |
---|
| 114 | def loadDepartmentsFromCSV(self): |
---|
| 115 | """install Universityspecific Faculies from CSV values""" |
---|
| 116 | #return |
---|
[282] | 117 | name = 'departments' |
---|
| 118 | no_import = False |
---|
[278] | 119 | logger = logging.getLogger('loaddepartments') |
---|
| 120 | try: |
---|
| 121 | deps = csv.DictReader(open("%s/import/departments.csv" % i_home,"rb")) |
---|
| 122 | except: |
---|
[280] | 123 | logger.error('Error reading departments.csv') |
---|
[278] | 124 | return |
---|
| 125 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
| 126 | facs = {} |
---|
| 127 | for f in l: |
---|
| 128 | facs[f.id] = f.getObject() |
---|
| 129 | for dep in deps: |
---|
| 130 | logger.info('Processing %(Session)s %(DeptCode)s %(Description)s %(FacultyCode)s' % dep) |
---|
| 131 | fid = dep['FacultyCode'] |
---|
| 132 | f = facs.get(fid,None) |
---|
| 133 | if f is None: |
---|
| 134 | logger.info( "No Faculty with ID: %s" % fid) |
---|
[282] | 135 | if not no_import: |
---|
| 136 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
[287] | 137 | no_import.write('"Session","DeptCode","Description","FacultyCode"\n') |
---|
| 138 | no_import.write( "No Faculty with ID: %s\n" % fid) |
---|
[282] | 139 | no_import.write('"%(Session)s","%(DeptCode)s","%(Description)s","%(FacultyCode)s"\n' % dep) |
---|
[278] | 140 | else: |
---|
| 141 | did = dep.get('DeptCode') |
---|
| 142 | d = getattr(f,did,None) |
---|
| 143 | if d is None or d.portal_type == "Faculty": |
---|
| 144 | logger.info('Creating Department %(DeptCode)s = %(Description)s' % dep) |
---|
| 145 | f.invokeFactory('Department', did) |
---|
| 146 | d = getattr(f,did) |
---|
[295] | 147 | dict = {'Title': dep['Description']} |
---|
| 148 | d.getContent().edit(mapping=dict) |
---|
[319] | 149 | d.invokeFactory('CoursesFolder','courses') |
---|
[324] | 150 | courses = getattr(d,'courses') |
---|
[295] | 151 | dict = {'Title': 'Courses'} |
---|
| 152 | courses.getContent().edit(mapping=dict) |
---|
[319] | 153 | d.invokeFactory('CertificatesFolder','certificates') |
---|
[321] | 154 | certificates = getattr(d,'certificates') |
---|
[295] | 155 | dict = {'Title': 'Certificates'} |
---|
| 156 | certificates.getContent().edit(mapping=dict) |
---|
[296] | 157 | return self.academics.academics_contents() |
---|
[278] | 158 | ###) |
---|
[319] | 159 | |
---|
[278] | 160 | security.declareProtected(ModifyPortalContent,"loadCoursesFromCSV")###( |
---|
| 161 | def loadCoursesFromCSV(self): |
---|
| 162 | """install Universityspecific Courses from CSV values""" |
---|
| 163 | #return |
---|
[282] | 164 | name = 'courses' |
---|
| 165 | no_import = False |
---|
[278] | 166 | logger = logging.getLogger('loadcourses') |
---|
| 167 | try: |
---|
| 168 | courses = csv.DictReader(open("%s/import/courses.csv" % i_home,"rb")) |
---|
| 169 | except: |
---|
[280] | 170 | logger.error('Error reading courses.csv') |
---|
[278] | 171 | return |
---|
| 172 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
| 173 | facs = {} |
---|
| 174 | for f in l: |
---|
| 175 | facs[f.id] = f.getObject() |
---|
| 176 | dl = self.portal_catalog({'meta_type': "Department"}) |
---|
| 177 | deps = {} |
---|
| 178 | for d in dl: |
---|
| 179 | deps[d.id] = d.getObject() |
---|
| 180 | cl = self.portal_catalog({'meta_type': "Course"}) |
---|
| 181 | course_list = [ c.id for c in cl] |
---|
| 182 | for course in courses: |
---|
[296] | 183 | logger.info('Processing %(CourseCode)s %(Description)s %(Credits)s %(Dept)s %(Semester)s %(Session)s %(PassMark)s %(Category)s %(AdmStatus)s' % course) |
---|
[282] | 184 | ## if course.get("FORMERCODE").endswith('BITS'): |
---|
| 185 | ## continue |
---|
[278] | 186 | depid = course.get('Dept').upper() |
---|
| 187 | if depid in deps.keys(): |
---|
| 188 | dept= deps.get(depid) |
---|
| 189 | ## elif depid in facs.keys(): |
---|
| 190 | ## dept= facs.get(depid) |
---|
| 191 | else: |
---|
| 192 | logger.info("Dep %(Dept)s for Course %(CourseCode)s not found" % course) |
---|
[282] | 193 | if not no_import: |
---|
| 194 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
[296] | 195 | no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n') |
---|
[287] | 196 | no_import.write("Dep %(Dept)s for Course %(CourseCode)s not found\n" % course) |
---|
[296] | 197 | no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course) |
---|
[278] | 198 | continue |
---|
| 199 | course_id = ''.join(re.split('\W+',course.get('CourseCode'))) |
---|
| 200 | if len(course_id) == 3: |
---|
| 201 | course_id = "%s000" % course_id |
---|
[296] | 202 | elif len(course_id) > 10: |
---|
[278] | 203 | logger.info("invalid course_code %(CourseCode)s" % course) |
---|
[282] | 204 | if not no_import: |
---|
| 205 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
[296] | 206 | no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n') |
---|
[287] | 207 | no_import.write("invalid course_code %(CourseCode)s\n" % course) |
---|
[296] | 208 | no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course) |
---|
[278] | 209 | continue |
---|
[323] | 210 | courses = dept.courses |
---|
[295] | 211 | c = getattr(courses,course_id,None) |
---|
[278] | 212 | if c is None: |
---|
| 213 | logger.info('Creating Course %(CourseCode)s %(Description)s in Department %(Dept)s' % course) |
---|
[295] | 214 | courses.invokeFactory('Course', course_id) |
---|
| 215 | c = getattr(courses,course_id) |
---|
[278] | 216 | dict = {'Title': course['Description']} |
---|
| 217 | dict['code'] = course_id |
---|
[319] | 218 | dict['org_code'] = course.get('CourseCode') |
---|
[282] | 219 | dict['credits'] = course.get('Credits') |
---|
[278] | 220 | dict['semester'] = course.get('Semester') |
---|
| 221 | dict['session'] = course.get('Session') |
---|
| 222 | dict['category'] = course.get('Category') |
---|
[379] | 223 | dict['adm_status'] = course.get('AdmStatus') |
---|
| 224 | dict['former_code'] = course.get('FORMERCODE') |
---|
[282] | 225 | pm = course.get('PassMark') |
---|
| 226 | if pm.find(',') > -1: |
---|
| 227 | pm.replace(',','.') |
---|
| 228 | elif pm == "": |
---|
| 229 | pm = "0.0" |
---|
| 230 | try: |
---|
| 231 | dict['passmark'] = int(float(pm)) |
---|
| 232 | except: |
---|
| 233 | dict['passmark'] = 0 |
---|
[278] | 234 | c.getContent().edit(mapping=dict) |
---|
[296] | 235 | return self.academics.academics_contents() |
---|
[278] | 236 | ###) |
---|
| 237 | |
---|
| 238 | security.declareProtected(ModifyPortalContent,"loadCertificatesFromCSV")###( |
---|
[290] | 239 | |
---|
[278] | 240 | def loadCertificatesFromCSV(self): |
---|
| 241 | """install Universityspecific Certificates from CSV values""" |
---|
| 242 | #return |
---|
[287] | 243 | name = 'certificates' |
---|
| 244 | no_import = False |
---|
[278] | 245 | logger = logging.getLogger('loadcertificates') |
---|
| 246 | try: |
---|
| 247 | certificates = csv.DictReader(open("%s/import/certificates.csv" % i_home,"rb")) |
---|
| 248 | except: |
---|
[280] | 249 | logger.error('Error reading certificates.csv') |
---|
[278] | 250 | return |
---|
| 251 | f_ids = [f.id for f in self.portal_catalog({'meta_type': "Faculty"})] |
---|
| 252 | #d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})] |
---|
| 253 | dl = self.portal_catalog({'meta_type': "Department"}) |
---|
| 254 | deps = {} |
---|
| 255 | for d in dl: |
---|
| 256 | deps[d.id] = d.getObject() |
---|
| 257 | for certificate in certificates: |
---|
| 258 | 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) |
---|
| 259 | depid = certificate.get('Dept') |
---|
| 260 | facid = certificate.get('Faculty') |
---|
| 261 | if facid not in f_ids: |
---|
| 262 | logger.info('Faculty %(Faculty)s for %(CertCode)s %(Description)s not found' % certificate) |
---|
[287] | 263 | if not no_import: |
---|
| 264 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
| 265 | no_import.write('"CertCode","Description","Faculty","MaxPass","MaxLoad","session","PromotionCredits","Probationcredits","StartLevel","endLevel","Nyears","Ncore","MaxElect","MPREFIX","Dept","Admstatus","category"\n') |
---|
| 266 | no_import.write('Faculty %(Faculty)s for %(CertCode)s %(Description)s not found\n' % certificate) |
---|
| 267 | 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) |
---|
[278] | 268 | continue |
---|
| 269 | if not deps.has_key(depid): |
---|
| 270 | logger.info('Department %(Dept)s for %(CertCode)s %(Description)s not found' % certificate) |
---|
[287] | 271 | if not no_import: |
---|
| 272 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
| 273 | no_import.write('"CertCode","Description","Faculty","MaxPass","MaxLoad","session","PromotionCredits","Probationcredits","StartLevel","endLevel","Nyears","Ncore","MaxElect","MPREFIX","Dept","Admstatus","category"\n') |
---|
| 274 | no_import.write('Department %(Dept)s for %(CertCode)s %(Description)s not found\n' % certificate) |
---|
| 275 | 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) |
---|
[278] | 276 | continue |
---|
[296] | 277 | #certificate_id = "%(category)s_%(Admstatus)s_%(Dept)s" % certificate |
---|
[278] | 278 | dep = deps[depid] |
---|
[323] | 279 | certificates = dep.certificates |
---|
[361] | 280 | code = makeCertificateCode(certificate.get('CertCode')) |
---|
[296] | 281 | certificate_id = code |
---|
[295] | 282 | c = getattr(certificates,certificate_id,None) |
---|
[278] | 283 | if c is None: |
---|
| 284 | #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) |
---|
| 285 | logger.info('Creating certificate %(CertCode)s %(Description)s in Department %(Dept)s' % certificate) |
---|
[295] | 286 | certificates.invokeFactory('Certificate', certificate_id) |
---|
| 287 | c = getattr(certificates,certificate_id) |
---|
[370] | 288 | dict = {'Title': certificate['Description']} |
---|
| 289 | dict['code'] = code |
---|
| 290 | dict['faculty'] = certificate.get('Faculty') |
---|
| 291 | dict['department'] = certificate.get('Dept') |
---|
| 292 | dict['max_pass'] = certificate.get('MaxPass') |
---|
| 293 | dict['max_load'] = certificate.get('MaxLoad') |
---|
| 294 | dict['admin_status'] = certificate.get('Admstatus') |
---|
| 295 | dict['category'] = certificate.get('category') |
---|
| 296 | dict['m_prefix'] = certificate.get('MPREFIX') |
---|
| 297 | dict['nr_years'] = int(certificate.get('Nyears')) |
---|
| 298 | nc = certificate.get('Ncore','1') |
---|
| 299 | try: |
---|
| 300 | dict['n_core'] = int(nc) |
---|
| 301 | except: |
---|
| 302 | dict['n_core'] = 1 |
---|
| 303 | dict['start_level'] = certificate.get('StartLevel') |
---|
| 304 | dict['end_level'] = certificate.get('endLevel') |
---|
| 305 | dict['promotion_credits'] = certificate.get('PromotionCredits') |
---|
| 306 | dict['probation_credits'] = certificate.get('ProbationCredits') |
---|
| 307 | else: |
---|
| 308 | dict = {} |
---|
| 309 | dict['original_code'] = certificate.get('CertCode') |
---|
[382] | 310 | print |
---|
[278] | 311 | c.getContent().edit(mapping=dict) |
---|
[296] | 312 | return self.academics.academics_contents() |
---|
[278] | 313 | ###) |
---|
| 314 | |
---|
| 315 | security.declareProtected(ModifyPortalContent,"loadCertificateCoursesFromCSV")###( |
---|
| 316 | def loadCertificateCoursesFromCSV(self): |
---|
| 317 | """install Certificate Courses from CSV values""" |
---|
| 318 | #return |
---|
| 319 | logger = logging.getLogger('loadcertificatecourses') |
---|
[290] | 320 | name = 'certificate_courses' |
---|
| 321 | no_import = False |
---|
[278] | 322 | try: |
---|
| 323 | cert_courses = csv.DictReader(open("%s/import/course_level_courses.csv" % i_home,"rb")) |
---|
| 324 | except: |
---|
[280] | 325 | logger.error('Error reading course_level_courses.csv') |
---|
[278] | 326 | return |
---|
| 327 | d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})] |
---|
[290] | 328 | c_ids = [c.id for c in self.portal_catalog({'meta_type': "Course"})] |
---|
[296] | 329 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 330 | certs = {} |
---|
| 331 | for f in l: |
---|
| 332 | certs[f.id] = f.getObject() |
---|
[278] | 333 | for cert_course in cert_courses: |
---|
[296] | 334 | 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) |
---|
[278] | 335 | depid = cert_course.get('Dept') |
---|
[290] | 336 | course_code = cert_course.get('CosCode') |
---|
[278] | 337 | code = cert_course.get('CertCode') |
---|
| 338 | code = code.replace('.','') |
---|
| 339 | code = code.replace('(','') |
---|
| 340 | code = code.replace(')','') |
---|
| 341 | code = code.replace('/','') |
---|
| 342 | code = code.replace(' ','') |
---|
| 343 | code = code.replace('_','') |
---|
[290] | 344 | ## if cert_course.get('Session') != '2002/2003': |
---|
| 345 | ## continue |
---|
[296] | 346 | ## certificate = self.portal_catalog({'meta_type': "Certificate", |
---|
| 347 | ## 'SearchableText': code}) |
---|
| 348 | ## if not certificate: |
---|
| 349 | if not code in certs.keys(): |
---|
[290] | 350 | #print code |
---|
| 351 | em = 'CertCode %(CertCode)s for %(CosCode)s not found\n' % cert_course |
---|
| 352 | logger.info(em) |
---|
| 353 | if not no_import: |
---|
| 354 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
[296] | 355 | no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n') |
---|
[290] | 356 | no_import.write(em) |
---|
[296] | 357 | 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) |
---|
[278] | 358 | continue |
---|
[309] | 359 | certificate = certs[code] |
---|
[278] | 360 | certificate_code = certificate.getId() |
---|
[290] | 361 | if course_code not in c_ids: |
---|
| 362 | em = 'CorseCode %(CosCode)s for %(CertCode)s not found in Courses\n' % cert_course |
---|
| 363 | logger.info(em) |
---|
| 364 | if not no_import: |
---|
| 365 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
[296] | 366 | no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n') |
---|
[290] | 367 | no_import.write(em) |
---|
[296] | 368 | 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) |
---|
[290] | 369 | continue |
---|
[278] | 370 | if depid not in d_ids: |
---|
[290] | 371 | em = 'Department %(Dept)s for %(CertCode)s not found\n' % cert_course |
---|
| 372 | logger.info(em) |
---|
| 373 | if not no_import: |
---|
| 374 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
[296] | 375 | no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n') |
---|
[290] | 376 | no_import.write(em) |
---|
[296] | 377 | 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) |
---|
[278] | 378 | continue |
---|
| 379 | level = cert_course.get('Level') |
---|
| 380 | l = getattr(certificate,level,None) |
---|
| 381 | if l is None: |
---|
| 382 | #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep) |
---|
| 383 | logger.info('Creating Level %(Level)s in certificate %(CertCode)s' % cert_course) |
---|
| 384 | certificate.invokeFactory('StudyLevel', level) |
---|
| 385 | l = getattr(certificate, level) |
---|
[329] | 386 | l.getContent().edit(mapping={'Title': "Level %s" % level}) |
---|
[278] | 387 | l.invokeFactory('Semester','first') |
---|
| 388 | l.invokeFactory('Semester','second') |
---|
[290] | 389 | certificate.orderObjects('id') |
---|
[278] | 390 | first_s = getattr(l,'first') |
---|
[332] | 391 | first_s.getContent().edit(mapping={'Title': 'First Semester'}) |
---|
[278] | 392 | second_s = getattr(l,'second') |
---|
[332] | 393 | second_s.getContent().edit(mapping={'Title': 'Second Semester'}) |
---|
[278] | 394 | if cert_course.get('Semester') == '1': |
---|
| 395 | semester = first_s |
---|
| 396 | else: |
---|
| 397 | semester = second_s |
---|
| 398 | if hasattr(semester,course_code): |
---|
| 399 | logger.info('Duplicate %(CosCode)s in Level %(Level)s' % cert_course) |
---|
[290] | 400 | if not no_import: |
---|
| 401 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
[296] | 402 | no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n') |
---|
[295] | 403 | ## no_import.write('Duplicate %(CosCode)s in Level %(Level)s' % cert_course) |
---|
[296] | 404 | ## 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) |
---|
[278] | 405 | continue |
---|
| 406 | semester.invokeFactory('CertificateCourse',course_code) |
---|
| 407 | cc = getattr(semester,course_code) |
---|
| 408 | dict = {} |
---|
| 409 | dict['code'] = cert_course.get('CosCode') |
---|
| 410 | dict['certificate_code'] = code |
---|
[319] | 411 | dict['certificate_code_org'] = cert_course.get('CertCode') |
---|
| 412 | dict['department'] = cert_course.get('Dept') |
---|
[278] | 413 | dict['admin_status'] = cert_course.get('Admstatus') |
---|
| 414 | dict['session'] = cert_course.get('Session') |
---|
| 415 | if cert_course.get('Core') != '': |
---|
| 416 | dict['core_or_elective'] = True |
---|
| 417 | else: |
---|
| 418 | dict['core_or_elective'] = False |
---|
| 419 | dict['level'] = cert_course.get('Level') |
---|
[295] | 420 | cc.getContent().edit(mapping=dict) |
---|
[296] | 421 | return self.academics.academics_contents() |
---|
[278] | 422 | ###) |
---|
| 423 | |
---|
| 424 | InitializeClass(AcademicsFolder) |
---|
| 425 | |
---|
| 426 | def addAcademicsFolder(container, id, REQUEST=None, **kw): |
---|
| 427 | """Add a AcademicsFolder.""" |
---|
| 428 | ob = AcademicsFolder(id, **kw) |
---|
| 429 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 430 | |
---|
| 431 | ###) |
---|
| 432 | |
---|
[256] | 433 | class Certificate(CPSDocument): ###( |
---|
[238] | 434 | """ |
---|
[319] | 435 | WAeUP Certificate |
---|
[238] | 436 | """ |
---|
[256] | 437 | meta_type = 'Certificate' |
---|
[238] | 438 | portal_type = meta_type |
---|
| 439 | security = ClassSecurityInfo() |
---|
[319] | 440 | |
---|
[238] | 441 | def __init__(self, id, **kw): |
---|
| 442 | CPSDocument.__init__(self, id, **kw) |
---|
| 443 | |
---|
[256] | 444 | ## security.declareProtected(View,"Title") |
---|
| 445 | ## def Title(self): |
---|
| 446 | ## """compose title""" |
---|
| 447 | ## return "Certificate of %s" % (self.title) |
---|
[238] | 448 | |
---|
[256] | 449 | InitializeClass(Certificate) |
---|
[238] | 450 | |
---|
[256] | 451 | def addCertificate(container, id, REQUEST=None, **kw): |
---|
| 452 | """Add a Certificate.""" |
---|
| 453 | ob = Certificate(id, **kw) |
---|
[238] | 454 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 455 | |
---|
| 456 | ###) |
---|
| 457 | |
---|
[454] | 458 | class StudyLevel(CPSDocument): ###( |
---|
| 459 | """ |
---|
| 460 | WAeUP StudyLevel containing the courses and students |
---|
| 461 | """ |
---|
| 462 | meta_type = 'StudyLevel' |
---|
| 463 | portal_type = meta_type |
---|
| 464 | security = ClassSecurityInfo() |
---|
| 465 | |
---|
| 466 | security.declareProtected(View,"Title") |
---|
| 467 | def Title(self): |
---|
| 468 | """compose title""" |
---|
[458] | 469 | try: |
---|
| 470 | return "Level %s" % self.aq_parent.getId() |
---|
| 471 | except: |
---|
| 472 | return "no Title for %s" % self.getId() |
---|
[454] | 473 | |
---|
| 474 | |
---|
| 475 | InitializeClass(StudyLevel) |
---|
| 476 | |
---|
| 477 | def addStudyLevel(container, id, REQUEST=None, **kw): |
---|
| 478 | """Add a StudyLevel.""" |
---|
| 479 | ob = StudyLevel(id, **kw) |
---|
| 480 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 481 | |
---|
| 482 | ###) |
---|
| 483 | |
---|
[256] | 484 | class CertificateCourse(CPSDocument): ###( |
---|
[238] | 485 | """ |
---|
[319] | 486 | WAeUP CertificateCourse |
---|
[238] | 487 | """ |
---|
[256] | 488 | meta_type = 'CertificateCourse' |
---|
[238] | 489 | portal_type = meta_type |
---|
| 490 | security = ClassSecurityInfo() |
---|
[319] | 491 | |
---|
[279] | 492 | def getCourseEntry(self,cid): |
---|
| 493 | res = self.portal_catalog({'meta_type': "Course", |
---|
| 494 | 'id': cid}) |
---|
| 495 | if res: |
---|
[319] | 496 | return res[-1] |
---|
[279] | 497 | else: |
---|
| 498 | return None |
---|
[319] | 499 | |
---|
[256] | 500 | security.declareProtected(View,"Title") |
---|
| 501 | def Title(self): |
---|
| 502 | """compose title""" |
---|
[368] | 503 | ce = self.getCourseEntry(self.id.upper()) |
---|
[454] | 504 | #print self.id, self.aq_parent.id |
---|
[279] | 505 | if ce: |
---|
| 506 | return "%s" % ce.Title |
---|
| 507 | return "No such course" |
---|
[238] | 508 | |
---|
[279] | 509 | security.declareProtected(View,"credits") |
---|
| 510 | def credits(self): |
---|
| 511 | """credits from course""" |
---|
| 512 | ce = self.getCourseEntry(self.id) |
---|
| 513 | if ce: |
---|
| 514 | return "%s" % ce.credits |
---|
[280] | 515 | return "0" |
---|
[319] | 516 | |
---|
[279] | 517 | security.declareProtected(View,"passmark") |
---|
| 518 | def passmark(self): |
---|
| 519 | """passmark from course""" |
---|
| 520 | ce = self.getCourseEntry(self.id) |
---|
[296] | 521 | if ce is not None and hasattr(ce,"passmark"): |
---|
| 522 | return ce.passmark |
---|
[319] | 523 | |
---|
| 524 | |
---|
[280] | 525 | security.declareProtected(View,"coursepath") |
---|
| 526 | def coursepath(self): |
---|
| 527 | """coursepath from course""" |
---|
| 528 | ce = self.getCourseEntry(self.id) |
---|
| 529 | if ce: |
---|
| 530 | return ce.getPath() |
---|
| 531 | return "?" |
---|
[279] | 532 | |
---|
[319] | 533 | |
---|
[256] | 534 | InitializeClass(CertificateCourse) |
---|
[238] | 535 | |
---|
[256] | 536 | def addCertificateCourse(container, id, REQUEST=None, **kw): |
---|
| 537 | """Add a CertificateCourse.""" |
---|
| 538 | ob = CertificateCourse(id, **kw) |
---|
[238] | 539 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 540 | ###) |
---|
| 541 | |
---|
[68] | 542 | class Faculty(CPSDocument): ###( |
---|
| 543 | """ |
---|
[319] | 544 | WAeUP Faculty containing Departments |
---|
[68] | 545 | """ |
---|
| 546 | meta_type = 'Faculty' |
---|
| 547 | portal_type = meta_type |
---|
| 548 | security = ClassSecurityInfo() |
---|
[319] | 549 | |
---|
[238] | 550 | ## def __init__(self, id, **kw): |
---|
| 551 | ## CPSDocument.__init__(self, id, **kw) |
---|
[173] | 552 | |
---|
[200] | 553 | security.declareProtected(View,"Title") |
---|
| 554 | def Title(self): |
---|
| 555 | """compose title""" |
---|
[238] | 556 | return "%s" % (self.title) |
---|
[319] | 557 | |
---|
[389] | 558 | |
---|
[296] | 559 | security.declareProtected(View,"LongTitle") |
---|
| 560 | def LongTitle(self): |
---|
| 561 | """compose long_title""" |
---|
[389] | 562 | prefix = getattr(self,'title_prefix',None) |
---|
| 563 | if prefix is None: |
---|
| 564 | prefix = getattr(self,'institution_type','faculty') |
---|
| 565 | self.getContent().edit(mapping = {'title_prefix': prefix}) |
---|
| 566 | itype = self.portal_vocabularies.institution_types_voc.get(prefix,default="Faculty of") |
---|
[296] | 567 | return "%s %s" % (itype,self.title) |
---|
[200] | 568 | |
---|
[68] | 569 | InitializeClass(Faculty) |
---|
| 570 | |
---|
| 571 | def addFaculty(container, id, REQUEST=None, **kw): |
---|
| 572 | """Add a Faculty.""" |
---|
| 573 | ob = Faculty(id, **kw) |
---|
| 574 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 575 | |
---|
| 576 | ###) |
---|
| 577 | |
---|
| 578 | class Department(CPSDocument): ###( |
---|
| 579 | """ |
---|
| 580 | WAeUP Department containing the courses and students |
---|
| 581 | """ |
---|
| 582 | meta_type = 'Department' |
---|
| 583 | portal_type = meta_type |
---|
| 584 | security = ClassSecurityInfo() |
---|
[173] | 585 | |
---|
[296] | 586 | security.declareProtected(View,"LongTitle") |
---|
| 587 | def LongTitle(self): |
---|
| 588 | """compose long_title""" |
---|
[389] | 589 | prefix = getattr(self,'title_prefix',None) |
---|
| 590 | if prefix is None: |
---|
| 591 | prefix = getattr(self,'institution_type','department') |
---|
| 592 | self.getContent().edit(mapping = {'title_prefix': prefix}) |
---|
| 593 | itype = self.portal_vocabularies.institution_types_voc.get(prefix,default="Department of") |
---|
[296] | 594 | return "%s %s" % (itype,self.title) |
---|
| 595 | |
---|
[68] | 596 | InitializeClass(Department) |
---|
| 597 | |
---|
| 598 | def addDepartment(container, id, REQUEST=None, **kw): |
---|
| 599 | """Add a Department.""" |
---|
[296] | 600 | object = Department(id, **kw) |
---|
[295] | 601 | id = object.getId() |
---|
[319] | 602 | container._setObject(id, object) |
---|
[309] | 603 | ## dep = getattr(container,id).getEditableContent() #getContent() |
---|
| 604 | ## dep.invokeFactory('CoursesFolder','Courses') |
---|
| 605 | ## o = getattr(dep,'Courses') |
---|
| 606 | ## dict = {'Title': 'Courses'} |
---|
| 607 | ## o.getContent().edit(mapping=dict) |
---|
| 608 | ## dep.invokeFactory('CertificatesFolder','Certificates') |
---|
| 609 | ## o = getattr(dep,'Certificates') |
---|
| 610 | ## dict = {'Title': 'Certificates'} |
---|
| 611 | ## o.geetContent().edit(mapping=dict) |
---|
[295] | 612 | if REQUEST is not None: |
---|
| 613 | url = container.absolute_url() |
---|
| 614 | REQUEST.RESPONSE.redirect('%s/manage_main' % url) |
---|
[309] | 615 | |
---|
[68] | 616 | ###) |
---|
| 617 | |
---|
| 618 | class Course(CPSDocument): ###( |
---|
| 619 | """ |
---|
[319] | 620 | WAeUP Course |
---|
[68] | 621 | """ |
---|
| 622 | meta_type = 'Course' |
---|
| 623 | portal_type = meta_type |
---|
| 624 | security = ClassSecurityInfo() |
---|
[152] | 625 | |
---|
| 626 | security.declareProtected(View,"Title") |
---|
| 627 | def Title(self): |
---|
| 628 | """compose title""" |
---|
[238] | 629 | return self.title |
---|
[319] | 630 | |
---|
[68] | 631 | InitializeClass(Course) |
---|
| 632 | |
---|
| 633 | def addCourse(container, id, REQUEST=None, **kw): |
---|
| 634 | """Add a Course.""" |
---|
| 635 | ob = Course(id, **kw) |
---|
| 636 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 637 | ###) |
---|
[139] | 638 | |
---|
[319] | 639 | |
---|