source: WAeUP_SRP/trunk/Academics.py @ 349

Last change on this file since 349 was 332, checked in by joachim, 18 years ago

academics_contents for Levels, add Course in Semesters

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