source: WAeUP_SRP/trunk/Academics.py @ 309

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

=types changed

  • Property svn:keywords set to Id
File size: 27.4 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
8from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder
9#from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument
10from Products.CPSDocument.CPSDocument import CPSDocument
[200]11#from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder
12#from Products.CPSCore.CPSBase import CPSBaseBTreeDocument as BaseBTreeDocument
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    """
27    WAeUP AcademicsFolder containing StudyCourses
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")###(
[278]39    def loadFacultiesFromCSV(self):
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")###(
77    def yamlDumpFaculties(self):
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()
[278]94           
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)
133                    d.invokeFactory('CoursesFolder','Courses')
134                    courses = getattr(d,'Courses')
135                    dict = {'Title': 'Courses'}
136                    courses.getContent().edit(mapping=dict)
137                    d.invokeFactory('CertificatesFolder','Certificates')
138                    certificates = getattr(d,'Certificates')
139                    dict = {'Title': 'Certificates'}
140                    certificates.getContent().edit(mapping=dict)
[296]141        return self.academics.academics_contents()
[278]142    ###)
143   
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
[295]206            courses = dept.Courses
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
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]
[295]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
290            dict['faculty'] = certificate.get('Faculty')
291            dict['department'] = certificate.get('Dept')
292            dict['max_pass'] = certificate.get('MaxPass')
293            dict['max_load'] = certificate.get('MaxLoad')
294            dict['admin_status'] = certificate.get('Admstatus')
295            dict['category'] = certificate.get('category')
296            dict['m_prefix'] = certificate.get('MPREFIX')
297            dict['nr_years'] = int(certificate.get('Nyears'))
298            nc = certificate.get('Ncore','1')
299            try:
300                dict['n_core'] = int(nc)
301            except:
302                dict['n_core'] = 1
303            dict['start_level'] = certificate.get('StartLevel')
304            dict['end_level'] = certificate.get('endLevel')
305            dict['promotion_credits'] = certificate.get('PromotionCredits')
306            dict['probation_credits'] = certificate.get('ProbationCredits')
307            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)
382                l.invokeFactory('Semester','first')
383                l.invokeFactory('Semester','second')
[290]384            certificate.orderObjects('id')
[278]385            first_s = getattr(l,'first')
386            second_s = getattr(l,'second')
387            if cert_course.get('Semester') == '1':
388                semester = first_s
389            else:
390                semester = second_s
391            if hasattr(semester,course_code):
392                logger.info('Duplicate %(CosCode)s in Level %(Level)s' % cert_course)
[290]393                if not no_import:
394                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
[296]395                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
[295]396##                no_import.write('Duplicate %(CosCode)s in Level %(Level)s' % cert_course)
[296]397##                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]398                continue
399            semester.invokeFactory('CertificateCourse',course_code)
400            cc = getattr(semester,course_code)
401            dict = {}
402            dict['code'] = cert_course.get('CosCode')
403            dict['certificate_code'] = code
404            dict['certificate_code_org'] = cert_course.get('CertCode')
405            dict['department'] = cert_course.get('Dept')
406            dict['admin_status'] = cert_course.get('Admstatus')
407            dict['session'] = cert_course.get('Session')
408            if cert_course.get('Core') != '':
409                dict['core_or_elective'] = True
410            else:
411                dict['core_or_elective'] = False
412            dict['level'] = cert_course.get('Level')
[295]413            cc.getContent().edit(mapping=dict)
[296]414        return self.academics.academics_contents()
[278]415    ###)
416
417InitializeClass(AcademicsFolder)
418
419def addAcademicsFolder(container, id, REQUEST=None, **kw):
420    """Add a AcademicsFolder."""
421    ob = AcademicsFolder(id, **kw)
422    return CPSBase_adder(container, ob, REQUEST=REQUEST)
423
424###)
425
[256]426class Certificate(CPSDocument): ###(
[238]427    """
[256]428    WAeUP Certificate
[238]429    """
[256]430    meta_type = 'Certificate'
[238]431    portal_type = meta_type
432    security = ClassSecurityInfo()
433   
434    def __init__(self, id, **kw):
435        CPSDocument.__init__(self, id, **kw)
436
[256]437##    security.declareProtected(View,"Title")
438##    def Title(self):
439##        """compose title"""
440##        return "Certificate of %s" % (self.title)
[238]441
[256]442InitializeClass(Certificate)
[238]443
[256]444def addCertificate(container, id, REQUEST=None, **kw):
445    """Add a Certificate."""
446    ob = Certificate(id, **kw)
[238]447    return CPSBase_adder(container, ob, REQUEST=REQUEST)
448
449###)
450
[256]451class CertificateCourse(CPSDocument): ###(
[238]452    """
[256]453    WAeUP CertificateCourse 
[238]454    """
[256]455    meta_type = 'CertificateCourse'
[238]456    portal_type = meta_type
457    security = ClassSecurityInfo()
458   
[279]459    def getCourseEntry(self,cid):
460        res = self.portal_catalog({'meta_type': "Course",
461                                           'id': cid})
462        if res:
463            return res[-1] 
464        else:
465            return None
466       
[256]467    security.declareProtected(View,"Title")
468    def Title(self):
469        """compose title"""
[279]470        ce = self.getCourseEntry(self.id)
471        if ce:
472            return "%s" % ce.Title
473        return "No such course"
[238]474
[279]475    security.declareProtected(View,"credits")
476    def credits(self):
477        """credits from course"""
478        ce = self.getCourseEntry(self.id)
479        if ce:
480            return "%s" % ce.credits
[280]481        return "0"
[279]482   
483    security.declareProtected(View,"passmark")
484    def passmark(self):
485        """passmark from course"""
486        ce = self.getCourseEntry(self.id)
[296]487        if ce is not None and hasattr(ce,"passmark"):
488            return ce.passmark
489       
[290]490   
[280]491    security.declareProtected(View,"coursepath")
492    def coursepath(self):
493        """coursepath from course"""
494        ce = self.getCourseEntry(self.id)
495        if ce:
496            return ce.getPath()
497        return "?"
[279]498   
499
[256]500InitializeClass(CertificateCourse)
[238]501
[256]502def addCertificateCourse(container, id, REQUEST=None, **kw):
503    """Add a CertificateCourse."""
504    ob = CertificateCourse(id, **kw)
[238]505    return CPSBase_adder(container, ob, REQUEST=REQUEST)
506###)
507
[68]508class Faculty(CPSDocument): ###(
509    """
510    WAeUP Faculty containing Departments
511    """
512    meta_type = 'Faculty'
513    portal_type = meta_type
514    security = ClassSecurityInfo()
515   
[238]516##    def __init__(self, id, **kw):
517##        CPSDocument.__init__(self, id, **kw)
[173]518
[200]519    security.declareProtected(View,"Title")
520    def Title(self):
521        """compose title"""
[238]522        return "%s" % (self.title)
[296]523   
524    security.declareProtected(View,"LongTitle")
525    def LongTitle(self):
526        """compose long_title"""
527        itype = self.portal_vocabularies.institution_types_voc.get(self.institution_type,default="Faculty of")
528       
529        return "%s %s" % (itype,self.title)
[200]530
[68]531InitializeClass(Faculty)
532
533def addFaculty(container, id, REQUEST=None, **kw):
534    """Add a Faculty."""
535    ob = Faculty(id, **kw)
536    return CPSBase_adder(container, ob, REQUEST=REQUEST)
537
538###)
539
540class Department(CPSDocument): ###(
541    """
542    WAeUP Department containing the courses and students
543    """
544    meta_type = 'Department'
545    portal_type = meta_type
546    security = ClassSecurityInfo()
[173]547
[176]548##    security.declareProtected(View,"Title")
549##    def Title(self):
550##        """compose title"""
551##        reg_nr = self.getId()[1:]
552##        return "Department of %s" % (self.title)
[173]553
[296]554    security.declareProtected(View,"LongTitle")
555    def LongTitle(self):
556        """compose long_title"""
557        if not hasattr(self,'institution_type'):
558            self.institution_type = "department"
559        itype = self.portal_vocabularies.institution_types_voc.get(self.institution_type,default="Department of")
560       
561        return "%s %s" % (itype,self.title)
562
[68]563InitializeClass(Department)
564
565def addDepartment(container, id, REQUEST=None, **kw):
566    """Add a Department."""
[296]567    object = Department(id, **kw)
[295]568    id = object.getId()
[309]569    container._setObject(id, object)   
570##    dep = getattr(container,id).getEditableContent()   #getContent()
571##    dep.invokeFactory('CoursesFolder','Courses')
572##    o = getattr(dep,'Courses')
573##    dict = {'Title': 'Courses'}
574##    o.getContent().edit(mapping=dict)
575##    dep.invokeFactory('CertificatesFolder','Certificates')
576##    o = getattr(dep,'Certificates')
577##    dict = {'Title': 'Certificates'}
578##    o.geetContent().edit(mapping=dict)
[295]579    if REQUEST is not None:
580        url = container.absolute_url()
581        REQUEST.RESPONSE.redirect('%s/manage_main' % url)
[309]582
[68]583###)
584
585class Course(CPSDocument): ###(
586    """
587    WAeUP Course 
588    """
589    meta_type = 'Course'
590    portal_type = meta_type
591    security = ClassSecurityInfo()
[152]592
593    security.declareProtected(View,"Title")
594    def Title(self):
595        """compose title"""
[238]596        return self.title
[68]597   
598InitializeClass(Course)
599
600def addCourse(container, id, REQUEST=None, **kw):
601    """Add a Course."""
602    ob = Course(id, **kw)
603    return CPSBase_adder(container, ob, REQUEST=REQUEST)
604###)
[139]605
606class CourseTicket(CPSDocument): ###(
607    """
608    WAeUP CourseTicket 
609    """
610    meta_type = 'CourseTicket'
611    portal_type = meta_type
612    security = ClassSecurityInfo()
613   
614InitializeClass(CourseTicket)
615
616def addCourseTicket(container, id, REQUEST=None, **kw):
617    """Add a CourseTicket."""
618    ob = CourseTicket(id, **kw)
619    return CPSBase_adder(container, ob, REQUEST=REQUEST)
620###)
[256]621
Note: See TracBrowser for help on using the repository browser.