source: WAeUP_SRP/trunk/Academics.py @ 368

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

moved catalog.xml

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