source: WAeUP_SRP/trunk/Academics.py @ 417

Last change on this file since 417 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
RevLine 
[68]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
[319]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
[200]13#from Products.CMFCore.DirectoryView import registerDirectory
[68]14
[200]15#registerDirectory('skins', globals())
16#registerDirectory('skins/waeup_default', globals())
17#registerDirectory('skins/waeup_faculty', globals())
[68]18
[279]19import csv,re
20import logging
21import Globals
22p_home = Globals.package_home(globals())
23i_home = Globals.INSTANCE_HOME
24
[361]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
[278]34class AcademicsFolder(CPSDocument): ###(
35    """
[319]36    WAeUP AcademicsFolder containing StudyCourses
[278]37    """
38    meta_type = 'AcademicsFolder'
39    portal_type = meta_type
40    security = ClassSecurityInfo()
41
[364]42    security.declareProtected(View,"Title")
43    def Title(self):
44        """compose title"""
[382]45        return "Academic Section"
[256]46
[351]47    security.declareProtected(ModifyPortalContent,"loadFacultiesFromCSV")###(
[319]48    def loadFacultiesFromCSV(self):
[278]49        """install Universityspecific Faculies from CSV values"""
50        #return
[282]51        name = 'faculty'
52        no_import = False
53        logger = logging.getLogger('%s_import' % name)
54        logger.info('Start loading from %s.csv' % name)
[278]55        academics = self.portal_catalog({'meta_type': 'AcademicsFolder'})[-1].getObject()
56        try:
[282]57            faculties = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
[278]58        except:
[282]59            logger.error('Error reading %s.csv' % name)
[278]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)
[282]74                d = {'Title': faculty['Description']}
75            else:
[369]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")
[371]84            d['institution_type'] = 'faculty'
[379]85            d['Description'] = ''
86            d['college_code'] = faculty.get('CollegeCode')
[369]87            f.getContent().edit(mapping=d)
[296]88        return self.academics.academics_contents()
[278]89    ###)
90
91    security.declareProtected(ModifyPortalContent,"yamlDumpFaculties")###(
[319]92    def yamlDumpFaculties(self):
[278]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)
[290]107        return self.academics.temporary_view_all()
108        return self.temporary_view_all()
[319]109
[278]110    ###)
111
112    security.declareProtected(ModifyPortalContent,"loadDepartmentsFromCSV")###(
113    def loadDepartmentsFromCSV(self):
114        """install Universityspecific Faculies from CSV values"""
115        #return
[282]116        name = 'departments'
117        no_import = False
[278]118        logger = logging.getLogger('loaddepartments')
119        try:
120            deps = csv.DictReader(open("%s/import/departments.csv" % i_home,"rb"))
121        except:
[280]122            logger.error('Error reading departments.csv')
[278]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)
[282]134                if not no_import:
135                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
[287]136                    no_import.write('"Session","DeptCode","Description","FacultyCode"\n')
137                no_import.write( "No Faculty with ID: %s\n" % fid)
[282]138                no_import.write('"%(Session)s","%(DeptCode)s","%(Description)s","%(FacultyCode)s"\n' % dep)
[278]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)
[295]146                    dict = {'Title': dep['Description']}
147                    d.getContent().edit(mapping=dict)
[319]148                    d.invokeFactory('CoursesFolder','courses')
[324]149                    courses = getattr(d,'courses')
[295]150                    dict = {'Title': 'Courses'}
151                    courses.getContent().edit(mapping=dict)
[319]152                    d.invokeFactory('CertificatesFolder','certificates')
[321]153                    certificates = getattr(d,'certificates')
[295]154                    dict = {'Title': 'Certificates'}
155                    certificates.getContent().edit(mapping=dict)
[296]156        return self.academics.academics_contents()
[278]157    ###)
[319]158
[278]159    security.declareProtected(ModifyPortalContent,"loadCoursesFromCSV")###(
160    def loadCoursesFromCSV(self):
161        """install Universityspecific Courses from CSV values"""
162        #return
[282]163        name = 'courses'
164        no_import = False
[278]165        logger = logging.getLogger('loadcourses')
166        try:
167            courses = csv.DictReader(open("%s/import/courses.csv" % i_home,"rb"))
168        except:
[280]169            logger.error('Error reading courses.csv')
[278]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:
[296]182            logger.info('Processing %(CourseCode)s %(Description)s %(Credits)s %(Dept)s %(Semester)s %(Session)s %(PassMark)s %(Category)s %(AdmStatus)s' % course)
[282]183##            if course.get("FORMERCODE").endswith('BITS'):
184##                continue
[278]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)
[282]192                if not no_import:
193                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
[296]194                    no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n')
[287]195                no_import.write("Dep %(Dept)s for Course %(CourseCode)s not found\n" % course)
[296]196                no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course)
[278]197                continue
198            course_id = ''.join(re.split('\W+',course.get('CourseCode')))
199            if len(course_id) == 3:
200                course_id = "%s000" % course_id
[296]201            elif len(course_id) > 10:
[278]202                logger.info("invalid course_code %(CourseCode)s" % course)
[282]203                if not no_import:
204                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
[296]205                    no_import.write('"CourseCode","Description","Credits","Dept","Semester","Session","PassMark","Category","AdmStatus"\n')
[287]206                no_import.write("invalid course_code %(CourseCode)s\n" % course)
[296]207                no_import.write('"%(CourseCode)s","%(Description)s","%(Credits)s","%(Dept)s","%(Semester)s","%(Session)s","%(PassMark)s","%(Category)s","%(AdmStatus)s"\n' % course)
[278]208                continue
[323]209            courses = dept.courses
[295]210            c = getattr(courses,course_id,None)
[278]211            if c is None:
212                logger.info('Creating Course %(CourseCode)s  %(Description)s in Department %(Dept)s' % course)
[295]213                courses.invokeFactory('Course', course_id)
214                c = getattr(courses,course_id)
[278]215            dict = {'Title': course['Description']}
216            dict['code'] = course_id
[319]217            dict['org_code'] = course.get('CourseCode')
[282]218            dict['credits'] = course.get('Credits')
[278]219            dict['semester'] = course.get('Semester')
220            dict['session'] = course.get('Session')
221            dict['category'] = course.get('Category')
[379]222            dict['adm_status'] = course.get('AdmStatus')
223            dict['former_code'] = course.get('FORMERCODE')
[282]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
[278]233            c.getContent().edit(mapping=dict)
[296]234        return self.academics.academics_contents()
[278]235    ###)
236
237    security.declareProtected(ModifyPortalContent,"loadCertificatesFromCSV")###(
[290]238
[278]239    def loadCertificatesFromCSV(self):
240        """install Universityspecific Certificates from CSV values"""
241        #return
[287]242        name = 'certificates'
243        no_import = False
[278]244        logger = logging.getLogger('loadcertificates')
245        try:
246            certificates = csv.DictReader(open("%s/import/certificates.csv" % i_home,"rb"))
247        except:
[280]248            logger.error('Error reading certificates.csv')
[278]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)
[287]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)
[278]267                continue
268            if not deps.has_key(depid):
269                logger.info('Department %(Dept)s for %(CertCode)s %(Description)s not found' % certificate)
[287]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)
[278]275                continue
[296]276            #certificate_id = "%(category)s_%(Admstatus)s_%(Dept)s" % certificate
[278]277            dep = deps[depid]
[323]278            certificates = dep.certificates
[361]279            code = makeCertificateCode(certificate.get('CertCode'))
[296]280            certificate_id = code
[295]281            c = getattr(certificates,certificate_id,None)
[278]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)
[295]285                certificates.invokeFactory('Certificate', certificate_id)
286                c = getattr(certificates,certificate_id)
[370]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')
[382]309            print
[278]310            c.getContent().edit(mapping=dict)
[296]311        return self.academics.academics_contents()
[278]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')
[290]319        name = 'certificate_courses'
320        no_import = False
[278]321        try:
322            cert_courses = csv.DictReader(open("%s/import/course_level_courses.csv" % i_home,"rb"))
323        except:
[280]324            logger.error('Error reading course_level_courses.csv')
[278]325            return
326        d_ids = [d.id for d in self.portal_catalog({'meta_type': "Department"})]
[290]327        c_ids = [c.id for c in self.portal_catalog({'meta_type': "Course"})]
[296]328        l = self.portal_catalog({'meta_type': "Certificate"})
329        certs = {}
330        for f in l:
331            certs[f.id] = f.getObject()
[278]332        for cert_course in cert_courses:
[296]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)
[278]334            depid = cert_course.get('Dept')
[290]335            course_code = cert_course.get('CosCode')
[278]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('_','')
[290]343##            if cert_course.get('Session') != '2002/2003':
344##                continue
[296]345##            certificate = self.portal_catalog({'meta_type': "Certificate",
346##                                               'SearchableText': code})
347##            if not certificate:
348            if not code in certs.keys():
[290]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")
[296]354                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
[290]355                no_import.write(em)
[296]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)
[278]357                continue
[309]358            certificate = certs[code]
[278]359            certificate_code = certificate.getId()
[290]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")
[296]365                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
[290]366                no_import.write(em)
[296]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)
[290]368                continue
[278]369            if depid not in d_ids:
[290]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")
[296]374                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
[290]375                no_import.write(em)
[296]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)
[278]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)
[329]385                l.getContent().edit(mapping={'Title': "Level %s" % level})
[278]386                l.invokeFactory('Semester','first')
387                l.invokeFactory('Semester','second')
[290]388            certificate.orderObjects('id')
[278]389            first_s = getattr(l,'first')
[332]390            first_s.getContent().edit(mapping={'Title': 'First Semester'})
[278]391            second_s = getattr(l,'second')
[332]392            second_s.getContent().edit(mapping={'Title': 'Second Semester'})
[278]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)
[290]399                if not no_import:
400                    no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
[296]401                    no_import.write('"CosCode","CertCode","Session","Level","Core","Elective","Mandatory","AdmStatus","Dept","Semester"\n')
[295]402##                no_import.write('Duplicate %(CosCode)s in Level %(Level)s' % cert_course)
[296]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)
[278]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
[319]410            dict['certificate_code_org'] = cert_course.get('CertCode')
411            dict['department'] = cert_course.get('Dept')
[278]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')
[295]419            cc.getContent().edit(mapping=dict)
[296]420        return self.academics.academics_contents()
[278]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
[256]432class Certificate(CPSDocument): ###(
[238]433    """
[319]434    WAeUP Certificate
[238]435    """
[256]436    meta_type = 'Certificate'
[238]437    portal_type = meta_type
438    security = ClassSecurityInfo()
[319]439
[238]440    def __init__(self, id, **kw):
441        CPSDocument.__init__(self, id, **kw)
442
[256]443##    security.declareProtected(View,"Title")
444##    def Title(self):
445##        """compose title"""
446##        return "Certificate of %s" % (self.title)
[238]447
[256]448InitializeClass(Certificate)
[238]449
[256]450def addCertificate(container, id, REQUEST=None, **kw):
451    """Add a Certificate."""
452    ob = Certificate(id, **kw)
[238]453    return CPSBase_adder(container, ob, REQUEST=REQUEST)
454
455###)
456
[256]457class CertificateCourse(CPSDocument): ###(
[238]458    """
[319]459    WAeUP CertificateCourse
[238]460    """
[256]461    meta_type = 'CertificateCourse'
[238]462    portal_type = meta_type
463    security = ClassSecurityInfo()
[319]464
[279]465    def getCourseEntry(self,cid):
466        res = self.portal_catalog({'meta_type': "Course",
467                                           'id': cid})
468        if res:
[319]469            return res[-1]
[279]470        else:
471            return None
[319]472
[256]473    security.declareProtected(View,"Title")
474    def Title(self):
475        """compose title"""
[368]476        ce = self.getCourseEntry(self.id.upper())
[279]477        if ce:
478            return "%s" % ce.Title
479        return "No such course"
[238]480
[279]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
[280]487        return "0"
[319]488
[279]489    security.declareProtected(View,"passmark")
490    def passmark(self):
491        """passmark from course"""
492        ce = self.getCourseEntry(self.id)
[296]493        if ce is not None and hasattr(ce,"passmark"):
494            return ce.passmark
[319]495
496
[280]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 "?"
[279]504
[319]505
[256]506InitializeClass(CertificateCourse)
[238]507
[256]508def addCertificateCourse(container, id, REQUEST=None, **kw):
509    """Add a CertificateCourse."""
510    ob = CertificateCourse(id, **kw)
[238]511    return CPSBase_adder(container, ob, REQUEST=REQUEST)
512###)
513
[68]514class Faculty(CPSDocument): ###(
515    """
[319]516    WAeUP Faculty containing Departments
[68]517    """
518    meta_type = 'Faculty'
519    portal_type = meta_type
520    security = ClassSecurityInfo()
[319]521
[238]522##    def __init__(self, id, **kw):
523##        CPSDocument.__init__(self, id, **kw)
[173]524
[200]525    security.declareProtected(View,"Title")
526    def Title(self):
527        """compose title"""
[238]528        return "%s" % (self.title)
[319]529
[389]530
[296]531    security.declareProtected(View,"LongTitle")
532    def LongTitle(self):
533        """compose long_title"""
[389]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")
[296]539        return "%s %s" % (itype,self.title)
[200]540
[68]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()
[173]557
[296]558    security.declareProtected(View,"LongTitle")
559    def LongTitle(self):
560        """compose long_title"""
[389]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")
[296]566        return "%s %s" % (itype,self.title)
567
[68]568InitializeClass(Department)
569
570def addDepartment(container, id, REQUEST=None, **kw):
571    """Add a Department."""
[296]572    object = Department(id, **kw)
[295]573    id = object.getId()
[319]574    container._setObject(id, object)
[309]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)
[295]584    if REQUEST is not None:
585        url = container.absolute_url()
586        REQUEST.RESPONSE.redirect('%s/manage_main' % url)
[309]587
[68]588###)
589
590class Course(CPSDocument): ###(
591    """
[319]592    WAeUP Course
[68]593    """
594    meta_type = 'Course'
595    portal_type = meta_type
596    security = ClassSecurityInfo()
[152]597
598    security.declareProtected(View,"Title")
599    def Title(self):
600        """compose title"""
[238]601        return self.title
[319]602
[68]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###)
[139]610
611class CourseTicket(CPSDocument): ###(
612    """
[319]613    WAeUP CourseTicket
[139]614    """
615    meta_type = 'CourseTicket'
616    portal_type = meta_type
617    security = ClassSecurityInfo()
[398]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
[319]625
[398]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
[139]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###)
[256]641
Note: See TracBrowser for help on using the repository browser.