source: WAeUP_SRP/trunk/Academics.py @ 313

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

=types changed

  • Property svn:keywords set to Id
File size: 27.4 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
25class AcademicsFolder(CPSDocument): ###(
26    """
27    WAeUP AcademicsFolder containing StudyCourses
28    """
29    meta_type = 'AcademicsFolder'
30    portal_type = meta_type
31    security = ClassSecurityInfo()
32
33##    security.declareProtected(View,"Title")
34##    def Title(self):
35##        """compose title"""
36##        return "AcademicsFolder of %s" % (self.title)
37
38    security.declareProtected(View,"loadFacultiesFromCSV")###(
39    def loadFacultiesFromCSV(self):
40        """install Universityspecific Faculies from CSV values"""
41        #return
42        name = 'faculty'
43        no_import = False
44        logger = logging.getLogger('%s_import' % name)
45        logger.info('Start loading from %s.csv' % name)
46        academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject()
47        try:
48            faculties = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
49        except:
50            logger.error('Error reading %s.csv' % name)
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)
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)
73        return self.academics.academics_contents()
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)
92        return self.academics.temporary_view_all()
93        return self.temporary_view_all()
94           
95    ###)
96
97    security.declareProtected(ModifyPortalContent,"loadDepartmentsFromCSV")###(
98    def loadDepartmentsFromCSV(self):
99        """install Universityspecific Faculies from CSV values"""
100        #return
101        name = 'departments'
102        no_import = False
103        logger = logging.getLogger('loaddepartments')
104        try:
105            deps = csv.DictReader(open("%s/import/departments.csv" % i_home,"rb"))
106        except:
107            logger.error('Error reading departments.csv')
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)
119                if not no_import:
120                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
121                    no_import.write('"Session","DeptCode","Description","FacultyCode"\n')
122                no_import.write( "No Faculty with ID: %s\n" % fid)
123                no_import.write('"%(Session)s","%(DeptCode)s","%(Description)s","%(FacultyCode)s"\n' % dep)
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)
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)
141        return self.academics.academics_contents()
142    ###)
143   
144    security.declareProtected(ModifyPortalContent,"loadCoursesFromCSV")###(
145    def loadCoursesFromCSV(self):
146        """install Universityspecific Courses from CSV values"""
147        #return
148        name = 'courses'
149        no_import = False
150        logger = logging.getLogger('loadcourses')
151        try:
152            courses = csv.DictReader(open("%s/import/courses.csv" % i_home,"rb"))
153        except:
154            logger.error('Error reading courses.csv')
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:
167            logger.info('Processing %(CourseCode)s %(Description)s %(Credits)s %(Dept)s %(Semester)s %(Session)s %(PassMark)s %(Category)s %(AdmStatus)s' % course)
168##            if course.get("FORMERCODE").endswith('BITS'):
169##                continue
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)
177                if not no_import:
178                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
179                    no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n')
180                no_import.write("Dep %(Dept)s for Course %(CourseCode)s not found\n" % course)
181                no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course)
182                continue
183            course_id = ''.join(re.split('\W+',course.get('CourseCode')))
184            if len(course_id) == 3:
185                course_id = "%s000" % course_id
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
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
198            elif len(course_id) > 10:
199                logger.info("invalid course_code %(CourseCode)s" % course)
200                if not no_import:
201                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
202                    no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n')
203                no_import.write("invalid course_code %(CourseCode)s\n" % course)
204                no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course)
205                continue
206            courses = dept.Courses
207            c = getattr(courses,course_id,None)
208            if c is None:
209                logger.info('Creating Course %(CourseCode)s  %(Description)s in Department %(Dept)s' % course)
210                courses.invokeFactory('Course', course_id)
211                c = getattr(courses,course_id)
212            dict = {'Title': course['Description']}
213            dict['code'] = course_id
214            dict['org_code'] = course.get('CourseCode')
215            dict['credits'] = course.get('Credits')
216            dict['semester'] = course.get('Semester')
217            dict['session'] = course.get('Session')
218            dict['category'] = course.get('Category')
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
228            c.getContent().edit(mapping=dict)
229        return self.academics.academics_contents()
230    ###)
231
232    security.declareProtected(ModifyPortalContent,"loadCertificatesFromCSV")###(
233
234    def loadCertificatesFromCSV(self):
235        """install Universityspecific Certificates from CSV values"""
236        #return
237        name = 'certificates'
238        no_import = False
239        logger = logging.getLogger('loadcertificates')
240        try:
241            certificates = csv.DictReader(open("%s/import/certificates.csv" % i_home,"rb"))
242        except:
243            logger.error('Error reading certificates.csv')
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)
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)
262                continue
263            if not deps.has_key(depid):
264                logger.info('Department %(Dept)s for %(CertCode)s %(Description)s not found' % certificate)
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)
270                continue
271            #certificate_id = "%(category)s_%(Admstatus)s_%(Dept)s" % certificate
272            dep = deps[depid]
273            certificates = dep.Certificates
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
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            c.getContent().edit(mapping=dict)
308        return self.academics.academics_contents()
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')
316        name = 'certificate_courses'
317        no_import = False
318        try:
319            cert_courses = csv.DictReader(open("%s/import/course_level_courses.csv" % i_home,"rb"))
320        except:
321            logger.error('Error reading course_level_courses.csv')
322            return
323        d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})]
324        c_ids = [c.id for c in self.portal_catalog({'meta_type': "Course"})]
325        l = self.portal_catalog({'meta_type': "Certificate"})
326        certs = {}
327        for f in l:
328            certs[f.id] = f.getObject()
329        for cert_course in cert_courses:
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)
331            depid = cert_course.get('Dept')
332            course_code = cert_course.get('CosCode')
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('_','')
340##            if cert_course.get('Session') != '2002/2003':
341##                continue
342##            certificate = self.portal_catalog({'meta_type': "Certificate",
343##                                               'SearchableText': code})
344##            if not certificate:
345            if not code in certs.keys():
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")
351                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
352                no_import.write(em)
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)
354                continue
355            certificate = certs[code]
356            certificate_code = certificate.getId()
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")
362                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
363                no_import.write(em)
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)
365                continue
366            if depid not in d_ids:
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")
371                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
372                no_import.write(em)
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)
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')
384            certificate.orderObjects('id')
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)
393                if not no_import:
394                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
395                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
396##                no_import.write('Duplicate %(CosCode)s in Level %(Level)s' % cert_course)
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)
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')
413            cc.getContent().edit(mapping=dict)
414        return self.academics.academics_contents()
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
426class Certificate(CPSDocument): ###(
427    """
428    WAeUP Certificate
429    """
430    meta_type = 'Certificate'
431    portal_type = meta_type
432    security = ClassSecurityInfo()
433   
434    def __init__(self, id, **kw):
435        CPSDocument.__init__(self, id, **kw)
436
437##    security.declareProtected(View,"Title")
438##    def Title(self):
439##        """compose title"""
440##        return "Certificate of %s" % (self.title)
441
442InitializeClass(Certificate)
443
444def addCertificate(container, id, REQUEST=None, **kw):
445    """Add a Certificate."""
446    ob = Certificate(id, **kw)
447    return CPSBase_adder(container, ob, REQUEST=REQUEST)
448
449###)
450
451class CertificateCourse(CPSDocument): ###(
452    """
453    WAeUP CertificateCourse 
454    """
455    meta_type = 'CertificateCourse'
456    portal_type = meta_type
457    security = ClassSecurityInfo()
458   
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       
467    security.declareProtected(View,"Title")
468    def Title(self):
469        """compose title"""
470        ce = self.getCourseEntry(self.id)
471        if ce:
472            return "%s" % ce.Title
473        return "No such course"
474
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
481        return "0"
482   
483    security.declareProtected(View,"passmark")
484    def passmark(self):
485        """passmark from course"""
486        ce = self.getCourseEntry(self.id)
487        if ce is not None and hasattr(ce,"passmark"):
488            return ce.passmark
489       
490   
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 "?"
498   
499
500InitializeClass(CertificateCourse)
501
502def addCertificateCourse(container, id, REQUEST=None, **kw):
503    """Add a CertificateCourse."""
504    ob = CertificateCourse(id, **kw)
505    return CPSBase_adder(container, ob, REQUEST=REQUEST)
506###)
507
508class Faculty(CPSDocument): ###(
509    """
510    WAeUP Faculty containing Departments
511    """
512    meta_type = 'Faculty'
513    portal_type = meta_type
514    security = ClassSecurityInfo()
515   
516##    def __init__(self, id, **kw):
517##        CPSDocument.__init__(self, id, **kw)
518
519    security.declareProtected(View,"Title")
520    def Title(self):
521        """compose title"""
522        return "%s" % (self.title)
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)
530
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()
547
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)
553
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
563InitializeClass(Department)
564
565def addDepartment(container, id, REQUEST=None, **kw):
566    """Add a Department."""
567    object = Department(id, **kw)
568    id = object.getId()
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)
579    if REQUEST is not None:
580        url = container.absolute_url()
581        REQUEST.RESPONSE.redirect('%s/manage_main' % url)
582
583###)
584
585class Course(CPSDocument): ###(
586    """
587    WAeUP Course 
588    """
589    meta_type = 'Course'
590    portal_type = meta_type
591    security = ClassSecurityInfo()
592
593    security.declareProtected(View,"Title")
594    def Title(self):
595        """compose title"""
596        return self.title
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###)
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###)
621
Note: See TracBrowser for help on using the repository browser.