[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 | |
---|
[526] | 19 | import DateTime |
---|
[279] | 20 | import csv,re |
---|
| 21 | import logging |
---|
| 22 | import Globals |
---|
| 23 | p_home = Globals.package_home(globals()) |
---|
| 24 | i_home = Globals.INSTANCE_HOME |
---|
| 25 | |
---|
[719] | 26 | def makeCertificateCode(code): ###( |
---|
[361] | 27 | code = code.replace('.','') |
---|
| 28 | code = code.replace('(','') |
---|
| 29 | code = code.replace(')','') |
---|
| 30 | code = code.replace('/','') |
---|
| 31 | code = code.replace(' ','') |
---|
| 32 | code = code.replace('_','') |
---|
| 33 | return code |
---|
| 34 | |
---|
[719] | 35 | ###) |
---|
| 36 | |
---|
[278] | 37 | class AcademicsFolder(CPSDocument): ###( |
---|
| 38 | """ |
---|
[319] | 39 | WAeUP AcademicsFolder containing StudyCourses |
---|
[278] | 40 | """ |
---|
| 41 | meta_type = 'AcademicsFolder' |
---|
| 42 | portal_type = meta_type |
---|
| 43 | security = ClassSecurityInfo() |
---|
[440] | 44 | use_catalog_for_folder_contents = True |
---|
[278] | 45 | |
---|
[364] | 46 | security.declareProtected(View,"Title") |
---|
| 47 | def Title(self): |
---|
| 48 | """compose title""" |
---|
[382] | 49 | return "Academic Section" |
---|
[256] | 50 | |
---|
[592] | 51 | def importLocalRoles(self,portal_type): ###( |
---|
| 52 | name = '%sLocalRoles' % portal_type |
---|
[1082] | 53 | logger = logging.getLogger('Import.%s' % name) |
---|
[592] | 54 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
[602] | 55 | logger.info('Start importing %(name)s to %(name)s_%(current)s.csv' % vars()) |
---|
[592] | 56 | export = [] |
---|
| 57 | export.append('"code","users"') |
---|
| 58 | pm = self.portal_membership |
---|
| 59 | #import pdb;pdb.set_trace() |
---|
| 60 | try: |
---|
| 61 | imp_roles = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 62 | except: |
---|
| 63 | logger.error('Error reading %s.csv' % name) |
---|
| 64 | return |
---|
| 65 | odict = {} |
---|
| 66 | for f in self.portal_catalog({'meta_type': portal_type}): |
---|
[602] | 67 | odict[f.getId] = f.getObject() |
---|
[592] | 68 | for role in imp_roles: |
---|
| 69 | obj_id = role['code'] |
---|
| 70 | if obj_id in odict.keys(): |
---|
| 71 | roles_dict = eval(role['users']) |
---|
| 72 | for r in roles_dict.keys(): |
---|
| 73 | if r.startswith('user'): |
---|
| 74 | member_id = r.split(':')[1] |
---|
| 75 | odict[obj_id].manage_setLocalRoles(member_id, roles_dict[r]) |
---|
| 76 | logger.info('importing role for %s %s %s' % (obj_id, member_id,roles_dict[r])) |
---|
| 77 | |
---|
| 78 | ###) |
---|
| 79 | |
---|
[351] | 80 | security.declareProtected(ModifyPortalContent,"loadFacultiesFromCSV")###( |
---|
[319] | 81 | def loadFacultiesFromCSV(self): |
---|
[278] | 82 | """install Universityspecific Faculies from CSV values""" |
---|
| 83 | #return |
---|
[592] | 84 | if self.REQUEST.get('localroles'): |
---|
| 85 | self.importLocalRoles('Faculty') |
---|
| 86 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
[549] | 87 | name = 'Faculties' |
---|
[282] | 88 | no_import = False |
---|
[1082] | 89 | logger = logging.getLogger('Import.%s_csv' % name) |
---|
[563] | 90 | logger.info('Start loading from %s.csv' % name) |
---|
| 91 | academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject() |
---|
| 92 | try: |
---|
| 93 | faculties = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 94 | except: |
---|
| 95 | logger.error('Error reading %s.csv' % name) |
---|
| 96 | return |
---|
| 97 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
| 98 | facs = {} |
---|
| 99 | for f in l: |
---|
| 100 | facs[f.id] = f.getObject() |
---|
| 101 | fields = ("code", |
---|
| 102 | "review_state", |
---|
| 103 | "title", |
---|
| 104 | "title_prefix", |
---|
| 105 | "college_code", |
---|
| 106 | "degree_grade", |
---|
| 107 | "bank_code", |
---|
| 108 | ) |
---|
[719] | 109 | format = ','.join(['"%%(%s)s"' % fn for fn in fields]) |
---|
[563] | 110 | for faculty in faculties: |
---|
| 111 | processing = "processing %s" % format |
---|
| 112 | logger.info(processing % faculty) |
---|
| 113 | fid = faculty.get('code') |
---|
| 114 | f = facs.get(fid,None) |
---|
| 115 | if f is None: |
---|
| 116 | #self.log('Creating Faculty %(id)s = %(Title)s' % faculty) |
---|
| 117 | logger.info('Creating Faculty with ID %(code)s %(title)s' % faculty) |
---|
| 118 | academics.invokeFactory('Faculty', fid) |
---|
| 119 | f = getattr(self,fid) |
---|
| 120 | d = {'Title': faculty.get('title')} |
---|
| 121 | else: |
---|
| 122 | d = {} |
---|
| 123 | f.getContent().edit(mapping=faculty) |
---|
| 124 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 125 | ###) |
---|
| 126 | |
---|
| 127 | security.declareProtected(ModifyPortalContent,"loadDepartmentsFromCSV")###( |
---|
| 128 | def loadDepartmentsFromCSV(self): |
---|
| 129 | """install Universityspecific Faculies from CSV values""" |
---|
| 130 | #return |
---|
[592] | 131 | if self.REQUEST.get('localroles'): |
---|
| 132 | self.importLocalRoles('Department') |
---|
| 133 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
[563] | 134 | name = 'Departments' |
---|
| 135 | no_import = False |
---|
[1082] | 136 | logger = logging.getLogger('Import.Departments') |
---|
[563] | 137 | fields = ("code", |
---|
| 138 | "review_state", |
---|
| 139 | "title", |
---|
| 140 | "title_prefix", |
---|
| 141 | "faculty_code", |
---|
| 142 | ) |
---|
[719] | 143 | format = ','.join(['"%%(%s)s"' % fn for fn in fields]) |
---|
[563] | 144 | try: |
---|
| 145 | deps = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 146 | except: |
---|
| 147 | logger.error('Error reading %s.csv' % name) |
---|
| 148 | return |
---|
| 149 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
[719] | 150 | heading = ','.join(['"%s"' % fn for fn in fields]) |
---|
[563] | 151 | no_import.write('%s\n' % heading) |
---|
| 152 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
| 153 | facs = {} |
---|
| 154 | for f in l: |
---|
| 155 | facs[f.id] = f.getObject() |
---|
| 156 | for dep in deps: |
---|
| 157 | processing = "processing %s" % format |
---|
| 158 | logger.info(processing % dep) |
---|
| 159 | fid = dep['faculty_code'] |
---|
| 160 | f = facs.get(fid,None) |
---|
| 161 | if f is None: |
---|
| 162 | logger.info( "No Faculty with ID: %s" % fid) |
---|
| 163 | no_import.write( "No Faculty with ID: %s\n" % fid) |
---|
| 164 | no_import.write(format % dep + "\n") |
---|
| 165 | else: |
---|
| 166 | did = dep.get('code') |
---|
| 167 | d = getattr(f,did,None) |
---|
| 168 | if d is None or d.portal_type == "Faculty": |
---|
| 169 | logger.info('Creating Department %(code)s = %(title)s' % dep) |
---|
| 170 | f.invokeFactory('Department', did) |
---|
| 171 | d = getattr(f,did) |
---|
| 172 | d.invokeFactory('CoursesFolder','courses') |
---|
| 173 | courses = getattr(d,'courses') |
---|
| 174 | dict = {'Title': 'Courses'} |
---|
| 175 | courses.getContent().edit(mapping=dict) |
---|
| 176 | d.invokeFactory('CertificatesFolder','certificates') |
---|
| 177 | certificates = getattr(d,'certificates') |
---|
| 178 | dict = {'Title': 'Certificates'} |
---|
| 179 | certificates.getContent().edit(mapping=dict) |
---|
| 180 | d.getContent().edit(mapping=dep) |
---|
[602] | 181 | |
---|
[563] | 182 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 183 | ###) |
---|
| 184 | |
---|
| 185 | security.declareProtected(ModifyPortalContent,"loadCoursesFromCSV")###( |
---|
| 186 | def loadCoursesFromCSV(self): |
---|
| 187 | """install Universityspecific Courses from CSV values""" |
---|
| 188 | #return |
---|
[1146] | 189 | not_allowed =re.compile('[^A-Z0-9]') |
---|
[563] | 190 | wf = self.portal_workflow |
---|
| 191 | name = 'Courses' |
---|
| 192 | no_import = False |
---|
[1082] | 193 | logger = logging.getLogger('Import.Courses') |
---|
[563] | 194 | fields = ("code", |
---|
| 195 | "review_state", |
---|
| 196 | "title", |
---|
| 197 | "faculty_code", |
---|
| 198 | "department_code", |
---|
| 199 | "credits", |
---|
| 200 | "org_code", |
---|
| 201 | "passmark", |
---|
| 202 | "semester", |
---|
| 203 | "session", |
---|
| 204 | ) |
---|
[719] | 205 | format = ','.join(['"%%(%s)s"' % fn for fn in fields]) |
---|
[563] | 206 | try: |
---|
| 207 | courses = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 208 | except: |
---|
| 209 | logger.error('Error reading %s.csv' % name) |
---|
| 210 | return |
---|
[1146] | 211 | imported = [] |
---|
| 212 | not_imported = [] |
---|
[719] | 213 | heading = ','.join(['"%s"' % fn for fn in fields]) |
---|
[1146] | 214 | imported.append(heading) |
---|
| 215 | not_imported.append(heading) |
---|
| 216 | #no_import.write('%s\n' % heading) |
---|
[563] | 217 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
| 218 | facs = {} |
---|
| 219 | for f in l: |
---|
| 220 | facs[f.id] = f.getObject() |
---|
| 221 | dl = self.portal_catalog({'meta_type': "Department"}) |
---|
| 222 | deps = {} |
---|
| 223 | for d in dl: |
---|
| 224 | deps[d.id] = d.getObject() |
---|
| 225 | cl = self.portal_catalog({'meta_type': "Course"}) |
---|
| 226 | course_list = [ c.id for c in cl] |
---|
| 227 | for course in courses: |
---|
[1146] | 228 | #processing = "processing %s" % format |
---|
| 229 | #logger.info(processing % course) |
---|
| 230 | course_id = course.get('code') |
---|
| 231 | if not_allowed.search(course_id): |
---|
| 232 | msg = ',"Invalid Course Code"' |
---|
| 233 | #logger.info(msg) |
---|
| 234 | #not_imported.append('"%s",' % msg) |
---|
| 235 | not_imported.append(format % course + msg) |
---|
| 236 | continue |
---|
[563] | 237 | depid = course.get('department_code').upper() |
---|
| 238 | if depid in deps.keys(): |
---|
| 239 | dept= deps.get(depid) |
---|
| 240 | else: |
---|
[1146] | 241 | msg = ',"Department not found"' |
---|
| 242 | #logger.info(msg) |
---|
| 243 | #not_imported.append('"%s",' % msg) |
---|
| 244 | not_imported.append(format % course + msg) |
---|
[563] | 245 | continue |
---|
[928] | 246 | if course_id in course_list: |
---|
[1146] | 247 | msg = ',"Multiple Course Code"' |
---|
| 248 | #logger.info(msg) |
---|
| 249 | #not_imported.append('"%s",' % msg) |
---|
| 250 | not_imported.append(format % course + msg) |
---|
[928] | 251 | continue |
---|
[1146] | 252 | level = "%c00" % course_id[-3] |
---|
| 253 | course['level'] = level |
---|
[563] | 254 | cf = dept.courses |
---|
| 255 | c = getattr(cf,course_id,None) |
---|
[1146] | 256 | cd_fields = (('code','code'), |
---|
| 257 | ('faculty','faculty_code'), |
---|
| 258 | ('department','department_code'), |
---|
| 259 | ('title','title'), |
---|
| 260 | ('credits','credits'), |
---|
| 261 | ('level','level'), |
---|
| 262 | ('semester','semester'), |
---|
| 263 | ) |
---|
| 264 | cd = {} |
---|
| 265 | for t,f in cd_fields: |
---|
| 266 | cd[t] = course[f] |
---|
| 267 | #import pdb;pdb.set_trace() |
---|
[563] | 268 | if c is None: |
---|
| 269 | logger.info('Creating Course %(code)s %(title)s in Department %(department_code)s' % course) |
---|
| 270 | cf.invokeFactory('Course', course_id) |
---|
[928] | 271 | course_list.append(course_id) |
---|
[1146] | 272 | imported.append(format % course) |
---|
[563] | 273 | c = getattr(cf,course_id) |
---|
[1146] | 274 | self.courses_catalog.addRecord(**cd) |
---|
| 275 | else: |
---|
| 276 | self.courses_catalog.modifyRecord(**cd) |
---|
[563] | 277 | c.getContent().edit(mapping=course) |
---|
| 278 | review_state = course.get('review_state') |
---|
| 279 | if review_state == "checked" and wf.getInfoFor(c,'review_state',None) != 'checked': |
---|
| 280 | self.portal_workflow.doActionFor(c,'approve') |
---|
[1146] | 281 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 282 | if len(not_imported) > 1: |
---|
| 283 | open("%s/import/%s_%s_not_imported.csv" % (i_home,name,current),"w")\ |
---|
| 284 | .write('\n'.join(not_imported)) |
---|
| 285 | open("%s/import/%s_%s_imported.csv" % (i_home,name,current),"w")\ |
---|
| 286 | .write('\n'.join(imported)) |
---|
[563] | 287 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 288 | ###) |
---|
| 289 | |
---|
| 290 | security.declareProtected(ModifyPortalContent,"loadCertificatesFromCSV")###( |
---|
| 291 | |
---|
| 292 | def loadCertificatesFromCSV(self): |
---|
| 293 | """install Universityspecific Certificates from CSV values""" |
---|
| 294 | #return |
---|
| 295 | name = 'Certificates' |
---|
| 296 | wf = self.portal_workflow |
---|
| 297 | no_import_list = [] |
---|
[1082] | 298 | logger = logging.getLogger('Import.Certificates') |
---|
[563] | 299 | fields = ("code", |
---|
| 300 | "review_state", |
---|
| 301 | "title", |
---|
| 302 | "faculty_code", |
---|
| 303 | "department_code", |
---|
| 304 | "category", |
---|
| 305 | "end_level", |
---|
| 306 | "m_prefix", |
---|
| 307 | "max_elect", |
---|
| 308 | "max_pass", |
---|
| 309 | "n_core", |
---|
| 310 | "nr_years", |
---|
| 311 | "original_code", |
---|
| 312 | "probation_credits", |
---|
| 313 | "promotion_credits", |
---|
| 314 | "start_level", |
---|
| 315 | "admin_status", |
---|
| 316 | ) |
---|
[719] | 317 | format = ','.join(['"%%(%s)s"' % fn for fn in fields]) |
---|
[563] | 318 | try: |
---|
| 319 | courses = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 320 | except: |
---|
| 321 | logger.error('Error reading %s.csv' % name) |
---|
| 322 | return |
---|
| 323 | try: |
---|
| 324 | certificates = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 325 | except: |
---|
| 326 | logger.error('Error reading %s.csv' % name) |
---|
| 327 | return |
---|
| 328 | f_ids = [f.id for f in self.portal_catalog({'meta_type': "Faculty"})] |
---|
| 329 | dl = self.portal_catalog({'meta_type': "Department"}) |
---|
| 330 | deps = {} |
---|
| 331 | for d in dl: |
---|
| 332 | deps[d.id] = d.getObject() |
---|
| 333 | for certificate in certificates: |
---|
| 334 | processing = "processing %s" % format |
---|
| 335 | logger.info(processing % certificate) |
---|
| 336 | depid = certificate.get('department_code') |
---|
| 337 | facid = certificate.get('faculty_code') |
---|
| 338 | if facid not in f_ids: |
---|
| 339 | msg = 'Faculty %(faculty_code)s for %(code)s %(title)s not found' % certificate |
---|
| 340 | logger.info(msg) |
---|
| 341 | no_import_list.append(msg) |
---|
| 342 | no_import_list.append(format % certificate + "\n") |
---|
| 343 | continue |
---|
| 344 | if not deps.has_key(depid): |
---|
| 345 | msg = 'Department %(department_code)s for %(code)s %(title)s not found' % certificate |
---|
| 346 | logger.info(msg) |
---|
| 347 | no_import_list.append(msg) |
---|
| 348 | no_import_list.append(format % certificate + "\n") |
---|
| 349 | continue |
---|
| 350 | dep = deps[depid] |
---|
| 351 | cf= dep.certificates |
---|
| 352 | code = certificate.get('code') |
---|
| 353 | certificate_id = code |
---|
| 354 | c = getattr(cf,certificate_id,None) |
---|
| 355 | if c is None: |
---|
| 356 | logger.info('Creating certificate %(code)s %(title)s in Department %(department_code)s' % certificate) |
---|
| 357 | cf.invokeFactory('Certificate', certificate_id) |
---|
| 358 | c = getattr(cf,certificate_id) |
---|
| 359 | c.getContent().edit(mapping=certificate) |
---|
| 360 | review_state = c.get('review_state') |
---|
| 361 | if review_state == "checked" and wf.getInfoFor(c,'review_state',None) != 'checked': |
---|
| 362 | self.portal_workflow.doActionFor(c,'approve') |
---|
| 363 | if no_import_list: |
---|
| 364 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
[719] | 365 | heading = ','.join(['"%s"' % fn for fn in fields]) |
---|
[563] | 366 | no_import.write('%s\n' % heading) |
---|
| 367 | for line in no_import_list: |
---|
| 368 | no_import.write(line) |
---|
| 369 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 370 | ###) |
---|
| 371 | |
---|
| 372 | security.declareProtected(ModifyPortalContent,"loadCertificateCoursesFromCSV")###( |
---|
| 373 | def loadCertificateCoursesFromCSV(self): |
---|
| 374 | """install Certificate Courses from CSV values""" |
---|
| 375 | #return |
---|
[1082] | 376 | logger = logging.getLogger('Import.CertificateCourses') |
---|
[563] | 377 | name = 'CertificateCourses' |
---|
| 378 | wf = self.portal_workflow |
---|
| 379 | no_import_list = [] |
---|
[1082] | 380 | logger = logging.getLogger('Import.CertificateCourses') |
---|
[563] | 381 | fields = ("code", |
---|
| 382 | "review_state", |
---|
| 383 | "faculty_code", |
---|
| 384 | "department_code", |
---|
| 385 | "certificate_code", |
---|
| 386 | "level", |
---|
| 387 | "semester", |
---|
| 388 | "core_or_elective", |
---|
| 389 | ) |
---|
[719] | 390 | format = ','.join(['"%%(%s)s"' % fn for fn in fields]) |
---|
[563] | 391 | try: |
---|
| 392 | cert_courses = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 393 | except: |
---|
| 394 | logger.error('Error reading %s.csv' % name) |
---|
| 395 | return |
---|
[929] | 396 | ## d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})] |
---|
[563] | 397 | c_ids = [c.id for c in self.portal_catalog({'meta_type': "Course"})] |
---|
| 398 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 399 | certs = {} |
---|
| 400 | for f in l: |
---|
[720] | 401 | ca,ac,fa,depid,co,code = f.relative_path.split('/') |
---|
[929] | 402 | ## pid = "%(depid)s_%(code)s" % vars() |
---|
| 403 | pid = "%(code)s" % vars() |
---|
[720] | 404 | certs[pid] = f.getObject() |
---|
[563] | 405 | for cert_course in cert_courses: |
---|
| 406 | processing = "processing %s" % format |
---|
| 407 | logger.info(processing % cert_course) |
---|
[929] | 408 | ## depid = cert_course.get('department_code') |
---|
[563] | 409 | course_code = cert_course.get('code') |
---|
| 410 | code = cert_course.get('certificate_code') |
---|
[929] | 411 | ## pid = "%(depid)s_%(code)s" % vars() |
---|
[937] | 412 | pid = "%(code)s" % vars() |
---|
[720] | 413 | if not pid in certs.keys(): |
---|
[563] | 414 | em = 'CertCode %(certificate_code)s for %(code)s not found\n' % cert_course |
---|
| 415 | logger.info(em) |
---|
[718] | 416 | #no_import_list.append(em) |
---|
[719] | 417 | no_import_list.append(format % cert_course + ',"Certificate"\n') |
---|
[563] | 418 | continue |
---|
[720] | 419 | certificate = certs[pid] |
---|
[563] | 420 | certificate_code = certificate.getId() |
---|
| 421 | if course_code not in c_ids: |
---|
| 422 | em = 'Course %(code)s for %(certificate_code)s Level %(level)s not found in Courses\n' % cert_course |
---|
| 423 | logger.info(em) |
---|
[718] | 424 | #no_import_list.append(em) |
---|
[719] | 425 | no_import_list.append(format % cert_course + ',"Course"\n') |
---|
[563] | 426 | continue |
---|
[929] | 427 | ## if depid not in d_ids: |
---|
| 428 | ## em = 'Department %(department_code)s for %(certificate_code)s not found\n' % cert_course |
---|
| 429 | ## logger.info(em) |
---|
| 430 | ## #no_import_list.append(em) |
---|
| 431 | ## no_import_list.append(format % cert_course + ',"Department"\n') |
---|
| 432 | ## continue |
---|
[563] | 433 | level = cert_course.get('level') |
---|
| 434 | l = getattr(certificate,level,None) |
---|
| 435 | if l is None: |
---|
| 436 | logger.info('Creating Level %(level)s in certificate %(certificate_code)s' % cert_course) |
---|
| 437 | certificate.invokeFactory('StudyLevel', level) |
---|
| 438 | l = getattr(certificate, level) |
---|
| 439 | l.getContent().edit(mapping={'Title': "Level %s" % level}) |
---|
| 440 | certificate.orderObjects('id') |
---|
| 441 | if hasattr(l,course_code): |
---|
| 442 | msg = 'Duplicate %(code)s in Level %(level)s' % cert_course |
---|
| 443 | logger.info(msg) |
---|
[718] | 444 | #no_import_list.append(msg + "\n") |
---|
[719] | 445 | no_import_list.append(format % cert_course + ',"duplicate"\n') |
---|
[563] | 446 | continue |
---|
| 447 | l.invokeFactory('CertificateCourse',course_code) |
---|
| 448 | logger.info('Creating CertificateCourse %(code)s in certificate %(certificate_code)s Level %(level)s' % cert_course) |
---|
| 449 | cc = getattr(l,course_code) |
---|
| 450 | semester = 'first' |
---|
| 451 | try: |
---|
| 452 | sem = int(cert_course.get('semester')) |
---|
| 453 | cert_course['semester'] = ('first','second')[sem - 1] |
---|
| 454 | except: |
---|
| 455 | pass |
---|
[691] | 456 | cert_course['core_or_elective'] = cert_course['core_or_elective'] in ("TRUE","True") |
---|
[563] | 457 | cc.getContent().edit(mapping=cert_course) |
---|
| 458 | review_state = cc.get('review_state') |
---|
| 459 | if review_state == "checked" and wf.getInfoFor(cc,'review_state',None) != 'checked': |
---|
| 460 | self.portal_workflow.doActionFor(cc,'approve') |
---|
| 461 | if no_import_list: |
---|
| 462 | no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w") |
---|
[719] | 463 | heading = ','.join(['"%s"' % fn for fn in fields]) |
---|
[563] | 464 | no_import.write('%s\n' % heading) |
---|
| 465 | for line in no_import_list: |
---|
| 466 | no_import.write(line) |
---|
| 467 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 468 | ###) |
---|
| 469 | |
---|
[278] | 470 | |
---|
| 471 | security.declareProtected(ModifyPortalContent,"yamlDumpFaculties")###( |
---|
[319] | 472 | def yamlDumpFaculties(self): |
---|
[278] | 473 | """dump Faculies to Yaml""" |
---|
| 474 | #return |
---|
| 475 | import yaml |
---|
| 476 | logger = logging.getLogger('dumpfaculties') |
---|
| 477 | logger.info('Start dumping Faculties') |
---|
| 478 | academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject() |
---|
| 479 | l = self.portal_catalog({'meta_type': "Faculty"}) |
---|
| 480 | facs = {} |
---|
| 481 | for f in l: |
---|
| 482 | facs[f.id] = f.getObject() |
---|
| 483 | for fid in facs.keys(): |
---|
| 484 | faculty = facs.get(fid).aq_self |
---|
| 485 | logger.info('dumping %s %s ' % (faculty.id, faculty.title)) |
---|
| 486 | print yaml.dump(faculty) |
---|
[526] | 487 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
[319] | 488 | |
---|
[278] | 489 | ###) |
---|
| 490 | |
---|
[319] | 491 | |
---|
[592] | 492 | def exportLocalRoles(self,portal_type): ###( |
---|
[593] | 493 | name = '%sLocalRoles' % portal_type |
---|
[1082] | 494 | logger = logging.getLogger('Export.%s' % name) |
---|
[592] | 495 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 496 | logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars()) |
---|
[595] | 497 | objects = [f.getObject() for f in self.portal_catalog({'meta_type': portal_type})] |
---|
[592] | 498 | export = [] |
---|
| 499 | export.append('"code","users"') |
---|
[593] | 500 | #import pdb;pdb.set_trace() |
---|
[592] | 501 | for obj in objects: |
---|
[602] | 502 | lr = {} |
---|
| 503 | for (username, roles) in obj.get_local_roles(): |
---|
| 504 | lr[ 'user:' + username ] = [x for x in roles] |
---|
| 505 | for (groupname, roles) in obj.get_local_group_roles(): |
---|
| 506 | lr[ 'group:' + group ] = [x for x in roles] |
---|
[592] | 507 | logger.info('exporting %s %s ' % (obj.id, lr)) |
---|
| 508 | export.append('"%s","%s"' % (obj.getId(),lr)) |
---|
| 509 | open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export)) |
---|
| 510 | ###) |
---|
[602] | 511 | |
---|
[526] | 512 | security.declareProtected(ModifyPortalContent,"exportFacultiesToCSV")###( |
---|
| 513 | def exportFacultiesToCSV(self): |
---|
| 514 | """export Faculies to CSV""" |
---|
| 515 | #return |
---|
[592] | 516 | if self.REQUEST.get('localroles'): |
---|
| 517 | self.exportLocalRoles('Faculty') |
---|
| 518 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
[549] | 519 | name = 'Faculties' |
---|
[526] | 520 | no_import = False |
---|
[1082] | 521 | logger = logging.getLogger('Export.%s' % name) |
---|
[526] | 522 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 523 | logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars()) |
---|
[557] | 524 | objects = [f.getObject() for f in self.portal_catalog({'meta_type': 'Faculty'})] |
---|
[526] | 525 | export = [] |
---|
| 526 | export.append('"code","review_state","title","title_prefix","college_code","degree_grade","bank_code"') |
---|
| 527 | for obj in objects: |
---|
| 528 | logger.info('exporting %s %s ' % (obj.id, obj.title)) |
---|
| 529 | obj_d = obj.getContent() |
---|
| 530 | di = {} |
---|
| 531 | di['code'] = obj_d.code |
---|
| 532 | di['title'] = obj_d.title |
---|
| 533 | di['title_prefix'] = obj_d.title_prefix |
---|
| 534 | di['college_code'] = obj_d.college_code |
---|
| 535 | di['degree_grade'] = obj_d.degree_grade |
---|
| 536 | di['bank_code'] = obj_d.bank_code |
---|
| 537 | di['code'] = di['code'] or obj.id |
---|
| 538 | di['review_state'] = self.portal_workflow.getInfoFor(obj,'review_state','no_state') |
---|
| 539 | export.append('"%(code)s","%(review_state)s","%(title)s","%(title_prefix)s","%(college_code)s","%(degree_grade)s","%(bank_code)s"' % di) |
---|
| 540 | open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export)) |
---|
| 541 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 542 | |
---|
| 543 | ###) |
---|
| 544 | |
---|
| 545 | security.declareProtected(ModifyPortalContent,"exportDepartmentsToCSV")###( |
---|
| 546 | def exportDepartmentsToCSV(self): |
---|
| 547 | """export Faculies to CSV""" |
---|
| 548 | #return |
---|
[592] | 549 | if self.REQUEST.get('localroles'): |
---|
| 550 | self.exportLocalRoles('Department') |
---|
| 551 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
[549] | 552 | name = 'Departments' |
---|
[526] | 553 | no_import = False |
---|
[1082] | 554 | logger = logging.getLogger('Export.%s' % name) |
---|
[526] | 555 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 556 | logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars()) |
---|
| 557 | faculties = [f.getObject() for f in self.portal_catalog({'meta_type': 'Faculty'})] |
---|
| 558 | export = [] |
---|
| 559 | export.append('"code","review_state","title","title_prefix","faculty_code"') |
---|
| 560 | #import pdb;pdb.set_trace() |
---|
| 561 | for faculty in faculties: |
---|
| 562 | di = {} |
---|
| 563 | di['faculty_code'] = faculty.id |
---|
| 564 | for department in faculty.objectValues(): |
---|
| 565 | department_d = department.getContent() |
---|
| 566 | try: |
---|
[576] | 567 | di['code'] = department.getId() |
---|
[526] | 568 | di['title'] = department_d.title |
---|
| 569 | di['title_prefix'] = department_d.title_prefix |
---|
| 570 | di['review_state'] = self.portal_workflow.getInfoFor(department,'review_state','no_state') |
---|
[527] | 571 | export.append('"%(code)s","%(review_state)s","%(title)s","%(title_prefix)s","%(faculty_code)s"' % di) |
---|
[526] | 572 | logger.info('exporting %s %s ' % (department.id, department.title)) |
---|
| 573 | except: |
---|
| 574 | logger.info('could not export %s %s ' % (department.id, department.title)) |
---|
| 575 | continue |
---|
| 576 | open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export)) |
---|
| 577 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 578 | ###) |
---|
| 579 | |
---|
| 580 | security.declareProtected(ModifyPortalContent,"exportCoursesToCSV")###( |
---|
| 581 | def exportCoursesToCSV(self): |
---|
| 582 | """export Courses to CSV""" |
---|
| 583 | #return |
---|
[549] | 584 | name = 'Courses' |
---|
[526] | 585 | no_import = False |
---|
[1082] | 586 | logger = logging.getLogger('Export.%s' % name) |
---|
[526] | 587 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 588 | logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars()) |
---|
| 589 | faculties = [f.getObject() for f in self.portal_catalog({'meta_type': 'Faculty'})] |
---|
| 590 | export = [] |
---|
| 591 | heading = '"code","review_state","title","faculty_code","department_code",' |
---|
| 592 | heading += '"credits","org_code","passmark","semester","session"' |
---|
| 593 | dataline = '"%(code)s","%(review_state)s","%(title)s","%(faculty_code)s","%(department_code)s",' |
---|
| 594 | dataline += '"%(credits)s","%(org_code)s","%(passmark)s","%(semester)s","%(session)s"' |
---|
| 595 | export.append(heading) |
---|
| 596 | #import pdb;pdb.set_trace() |
---|
[576] | 597 | fields = ("title", |
---|
[567] | 598 | "credits", |
---|
| 599 | "org_code", |
---|
| 600 | "passmark", |
---|
| 601 | "semester", |
---|
| 602 | "session", |
---|
| 603 | ) |
---|
[526] | 604 | for faculty in faculties: |
---|
| 605 | di = {} |
---|
| 606 | di['faculty_code'] = faculty.id |
---|
| 607 | for department in faculty.objectValues(): |
---|
| 608 | di['department_code'] = department.id |
---|
[527] | 609 | for course in department.courses.objectValues(): |
---|
[576] | 610 | di['code'] = course.getId() |
---|
[526] | 611 | course_d = course.getContent() |
---|
[567] | 612 | for f in fields: |
---|
| 613 | di[f] = getattr(course_d,f,None) |
---|
[569] | 614 | di['review_state'] = self.portal_workflow.getInfoFor(course,'review_state','no_state') |
---|
[567] | 615 | export.append(dataline % di) |
---|
| 616 | logger.info('exporting %s %s ' % (course.id, course.title)) |
---|
[526] | 617 | continue |
---|
| 618 | open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export)) |
---|
| 619 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 620 | ###) |
---|
| 621 | |
---|
| 622 | security.declareProtected(ModifyPortalContent,"exportCertificatesToCSV")###( |
---|
| 623 | def exportCertificatesToCSV(self): |
---|
| 624 | """export Certificates to CSV""" |
---|
| 625 | #return |
---|
[549] | 626 | name = 'Certificates' |
---|
[526] | 627 | no_import = False |
---|
[1082] | 628 | logger = logging.getLogger('Export.%s' % name) |
---|
[526] | 629 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 630 | logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars()) |
---|
| 631 | faculties = [f.getObject() for f in self.portal_catalog({'meta_type': 'Faculty'})] |
---|
| 632 | export = [] |
---|
| 633 | heading = '"code","review_state","title","faculty_code","department_code",' |
---|
| 634 | heading += '"category","end_level","m_prefix","max_elect","max_pass",' |
---|
| 635 | heading += '"n_core","nr_years","original_code","probation_credits",' |
---|
| 636 | heading += '"promotion_credits","start_level","admin_status"' |
---|
[527] | 637 | dataline = '"%(code)s","%(review_state)s","%(title)s","%(faculty_code)s","%(department_code)s",' |
---|
[526] | 638 | dataline += '"%(category)s","%(end_level)s","%(m_prefix)s","%(max_elect)s","%(max_pass)s",' |
---|
| 639 | dataline += '"%(n_core)s","%(nr_years)s","%(original_code)s","%(probation_credits)s",' |
---|
| 640 | dataline += '"%(promotion_credits)s","%(start_level)s","%(admin_status)s"' |
---|
| 641 | export.append(heading) |
---|
| 642 | #import pdb;pdb.set_trace() |
---|
| 643 | for faculty in faculties: |
---|
| 644 | di = {} |
---|
| 645 | di['faculty_code'] = faculty.id |
---|
| 646 | for department in faculty.objectValues(): |
---|
| 647 | di['department_code'] = department.id |
---|
[527] | 648 | for certificate in department.certificates.objectValues(): |
---|
[526] | 649 | certificate_d = certificate.getContent() |
---|
[576] | 650 | di['code'] = certificate.id |
---|
| 651 | #di['code'] = getattr(certificate_d,'code',None) |
---|
[529] | 652 | di['title'] = getattr(certificate_d,'title',None) |
---|
| 653 | di['category'] = getattr(certificate_d,'category',None) |
---|
| 654 | di['admin_status'] = getattr(certificate_d,'admin_status',None) |
---|
| 655 | di['end_level'] = getattr(certificate_d,'end_level',None) |
---|
| 656 | di['m_prefix'] = getattr(certificate_d,'m_prefix',None) |
---|
| 657 | di['max_elect'] = getattr(certificate_d,'max_elect',None) |
---|
| 658 | di['max_load'] = getattr(certificate_d,'max_load',None) |
---|
| 659 | di['max_pass'] = getattr(certificate_d,'max_pass',None) |
---|
| 660 | di['n_core'] = getattr(certificate_d,'n_core',None) |
---|
| 661 | di['nr_years'] = getattr(certificate_d,'nr_years',None) |
---|
| 662 | di['original_code'] = getattr(certificate_d,'original_code',None) |
---|
| 663 | di['probation_credits'] = getattr(certificate_d,'probation_credits',None) |
---|
| 664 | di['promotion_credits'] = getattr(certificate_d,'promotion_credits',None) |
---|
| 665 | di['start_level'] = getattr(certificate_d,'start_level',None) |
---|
[526] | 666 | di['code'] = di['code'] or certificate.id |
---|
| 667 | di['review_state'] = self.portal_workflow.getInfoFor(certificate,'review_state','no_state') |
---|
| 668 | try: |
---|
| 669 | export.append(dataline % di) |
---|
| 670 | logger.info('exporting %s %s ' % (certificate.id, certificate.title)) |
---|
| 671 | except: |
---|
| 672 | logger.info('could not export %s %s ' % (certificate.id, certificate.title)) |
---|
| 673 | continue |
---|
| 674 | open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export)) |
---|
| 675 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 676 | ###) |
---|
| 677 | |
---|
| 678 | security.declareProtected(ModifyPortalContent,"exportCertificateCoursesToCSV")###( |
---|
| 679 | def exportCertificateCoursesToCSV(self): |
---|
| 680 | """export CertificateCourses to CSV""" |
---|
| 681 | #return |
---|
[549] | 682 | name = 'CertificateCourses' |
---|
[526] | 683 | no_import = False |
---|
[1082] | 684 | logger = logging.getLogger('Export.%s' % name) |
---|
[526] | 685 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 686 | logger.info('Start exporting %(name)s to %(name)s_%(current)s.csv' % vars()) |
---|
| 687 | faculties = [f.getObject() for f in self.portal_catalog({'meta_type': 'Faculty'})] |
---|
| 688 | export = [] |
---|
| 689 | heading = '"code","review_state","faculty_code","department_code",' |
---|
| 690 | heading += '"certificate_code","level","semester","core_or_elective"' |
---|
| 691 | dataline = '"%(code)s","%(review_state)s","%(faculty_code)s","%(department_code)s",' |
---|
[527] | 692 | dataline += '"%(certificate_code)s","%(level)s","%(semester)s","%(core_or_elective)s"' |
---|
[526] | 693 | export.append(heading) |
---|
| 694 | #import pdb;pdb.set_trace() |
---|
| 695 | semesters = ['first','second'] |
---|
| 696 | for faculty in faculties: |
---|
| 697 | di = {} |
---|
| 698 | di['faculty_code'] = faculty.id |
---|
| 699 | for department in faculty.objectValues(): |
---|
| 700 | di['department_code'] = department.id |
---|
[527] | 701 | for certificate in department.certificates.objectValues(): |
---|
[526] | 702 | di['certificate_code'] = certificate.id |
---|
| 703 | for level in certificate.objectValues(): |
---|
| 704 | di['level'] = level.id |
---|
| 705 | for sem in semesters: |
---|
| 706 | semester = getattr(level,sem,None) |
---|
| 707 | if semester is not None: |
---|
[527] | 708 | di['semester'] = semesters.index(sem) + 1 |
---|
[526] | 709 | for course in semester.objectValues(): |
---|
[576] | 710 | di['code'] = course.getId() |
---|
[526] | 711 | course_d = course.getContent() |
---|
[529] | 712 | di['core_or_elective'] = getattr(course_d,'core_or_elective',None) |
---|
[526] | 713 | di['review_state'] = self.portal_workflow.getInfoFor(course,'review_state','no_state') |
---|
| 714 | try: |
---|
| 715 | export.append(dataline % di) |
---|
| 716 | logger.info('exporting %s %s ' % (certificate.id, certificate.title)) |
---|
| 717 | except: |
---|
| 718 | logger.info('could not export %s %s ' % (certificate.id, certificate.title)) |
---|
| 719 | continue |
---|
| 720 | open("%s/import/%s-%s.csv" % (i_home,name,current),"w+").write('\n'.join(export)) |
---|
| 721 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 722 | ###) |
---|
| 723 | |
---|
| 724 | |
---|
[278] | 725 | InitializeClass(AcademicsFolder) |
---|
| 726 | |
---|
| 727 | def addAcademicsFolder(container, id, REQUEST=None, **kw): |
---|
| 728 | """Add a AcademicsFolder.""" |
---|
| 729 | ob = AcademicsFolder(id, **kw) |
---|
| 730 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 731 | |
---|
| 732 | ###) |
---|
| 733 | |
---|
[256] | 734 | class Certificate(CPSDocument): ###( |
---|
[238] | 735 | """ |
---|
[319] | 736 | WAeUP Certificate |
---|
[238] | 737 | """ |
---|
[256] | 738 | meta_type = 'Certificate' |
---|
[238] | 739 | portal_type = meta_type |
---|
| 740 | security = ClassSecurityInfo() |
---|
[319] | 741 | |
---|
[238] | 742 | def __init__(self, id, **kw): |
---|
| 743 | CPSDocument.__init__(self, id, **kw) |
---|
| 744 | |
---|
[256] | 745 | ## security.declareProtected(View,"Title") |
---|
| 746 | ## def Title(self): |
---|
| 747 | ## """compose title""" |
---|
| 748 | ## return "Certificate of %s" % (self.title) |
---|
[238] | 749 | |
---|
[256] | 750 | InitializeClass(Certificate) |
---|
[238] | 751 | |
---|
[256] | 752 | def addCertificate(container, id, REQUEST=None, **kw): |
---|
| 753 | """Add a Certificate.""" |
---|
| 754 | ob = Certificate(id, **kw) |
---|
[238] | 755 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 756 | |
---|
| 757 | ###) |
---|
| 758 | |
---|
[454] | 759 | class StudyLevel(CPSDocument): ###( |
---|
| 760 | """ |
---|
| 761 | WAeUP StudyLevel containing the courses and students |
---|
| 762 | """ |
---|
| 763 | meta_type = 'StudyLevel' |
---|
| 764 | portal_type = meta_type |
---|
| 765 | security = ClassSecurityInfo() |
---|
| 766 | |
---|
| 767 | security.declareProtected(View,"Title") |
---|
| 768 | def Title(self): |
---|
| 769 | """compose title""" |
---|
[458] | 770 | try: |
---|
| 771 | return "Level %s" % self.aq_parent.getId() |
---|
| 772 | except: |
---|
| 773 | return "no Title for %s" % self.getId() |
---|
[454] | 774 | |
---|
[527] | 775 | |
---|
[454] | 776 | InitializeClass(StudyLevel) |
---|
| 777 | |
---|
| 778 | def addStudyLevel(container, id, REQUEST=None, **kw): |
---|
| 779 | """Add a StudyLevel.""" |
---|
| 780 | ob = StudyLevel(id, **kw) |
---|
| 781 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 782 | |
---|
| 783 | ###) |
---|
| 784 | |
---|
[256] | 785 | class CertificateCourse(CPSDocument): ###( |
---|
[238] | 786 | """ |
---|
[319] | 787 | WAeUP CertificateCourse |
---|
[238] | 788 | """ |
---|
[256] | 789 | meta_type = 'CertificateCourse' |
---|
[238] | 790 | portal_type = meta_type |
---|
| 791 | security = ClassSecurityInfo() |
---|
[319] | 792 | |
---|
[279] | 793 | def getCourseEntry(self,cid): |
---|
| 794 | res = self.portal_catalog({'meta_type': "Course", |
---|
| 795 | 'id': cid}) |
---|
| 796 | if res: |
---|
[319] | 797 | return res[-1] |
---|
[279] | 798 | else: |
---|
| 799 | return None |
---|
[319] | 800 | |
---|
[256] | 801 | security.declareProtected(View,"Title") |
---|
| 802 | def Title(self): |
---|
| 803 | """compose title""" |
---|
[583] | 804 | #import pdb;pdb.set_trace() |
---|
| 805 | ce = self.getCourseEntry(self.aq_parent.getId()) |
---|
[454] | 806 | #print self.id, self.aq_parent.id |
---|
[279] | 807 | if ce: |
---|
| 808 | return "%s" % ce.Title |
---|
| 809 | return "No such course" |
---|
[238] | 810 | |
---|
[279] | 811 | security.declareProtected(View,"credits") |
---|
| 812 | def credits(self): |
---|
| 813 | """credits from course""" |
---|
| 814 | ce = self.getCourseEntry(self.id) |
---|
| 815 | if ce: |
---|
| 816 | return "%s" % ce.credits |
---|
[280] | 817 | return "0" |
---|
[319] | 818 | |
---|
[279] | 819 | security.declareProtected(View,"passmark") |
---|
| 820 | def passmark(self): |
---|
| 821 | """passmark from course""" |
---|
| 822 | ce = self.getCourseEntry(self.id) |
---|
[296] | 823 | if ce is not None and hasattr(ce,"passmark"): |
---|
| 824 | return ce.passmark |
---|
[319] | 825 | |
---|
| 826 | |
---|
[280] | 827 | security.declareProtected(View,"coursepath") |
---|
| 828 | def coursepath(self): |
---|
| 829 | """coursepath from course""" |
---|
| 830 | ce = self.getCourseEntry(self.id) |
---|
| 831 | if ce: |
---|
| 832 | return ce.getPath() |
---|
| 833 | return "?" |
---|
[279] | 834 | |
---|
[319] | 835 | |
---|
[256] | 836 | InitializeClass(CertificateCourse) |
---|
[238] | 837 | |
---|
[256] | 838 | def addCertificateCourse(container, id, REQUEST=None, **kw): |
---|
| 839 | """Add a CertificateCourse.""" |
---|
| 840 | ob = CertificateCourse(id, **kw) |
---|
[238] | 841 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 842 | ###) |
---|
| 843 | |
---|
[68] | 844 | class Faculty(CPSDocument): ###( |
---|
| 845 | """ |
---|
[319] | 846 | WAeUP Faculty containing Departments |
---|
[68] | 847 | """ |
---|
| 848 | meta_type = 'Faculty' |
---|
| 849 | portal_type = meta_type |
---|
| 850 | security = ClassSecurityInfo() |
---|
[319] | 851 | |
---|
[238] | 852 | ## def __init__(self, id, **kw): |
---|
| 853 | ## CPSDocument.__init__(self, id, **kw) |
---|
[173] | 854 | |
---|
[200] | 855 | security.declareProtected(View,"Title") |
---|
| 856 | def Title(self): |
---|
| 857 | """compose title""" |
---|
[238] | 858 | return "%s" % (self.title) |
---|
[319] | 859 | |
---|
[389] | 860 | |
---|
[296] | 861 | security.declareProtected(View,"LongTitle") |
---|
| 862 | def LongTitle(self): |
---|
| 863 | """compose long_title""" |
---|
[389] | 864 | prefix = getattr(self,'title_prefix',None) |
---|
| 865 | if prefix is None: |
---|
| 866 | prefix = getattr(self,'institution_type','faculty') |
---|
| 867 | self.getContent().edit(mapping = {'title_prefix': prefix}) |
---|
| 868 | itype = self.portal_vocabularies.institution_types_voc.get(prefix,default="Faculty of") |
---|
[296] | 869 | return "%s %s" % (itype,self.title) |
---|
[200] | 870 | |
---|
[68] | 871 | InitializeClass(Faculty) |
---|
| 872 | |
---|
| 873 | def addFaculty(container, id, REQUEST=None, **kw): |
---|
| 874 | """Add a Faculty.""" |
---|
| 875 | ob = Faculty(id, **kw) |
---|
| 876 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 877 | |
---|
| 878 | ###) |
---|
| 879 | |
---|
| 880 | class Department(CPSDocument): ###( |
---|
| 881 | """ |
---|
| 882 | WAeUP Department containing the courses and students |
---|
| 883 | """ |
---|
| 884 | meta_type = 'Department' |
---|
| 885 | portal_type = meta_type |
---|
| 886 | security = ClassSecurityInfo() |
---|
[173] | 887 | |
---|
[296] | 888 | security.declareProtected(View,"LongTitle") |
---|
| 889 | def LongTitle(self): |
---|
| 890 | """compose long_title""" |
---|
[389] | 891 | prefix = getattr(self,'title_prefix',None) |
---|
| 892 | if prefix is None: |
---|
| 893 | prefix = getattr(self,'institution_type','department') |
---|
| 894 | self.getContent().edit(mapping = {'title_prefix': prefix}) |
---|
| 895 | itype = self.portal_vocabularies.institution_types_voc.get(prefix,default="Department of") |
---|
[296] | 896 | return "%s %s" % (itype,self.title) |
---|
| 897 | |
---|
[68] | 898 | InitializeClass(Department) |
---|
| 899 | |
---|
| 900 | def addDepartment(container, id, REQUEST=None, **kw): |
---|
| 901 | """Add a Department.""" |
---|
[296] | 902 | object = Department(id, **kw) |
---|
[295] | 903 | id = object.getId() |
---|
[319] | 904 | container._setObject(id, object) |
---|
[309] | 905 | ## dep = getattr(container,id).getEditableContent() #getContent() |
---|
| 906 | ## dep.invokeFactory('CoursesFolder','Courses') |
---|
| 907 | ## o = getattr(dep,'Courses') |
---|
| 908 | ## dict = {'Title': 'Courses'} |
---|
| 909 | ## o.getContent().edit(mapping=dict) |
---|
| 910 | ## dep.invokeFactory('CertificatesFolder','Certificates') |
---|
| 911 | ## o = getattr(dep,'Certificates') |
---|
| 912 | ## dict = {'Title': 'Certificates'} |
---|
| 913 | ## o.geetContent().edit(mapping=dict) |
---|
[295] | 914 | if REQUEST is not None: |
---|
| 915 | url = container.absolute_url() |
---|
| 916 | REQUEST.RESPONSE.redirect('%s/manage_main' % url) |
---|
[309] | 917 | |
---|
[68] | 918 | ###) |
---|
| 919 | |
---|
| 920 | class Course(CPSDocument): ###( |
---|
| 921 | """ |
---|
[319] | 922 | WAeUP Course |
---|
[68] | 923 | """ |
---|
| 924 | meta_type = 'Course' |
---|
| 925 | portal_type = meta_type |
---|
| 926 | security = ClassSecurityInfo() |
---|
[152] | 927 | |
---|
| 928 | security.declareProtected(View,"Title") |
---|
| 929 | def Title(self): |
---|
| 930 | """compose title""" |
---|
[238] | 931 | return self.title |
---|
[319] | 932 | |
---|
[68] | 933 | InitializeClass(Course) |
---|
| 934 | |
---|
| 935 | def addCourse(container, id, REQUEST=None, **kw): |
---|
| 936 | """Add a Course.""" |
---|
| 937 | ob = Course(id, **kw) |
---|
| 938 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 939 | ###) |
---|
[139] | 940 | |
---|
[319] | 941 | |
---|