source: WAeUP_SRP/trunk/Academics.py @ 435

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

import of full_time_students_results

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