source: WAeUP_SRP/branches/srp_benin/Academics.py @ 482

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

levels can be created
keyerror elective fixed
check for blanks in Id's checked

  • 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    use_catalog_for_folder_contents = True
42
43    security.declareProtected(View,"Title")
44    def Title(self):
45        """compose title"""
46        return "Academic Section"
47
48    security.declareProtected(ModifyPortalContent,"loadFacultiesFromCSV")###(
49    def loadFacultiesFromCSV(self):
50        """install Universityspecific Faculies from CSV values"""
51        #return
52        name = 'faculty'
53        no_import = False
54        logger = logging.getLogger('%s_import' % name)
55        logger.info('Start loading from %s.csv' % name)
56        academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject()
57        try:
58            faculties = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
59        except:
60            logger.error('Error reading %s.csv' % name)
61            return
62        l = self.portal_catalog({'meta_type': "Faculty"})
63        facs = {}
64        for f in l:
65            facs[f.id] = f.getObject()
66        for faculty in faculties:
67            logger.info('processing %(Session)s %(FacultyCode)s %(Description)s %(CollegeCode)s %(FacultyKey)s %(Status)s %(degree_grade)s %(Bankcode)s' % faculty)
68            fid = faculty['FacultyCode']
69            f = facs.get(fid,None)
70            if f is None:
71                #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
72                logger.info('Creating Faculty with ID %(FacultyCode)s %(Description)s' % faculty)
73                academics.invokeFactory('Faculty', fid)
74                f = getattr(self,fid)
75                d = {'Title': faculty['Description']}
76            else:
77                d = {}
78##                if not no_import:
79##                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
80##                    no_import.write('"Session","FacultyCode","Description","CollegeCode","FacultyKey","Status","degree_grade","Bankcode"\n')
81##                logger.info('Faculty with ID %(FacultyCode)s %(Description)s already exists' % faculty)
82##                no_import.write('"%(Session)s","%(FacultyCode)s","%(Description)s","%(CollegeCode)s","%(FacultyKey)s","%(Status)s","%(degree_grade)s","%(Bankcode)s"\n' % faculty)
83            d['bank_code'] = faculty.get("Bankcode")
84            d["degree_grade"] = faculty.get("degree_grade")
85            d['institution_type'] = 'faculty'
86            d['Description'] = ''
87            d['college_code'] = faculty.get('CollegeCode')
88            f.getContent().edit(mapping=d)
89        return self.academics.academics_contents()
90    ###)
91
92    security.declareProtected(ModifyPortalContent,"yamlDumpFaculties")###(
93    def yamlDumpFaculties(self):
94        """dump Faculies to Yaml"""
95        #return
96        import yaml
97        logger = logging.getLogger('dumpfaculties')
98        logger.info('Start dumping Faculties')
99        academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject()
100        l = self.portal_catalog({'meta_type': "Faculty"})
101        facs = {}
102        for f in l:
103            facs[f.id] = f.getObject()
104        for fid in facs.keys():
105            faculty = facs.get(fid).aq_self
106            logger.info('dumping %s %s ' % (faculty.id, faculty.title))
107            print yaml.dump(faculty)
108        return self.academics.temporary_view_all()
109        return self.temporary_view_all()
110
111    ###)
112
113    security.declareProtected(ModifyPortalContent,"loadDepartmentsFromCSV")###(
114    def loadDepartmentsFromCSV(self):
115        """install Universityspecific Faculies from CSV values"""
116        #return
117        name = 'departments'
118        no_import = False
119        logger = logging.getLogger('loaddepartments')
120        try:
121            deps = csv.DictReader(open("%s/import/departments.csv" % i_home,"rb"))
122        except:
123            logger.error('Error reading departments.csv')
124            return
125        l = self.portal_catalog({'meta_type': "Faculty"})
126        facs = {}
127        for f in l:
128            facs[f.id] = f.getObject()
129        for dep in deps:
130            logger.info('Processing %(Session)s %(DeptCode)s %(Description)s %(FacultyCode)s' % dep)
131            fid = dep['FacultyCode']
132            f = facs.get(fid,None)
133            if f is None:
134                logger.info( "No Faculty with ID: %s" % fid)
135                if not no_import:
136                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
137                    no_import.write('"Session","DeptCode","Description","FacultyCode"\n')
138                no_import.write( "No Faculty with ID: %s\n" % fid)
139                no_import.write('"%(Session)s","%(DeptCode)s","%(Description)s","%(FacultyCode)s"\n' % dep)
140            else:
141                did = dep.get('DeptCode')
142                d = getattr(f,did,None)
143                if d is None or d.portal_type == "Faculty":
144                    logger.info('Creating Department %(DeptCode)s = %(Description)s' % dep)
145                    f.invokeFactory('Department', did)
146                    d = getattr(f,did)
147                    dict = {'Title': dep['Description']}
148                    d.getContent().edit(mapping=dict)
149                    d.invokeFactory('CoursesFolder','courses')
150                    courses = getattr(d,'courses')
151                    dict = {'Title': 'Courses'}
152                    courses.getContent().edit(mapping=dict)
153                    d.invokeFactory('CertificatesFolder','certificates')
154                    certificates = getattr(d,'certificates')
155                    dict = {'Title': 'Certificates'}
156                    certificates.getContent().edit(mapping=dict)
157        return self.academics.academics_contents()
158    ###)
159
160    security.declareProtected(ModifyPortalContent,"loadCoursesFromCSV")###(
161    def loadCoursesFromCSV(self):
162        """install Universityspecific Courses from CSV values"""
163        #return
164        name = 'courses'
165        no_import = False
166        logger = logging.getLogger('loadcourses')
167        try:
168            courses = csv.DictReader(open("%s/import/courses.csv" % i_home,"rb"))
169        except:
170            logger.error('Error reading courses.csv')
171            return
172        l = self.portal_catalog({'meta_type': "Faculty"})
173        facs = {}
174        for f in l:
175            facs[f.id] = f.getObject()
176        dl = self.portal_catalog({'meta_type': "Department"})
177        deps = {}
178        for d in dl:
179            deps[d.id] = d.getObject()
180        cl = self.portal_catalog({'meta_type': "Course"})
181        course_list = [ c.id for c in cl]
182        for course in courses:
183            logger.info('Processing %(CourseCode)s %(Description)s %(Credits)s %(Dept)s %(Semester)s %(Session)s %(PassMark)s %(Category)s %(AdmStatus)s' % course)
184##            if course.get("FORMERCODE").endswith('BITS'):
185##                continue
186            depid = course.get('Dept').upper()
187            if depid in deps.keys():
188                dept= deps.get(depid)
189    ##        elif depid in facs.keys():
190    ##            dept= facs.get(depid)
191            else:
192                logger.info("Dep %(Dept)s for Course %(CourseCode)s not found" % course)
193                if not no_import:
194                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
195                    no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n')
196                no_import.write("Dep %(Dept)s for Course %(CourseCode)s not found\n" % course)
197                no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course)
198                continue
199            course_id = ''.join(re.split('\W+',course.get('CourseCode')))
200            if len(course_id) == 3:
201                course_id = "%s000" % course_id
202            elif len(course_id) > 10:
203                logger.info("invalid course_code %(CourseCode)s" % course)
204                if not no_import:
205                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
206                    no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n')
207                no_import.write("invalid course_code %(CourseCode)s\n" % course)
208                no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course)
209                continue
210            courses = dept.courses
211            c = getattr(courses,course_id,None)
212            if c is None:
213                logger.info('Creating Course %(CourseCode)s  %(Description)s in Department %(Dept)s' % course)
214                courses.invokeFactory('Course', course_id)
215                c = getattr(courses,course_id)
216            dict = {'Title': course['Description']}
217            dict['code'] = course_id
218            dict['org_code'] = course.get('CourseCode')
219            dict['credits'] = course.get('Credits')
220            dict['semester'] = course.get('Semester')
221            dict['session'] = course.get('Session')
222            dict['category'] = course.get('Category')
223            dict['adm_status'] = course.get('AdmStatus')
224            dict['former_code'] = course.get('FORMERCODE')
225            pm = course.get('PassMark')
226            if pm.find(',') > -1:
227                pm.replace(',','.')
228            elif pm == "":
229                pm = "0.0"
230            try:
231                dict['passmark'] = int(float(pm))
232            except:
233                dict['passmark'] = 0
234            c.getContent().edit(mapping=dict)
235        return self.academics.academics_contents()
236    ###)
237
238    security.declareProtected(ModifyPortalContent,"loadCertificatesFromCSV")###(
239
240    def loadCertificatesFromCSV(self):
241        """install Universityspecific Certificates from CSV values"""
242        #return
243        name = 'certificates'
244        no_import = False
245        logger = logging.getLogger('loadcertificates')
246        try:
247            certificates = csv.DictReader(open("%s/import/certificates.csv" % i_home,"rb"))
248        except:
249            logger.error('Error reading certificates.csv')
250            return
251        f_ids = [f.id for f in self.portal_catalog({'meta_type': "Faculty"})]
252        #d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})]
253        dl = self.portal_catalog({'meta_type': "Department"})
254        deps = {}
255        for d in dl:
256            deps[d.id] = d.getObject()
257        for certificate in certificates:
258            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)
259            depid = certificate.get('Dept')
260            facid = certificate.get('Faculty')
261            if facid not in f_ids:
262                logger.info('Faculty %(Faculty)s for %(CertCode)s %(Description)s not found' % certificate)
263                if not no_import:
264                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
265                    no_import.write('"CertCode","Description","Faculty","MaxPass","MaxLoad","session","PromotionCredits","Probationcredits","StartLevel","endLevel","Nyears","Ncore","MaxElect","MPREFIX","Dept","Admstatus","category"\n')
266                no_import.write('Faculty %(Faculty)s for %(CertCode)s %(Description)s not found\n' % certificate)
267                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)
268                continue
269            if not deps.has_key(depid):
270                logger.info('Department %(Dept)s for %(CertCode)s %(Description)s not found' % certificate)
271                if not no_import:
272                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
273                    no_import.write('"CertCode","Description","Faculty","MaxPass","MaxLoad","session","PromotionCredits","Probationcredits","StartLevel","endLevel","Nyears","Ncore","MaxElect","MPREFIX","Dept","Admstatus","category"\n')
274                no_import.write('Department %(Dept)s for %(CertCode)s %(Description)s not found\n' % certificate)
275                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)
276                continue
277            #certificate_id = "%(category)s_%(Admstatus)s_%(Dept)s" % certificate
278            dep = deps[depid]
279            certificates = dep.certificates
280            code = makeCertificateCode(certificate.get('CertCode'))
281            certificate_id = code
282            c = getattr(certificates,certificate_id,None)
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)
286                certificates.invokeFactory('Certificate', certificate_id)
287                c = getattr(certificates,certificate_id)
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            else:
308                dict = {}
309            dict['original_code'] = certificate.get('CertCode')
310            print
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        ce = self.getCourseEntry(self.id.upper())
478        if ce:
479            return "%s" % ce.Title
480        return "No such course"
481
482    security.declareProtected(View,"credits")
483    def credits(self):
484        """credits from course"""
485        ce = self.getCourseEntry(self.id)
486        if ce:
487            return "%s" % ce.credits
488        return "0"
489
490    security.declareProtected(View,"passmark")
491    def passmark(self):
492        """passmark from course"""
493        ce = self.getCourseEntry(self.id)
494        if ce is not None and hasattr(ce,"passmark"):
495            return ce.passmark
496
497
498    security.declareProtected(View,"coursepath")
499    def coursepath(self):
500        """coursepath from course"""
501        ce = self.getCourseEntry(self.id)
502        if ce:
503            return ce.getPath()
504        return "?"
505
506
507InitializeClass(CertificateCourse)
508
509def addCertificateCourse(container, id, REQUEST=None, **kw):
510    """Add a CertificateCourse."""
511    ob = CertificateCourse(id, **kw)
512    return CPSBase_adder(container, ob, REQUEST=REQUEST)
513###)
514
515class Faculty(CPSDocument): ###(
516    """
517    WAeUP Faculty containing Departments
518    """
519    meta_type = 'Faculty'
520    portal_type = meta_type
521    security = ClassSecurityInfo()
522
523##    def __init__(self, id, **kw):
524##        CPSDocument.__init__(self, id, **kw)
525
526    security.declareProtected(View,"Title")
527    def Title(self):
528        """compose title"""
529        return "%s" % (self.title)
530
531
532    security.declareProtected(View,"LongTitle")
533    def LongTitle(self):
534        """compose long_title"""
535        prefix = getattr(self,'title_prefix',None)
536        if prefix is None:
537            prefix = getattr(self,'institution_type','faculty')
538            self.getContent().edit(mapping = {'title_prefix': prefix})
539        itype = self.portal_vocabularies.institution_types_voc.get(prefix,default="Faculty of")
540        return "%s %s" % (itype,self.title)
541
542InitializeClass(Faculty)
543
544def addFaculty(container, id, REQUEST=None, **kw):
545    """Add a Faculty."""
546    ob = Faculty(id, **kw)
547    return CPSBase_adder(container, ob, REQUEST=REQUEST)
548
549###)
550
551class Department(CPSDocument): ###(
552    """
553    WAeUP Department containing the courses and students
554    """
555    meta_type = 'Department'
556    portal_type = meta_type
557    security = ClassSecurityInfo()
558
559    security.declareProtected(View,"LongTitle")
560    def LongTitle(self):
561        """compose long_title"""
562        prefix = getattr(self,'title_prefix',None)
563        if prefix is None:
564            prefix = getattr(self,'institution_type','department')
565            self.getContent().edit(mapping = {'title_prefix': prefix})
566        itype = self.portal_vocabularies.institution_types_voc.get(prefix,default="Department of")
567        return "%s %s" % (itype,self.title)
568
569InitializeClass(Department)
570
571def addDepartment(container, id, REQUEST=None, **kw):
572    """Add a Department."""
573    object = Department(id, **kw)
574    id = object.getId()
575    container._setObject(id, object)
576##    dep = getattr(container,id).getEditableContent()   #getContent()
577##    dep.invokeFactory('CoursesFolder','Courses')
578##    o = getattr(dep,'Courses')
579##    dict = {'Title': 'Courses'}
580##    o.getContent().edit(mapping=dict)
581##    dep.invokeFactory('CertificatesFolder','Certificates')
582##    o = getattr(dep,'Certificates')
583##    dict = {'Title': 'Certificates'}
584##    o.geetContent().edit(mapping=dict)
585    if REQUEST is not None:
586        url = container.absolute_url()
587        REQUEST.RESPONSE.redirect('%s/manage_main' % url)
588
589###)
590
591class Course(CPSDocument): ###(
592    """
593    WAeUP Course
594    """
595    meta_type = 'Course'
596    portal_type = meta_type
597    security = ClassSecurityInfo()
598
599    security.declareProtected(View,"Title")
600    def Title(self):
601        """compose title"""
602        return self.title
603
604InitializeClass(Course)
605
606def addCourse(container, id, REQUEST=None, **kw):
607    """Add a Course."""
608    ob = Course(id, **kw)
609    return CPSBase_adder(container, ob, REQUEST=REQUEST)
610###)
611
612class CourseTicket(CPSDocument): ###(
613    """
614    WAeUP CourseTicket
615    """
616    meta_type = 'CourseTicket'
617    portal_type = meta_type
618    security = ClassSecurityInfo()
619    def getCourseEntry(self,cid):
620        res = self.portal_catalog({'meta_type': "Course",
621                                           'id': cid})
622        if res:
623            return res[-1]
624        else:
625            return None
626
627    security.declareProtected(View,"Title")
628    def Title(self):
629        """compose title"""
630        ce = self.getCourseEntry(self.id.upper())
631        if ce:
632            return "%s" % ce.Title
633        return "No such course"
634
635InitializeClass(CourseTicket)
636
637def addCourseTicket(container, id, REQUEST=None, **kw):
638    """Add a CourseTicket."""
639    ob = CourseTicket(id, **kw)
640    return CPSBase_adder(container, ob, REQUEST=REQUEST)
641###)
642
Note: See TracBrowser for help on using the repository browser.