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