source: WAeUP_SRP/trunk/Academics.py @ 500

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

moved StudyLevel? class from Academics.py back to Students.py,
cause this Change broke existing StudyLevel? Objects.

  • Property svn:keywords set to Id
File size: 27.9 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 StudyLevel(CPSDocument): ###(
459    """
460    WAeUP StudyLevel containing the courses and students
461    """
462    meta_type = 'StudyLevel'
463    portal_type = meta_type
464    security = ClassSecurityInfo()
465
466    security.declareProtected(View,"Title")
467    def Title(self):
468        """compose title"""
469        try:
470            return "Level %s" % self.aq_parent.getId()
471        except:
472            return "no Title for %s" % self.getId()
473   
474
475InitializeClass(StudyLevel)
476
477def addStudyLevel(container, id, REQUEST=None, **kw):
478    """Add a StudyLevel."""
479    ob = StudyLevel(id, **kw)
480    return CPSBase_adder(container, ob, REQUEST=REQUEST)
481
482###)
483
484class CertificateCourse(CPSDocument): ###(
485    """
486    WAeUP CertificateCourse
487    """
488    meta_type = 'CertificateCourse'
489    portal_type = meta_type
490    security = ClassSecurityInfo()
491
492    def getCourseEntry(self,cid):
493        res = self.portal_catalog({'meta_type': "Course",
494                                           'id': cid})
495        if res:
496            return res[-1]
497        else:
498            return None
499
500    security.declareProtected(View,"Title")
501    def Title(self):
502        """compose title"""
503        ce = self.getCourseEntry(self.id.upper())
504        #print self.id, self.aq_parent.id
505        if ce:
506            return "%s" % ce.Title
507        return "No such course"
508
509    security.declareProtected(View,"credits")
510    def credits(self):
511        """credits from course"""
512        ce = self.getCourseEntry(self.id)
513        if ce:
514            return "%s" % ce.credits
515        return "0"
516
517    security.declareProtected(View,"passmark")
518    def passmark(self):
519        """passmark from course"""
520        ce = self.getCourseEntry(self.id)
521        if ce is not None and hasattr(ce,"passmark"):
522            return ce.passmark
523
524
525    security.declareProtected(View,"coursepath")
526    def coursepath(self):
527        """coursepath from course"""
528        ce = self.getCourseEntry(self.id)
529        if ce:
530            return ce.getPath()
531        return "?"
532
533
534InitializeClass(CertificateCourse)
535
536def addCertificateCourse(container, id, REQUEST=None, **kw):
537    """Add a CertificateCourse."""
538    ob = CertificateCourse(id, **kw)
539    return CPSBase_adder(container, ob, REQUEST=REQUEST)
540###)
541
542class Faculty(CPSDocument): ###(
543    """
544    WAeUP Faculty containing Departments
545    """
546    meta_type = 'Faculty'
547    portal_type = meta_type
548    security = ClassSecurityInfo()
549
550##    def __init__(self, id, **kw):
551##        CPSDocument.__init__(self, id, **kw)
552
553    security.declareProtected(View,"Title")
554    def Title(self):
555        """compose title"""
556        return "%s" % (self.title)
557
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','faculty')
565            self.getContent().edit(mapping = {'title_prefix': prefix})
566        itype = self.portal_vocabularies.institution_types_voc.get(prefix,default="Faculty of")
567        return "%s %s" % (itype,self.title)
568
569InitializeClass(Faculty)
570
571def addFaculty(container, id, REQUEST=None, **kw):
572    """Add a Faculty."""
573    ob = Faculty(id, **kw)
574    return CPSBase_adder(container, ob, REQUEST=REQUEST)
575
576###)
577
578class Department(CPSDocument): ###(
579    """
580    WAeUP Department containing the courses and students
581    """
582    meta_type = 'Department'
583    portal_type = meta_type
584    security = ClassSecurityInfo()
585
586    security.declareProtected(View,"LongTitle")
587    def LongTitle(self):
588        """compose long_title"""
589        prefix = getattr(self,'title_prefix',None)
590        if prefix is None:
591            prefix = getattr(self,'institution_type','department')
592            self.getContent().edit(mapping = {'title_prefix': prefix})
593        itype = self.portal_vocabularies.institution_types_voc.get(prefix,default="Department of")
594        return "%s %s" % (itype,self.title)
595
596InitializeClass(Department)
597
598def addDepartment(container, id, REQUEST=None, **kw):
599    """Add a Department."""
600    object = Department(id, **kw)
601    id = object.getId()
602    container._setObject(id, object)
603##    dep = getattr(container,id).getEditableContent()   #getContent()
604##    dep.invokeFactory('CoursesFolder','Courses')
605##    o = getattr(dep,'Courses')
606##    dict = {'Title': 'Courses'}
607##    o.getContent().edit(mapping=dict)
608##    dep.invokeFactory('CertificatesFolder','Certificates')
609##    o = getattr(dep,'Certificates')
610##    dict = {'Title': 'Certificates'}
611##    o.geetContent().edit(mapping=dict)
612    if REQUEST is not None:
613        url = container.absolute_url()
614        REQUEST.RESPONSE.redirect('%s/manage_main' % url)
615
616###)
617
618class Course(CPSDocument): ###(
619    """
620    WAeUP Course
621    """
622    meta_type = 'Course'
623    portal_type = meta_type
624    security = ClassSecurityInfo()
625
626    security.declareProtected(View,"Title")
627    def Title(self):
628        """compose title"""
629        return self.title
630
631InitializeClass(Course)
632
633def addCourse(container, id, REQUEST=None, **kw):
634    """Add a Course."""
635    ob = Course(id, **kw)
636    return CPSBase_adder(container, ob, REQUEST=REQUEST)
637###)
638
639
Note: See TracBrowser for help on using the repository browser.