source: WAeUP_SRP/trunk/Students.py @ 504

Last change on this file since 504 was 502, checked in by joachim, 18 years ago

Scratchcard Pin Generation
basic login in apply_admission

  • Property svn:keywords set to Id
File size: 26.7 KB
Line 
1#-*- mode: python; mode: fold -*-
2# $Id: Students.py 502 2006-09-11 10:39:59Z joachim $
3from Globals import InitializeClass
4from AccessControl import ClassSecurityInfo
5from AccessControl.SecurityManagement import newSecurityManager
6from zExceptions import BadRequest
7from Products.ZCatalog.ZCatalog import ZCatalog
8from Products.CMFCore.utils import UniqueObject, getToolByName
9from Products.CMFCore.permissions import View
10from Products.CMFCore.permissions import ModifyPortalContent
11from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder
12#from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument
13from Products.CPSDocument.CPSDocument import CPSDocument
14from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder
15from Products.CPSCore.CPSMembershipTool import CPSUnrestrictedUser
16from Products.WAeUP_SRP.Academics import makeCertificateCode
17import logging
18import csv,re
19import Globals
20p_home = Globals.package_home(globals())
21i_home = Globals.INSTANCE_HOME
22MAX_TRANS = 1000
23
24def generateStudentId():
25    import random
26    r = random
27    return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000))
28
29def getStudentByRegNo(self,reg_no):
30    """search student by JAMB Reg No and return StudentFolder"""
31    search = ZCatalog.searchResults(self.portal_catalog,{'meta_type': 'StudentApplication',
32                                  'jamb_reg_no': reg_no,
33                                  })
34    if len(search) < 1:
35        return None
36    return search[0].getObject().aq_parent
37
38class StudentsFolder(CPSDocument): ###(
39    """
40    WAeUP container for the various WAeUP containers data
41    """
42    meta_type = 'StudentsFolder'
43    portal_type = meta_type
44    security = ClassSecurityInfo()
45
46    security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsFromCSV")###(
47    def loadFullTimeStudentsFromCSV(self):
48        """load Fulltime Studentdata from CSV values"""
49        #return
50        import transaction
51        tr_count = 0
52        name = 'short_full_time'
53        no_import = False
54        if not no_import:
55            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
56            no_import.write('"MatricNo","EntryRegNo","CurrentSession","StudentLevel","fullname","FirstName","MiddleName","Lastname","FormerSurname","Sex","Nationality","State","LGA","PermanentAddress","PermanentAddressCity","CampusAddress","PhoneNumber","Emailaddress","Mode","CourseMajor","Faculty","Dept"\n')
57        logger = logging.getLogger('%s_import' % name)
58        logger.info('Start loading from %s.csv' % name)
59        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
60        try:
61            students = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
62        except:
63            logger.error('Error reading %s.csv' % name)
64            return
65        l = self.portal_catalog({'meta_type': "StudentClearance",})
66        matrics = []
67        for s in l:
68            matrics.append(s.getObject().getContent().matric_no)
69        print matrics
70        l = self.portal_catalog({'meta_type': "Certificate"})
71        certs = {}
72        for c in l:
73            certs[c.id] = c.getObject()
74        for student in students:
75            logger.info('processing "%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
76            sid = student.get('MatricNo')
77            if sid == "":
78                em = 'Empty MatricNo\n'
79                logger.info(em)
80                no_import.write(em)
81                no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
82                continue
83            certcode = makeCertificateCode(student.get('CourseMajor'))
84            if certcode not in certs.keys():
85                em = 'Certificate with ID %s %s not found\n' % (certcode, student.get('CourseMajor'))
86                logger.info(em)
87                no_import.write(em)
88                no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
89                continue
90            level = student.get('StudentLevel')
91            try:
92                int(level)
93            except:
94                em = 'Student with ID %(MatricNo)s StudentLevel is empty\n' % student
95                logger.info(em)
96                no_import.write(em)
97                no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
98                continue
99            matric_no = student.get('MatricNo')
100            if matric_no not in matrics:
101                matrics.append(matric_no)
102                sid = generateStudentId()
103                #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
104                logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars())
105                not_created = True
106                while not_created:
107                    try:
108                        students_folder.invokeFactory('Student', sid)
109                        not_created = False
110                    except BadRequest:
111                        sid = generateStudentId()
112                logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars())
113                s = getattr(self,sid)
114                self.portal_registration.addMember(sid,
115                                                   'uNsEt' ,
116                                                   roles=('Member',
117                                                          'Student',))
118                s.invokeFactory('StudentApplication','application')
119                da = {'Title': 'Application Data'}
120                s.invokeFactory('StudentPersonal','personal')
121                da['jamb_reg_no'] = student.get('EntryRegNo')
122                sp = s.personal
123                d = {'Title': 'Personal Data'}
124                s.invokeFactory('StudentClearance','clearance')
125                sc = s.clearance
126                dc = {'Title': 'Clearance Data'}
127                dc['matric_no'] = matric_no
128                lga = student.get('State') + ' / ' + student.get('LGA')
129                dc['lga'] = lga
130                dc['nationality'] = student.get('Nationality')
131                dc['email'] = student.get('Emailaddress')
132                d['firstname'] = student.get('FirstName')
133                d['middlename'] = student.get('MiddleName')
134                d['lastname'] = student.get('Lastname')
135                d['former_surname'] = student.get('FormerSurname')
136                d['sex'] = student.get('Sex') == 'F'
137                d['perm_address'] = student.get('PermanentAddress')
138                d['perm_city'] = student.get('PermanentAddressCity')
139                d['campus_address'] = student.get('CampusAddress')
140                d['phone'] = student.get('PhoneNumber')
141                s.application.getContent().edit(mapping=da)
142                sp.getContent().edit(mapping=d)
143                sc.getContent().edit(mapping=dc)
144                #
145                # Study Course
146                #
147                s.invokeFactory('StudentStudyCourse','study_course')
148                sc = s.study_course
149                d = {}
150                #d['matricel_no'] = student.get('MatricNo')
151                #d['entry_reg_no'] = student.get('EntryRegNo')
152                #d['faculty'] = student.get('Faculty')
153                #d['department'] = student.get('Dept')
154                d['study_course'] = certcode
155                css = student.get('CurrentSession') or '2004-2005'
156                cs = int(css.split('-')[0]) - 2000
157                cl = int(student.get('StudentLevel'))/100
158                d['entry_session'] = "200%s" % (cs - cl)
159                sc.getContent().edit(mapping=d)
160                #
161                # Level
162                #
163                l = getattr(sc,level,None)
164                if l is None:
165                    #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
166                    logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student)
167                    sc.invokeFactory('StudentStudyLevel', level)
168                    l = getattr(sc, level)
169                    certificate = certs[certcode]
170                    cert_level = getattr(certificate,level,None)
171                    if cert_level is None:
172                        logger.info('Level %(level)s not in %(certcode)s' % vars())
173                    l.getContent().edit(mapping={'Title': "Level %s" % level})
174                    l.invokeFactory('StudentSemester','first')
175                    l.invokeFactory('StudentSemester','second')
176                    first_s = getattr(l,'first')
177                    first_s.getContent().edit(mapping={'Title': 'First Semester'})
178                    second_s = getattr(l,'second')
179                    second_s.getContent().edit(mapping={'Title': 'Second Semester'})
180            else:
181                em = 'Student with ID %(MatricNo)s %(fullname)s already exists\n' % student
182                logger.info(em)
183                no_import.write(em)
184                no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
185            if tr_count > MAX_TRANS:
186                transaction.commit()
187                em = 'Transaction commited\n' % student
188                logger.info(em)
189                tr_count = 0
190            tr_count += 1
191        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
192        return self.students.academics_contents()
193    ###)
194
195    security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsResultsFromCSV") ###(
196    def loadFullTimeStudentsResultsFromCSV(self):
197        """load Fulltime Studentdata from CSV values"""
198        #return
199        import transaction
200        tr_count = 0
201        name = 'short_full_time_results_2004_2005'
202        no_import = False
203        if not no_import:
204            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
205            no_import.write('"Matnumber","CosCode","Ansbook","CosStuatus","Session","Mat_Cos","Score","CarryLevel","Grade","Weight","Semster","Verdict","Level","id","GPA"\n')
206        logger = logging.getLogger('%s_import' % name)
207        logger.info('Start loading from %s.csv' % name)
208        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
209        try:
210            results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
211        except:
212            logger.error('Error reading %s.csv' % name)
213            return
214        l = self.portal_catalog({'meta_type': "Course"})
215        courses = {}
216        for c in l:
217            courses[c.id] = c.getObject()
218        for result in results:
219            sid = result.get('Matnumber')
220            res = self.portal_catalog({'meta_type': "StudentClearance",
221                                     'matric_no': sid })
222            if not res:
223                em = 'Student with ID %(Matnumber)s not found\n' % result
224                logger.info(em)
225                no_import.write(em)
226                no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result)
227                continue
228            sf = res[0].getObject().aq_parent
229            result['StudentId'] = sf.getId()
230            course = result.get('CosCode')
231            if course not in courses.keys():
232                em = 'Course with ID %(CosCode)s not found\n' % result
233                logger.info(em)
234                no_import.write(em)
235                no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result)
236                continue
237            level = result.get('Level')
238            try:
239                int(level)
240            except:
241                em = 'Result for result with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % result
242                logger.info(em)
243                no_import.write(em)
244                no_import.write('"%(Matnumber)s","%(CosCode)s","%(Ansbook)s","%(CosStuatus)s","%(Session)s","%(Mat_Cos)s","%(Score)s","%(CarryLevel)s","%(Grade)s","%(Weight)s","%(Semster)s","%(Verdict)s","%(Level)s","%(id)s","%(GPA)s"\n' % result)
245                continue
246            sc = getattr(sf,'study_course')
247            l = getattr(sc,level,None)
248            if l is None:
249                #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
250                logger.info('Creating Level %(Level)s for %(StudentId)s %(Matnumber)s' % result)
251                sc.invokeFactory('StudentStudyLevel', level)
252                l = getattr(sc, level)
253                l.invokeFactory('StudentSemester','first')
254                l.invokeFactory('StudentSemester','second')
255                first_s = getattr(l,'first')
256                first_s.getContent().edit(mapping={'Title': 'First Semester'})
257                second_s = getattr(l,'second')
258                second_s.getContent().edit(mapping={'Title': 'Second Semester'})
259            snr = result.get('Semster')
260            semester = getattr(l,'first')
261            if snr == "2":
262                semester = getattr(l,'second')
263            logger.info('Creating StudentCourseResult %(CosCode)s in Level %(Level)s for %(StudentId)s %(Matnumber)s' % result)
264            semester.invokeFactory('StudentCourseResult',course)
265            ct = getattr(semester,course)
266            d = {}
267            dlev = {}
268            d['ansbook'] = result.get('Ansbook')
269            d['status'] = result.get('CosStuatus')
270            d['score'] = result.get('Score')
271            dlev['session'] = result.get('Session')
272            dlev['carry_level'] = result.get('CarryLevel')
273            d['grade'] = result.get('Grade')
274            #d['weight'] = result.get('Weight')
275            dlev['verdict'] = result.get('Verdict')
276            #d['import_id'] = result.get('id')
277            #gpa = result.get('GPA').replace(',','.')
278            #d['gpa'] = float(gpa)
279            ct.getContent().edit(mapping = d)
280            l.getContent().edit(mapping = dlev)
281            if tr_count > MAX_TRANS:
282                transaction.commit()
283                tr_count = 0
284            tr_count += 1
285        return self.students.academics_contents()
286
287###)
288
289    security.declareProtected(ModifyPortalContent,"loadJAMBFromCSV")###(
290    def loadJAMBFromCSV(self):
291        """load JAMB data from CSV values"""
292        #return
293        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
294        import transaction
295        tr_count = 0
296        name = 'SampleJAMBDataII'
297        no_import = False
298        if not no_import:
299            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
300            no_import.write('REG-NO,NAME,SEX,STATE,LGA,ENG-SCORE,SUBJ1,SUBJ1-SCORE,SUBJ2,SUBJ2-SCORE,SUBJ3,SUBJ3-SCORE,AGGREGATE,UNIV1,FACULTY1,COURSE1,UNIV2,FACULTY2,COURSE2')
301        logger = logging.getLogger('%s_import' % name)
302        logger.info('Start loading from %s.csv' % name)
303        try:
304            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
305        except:
306            logger.error('Error reading %s.csv' % name)
307            return
308        for jamb in result:
309            logger.info('processing %(REG-NO)s,%(NAME)s,%(SEX)s,%(STATE)s,%(LGA)s,%(ENG-SCORE)s,%(SUBJ1)s,%(SUBJ1-SCORE)s,%(SUBJ2)s,%(SUBJ2-SCORE)s,%(SUBJ3)s,%(SUBJ3-SCORE)s,%(AGGREGATE)s,%(UNIV1)s,%(FACULTY1)s,%(COURSE1)s,%(UNIV2)s,%(FACULTY2)s,%(COURSE2)s\n' % jamb)
310            jamb_reg_no = jamb.get('REG-NO')
311            res = self.portal_catalog({'meta_type': "StudentApplication",
312                                     'jamb_reg_no': jamb_reg_no })
313            if res:
314                em = 'Student with REG-NO %(REG-NO)s already exists\n' % jamb
315                logger.info(em)
316                no_import.write(em)
317                no_import.write('%(REG-NO)s,%(NAME)s,%(SEX)s,%(STATE)s,%(LGA)s,%(ENG-SCORE)s,%(SUBJ1)s,%(SUBJ1-SCORE)s,%(SUBJ2)s,%(SUBJ2-SCORE)s,%(SUBJ3)s,%(SUBJ3-SCORE)s,%(AGGREGATE)s,%(UNIV1)s,%(FACULTY1)s,%(COURSE1)s,%(UNIV2)s,%(FACULTY2)s,%(COURSE2)s\n' % jamb)
318                continue
319            sid = generateStudentId()
320            #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
321            not_created = True
322            while not_created:
323                try:
324                    students_folder.invokeFactory('Student', sid)
325                    not_created = False
326                except BadRequest:
327                    sid = generateStudentId()
328            logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
329            s = getattr(self,sid)
330            self.portal_registration.addMember(sid,
331                                               'uNsEt' ,
332                                               roles=('Member',
333                                                      'Student',))
334            s.invokeFactory('StudentApplication','application')
335            da = {'Title': 'Application Data'}
336##            s.invokeFactory('StudentPersonal','personal')
337##            sp = s.personal
338##            d = {'Title': 'Personal Data'}
339##            s.invokeFactory('StudentClearance','clearance')
340##            sc = s.clearance
341##            dc = {'Title': 'Clearance Data'}
342            da["jamb_reg_no"] = jamb.get("REG-NO")
343            da["jamb_lastname"] = jamb.get("NAME")
344##            d["lastname"] = jamb.get("NAME")
345            da["jamb_sex"] = jamb.get("SEX")
346            da["jamb_state"] = jamb.get("STATE")
347            da["jamb_lga"] = jamb.get("LGA")
348            da["jamb_score"] = jamb.get("AGGREGATE")
349            da["jamb_first_cos"] = jamb.get("COURSE1")
350            da["jamb_second_cos"] = jamb.get("COURSE2")
351            da["jamb_first_uni"] = jamb.get("UNIV1")
352            da["jamb_second_uni"] = jamb.get("UNIV2")
353##            s.personal.getContent().edit(mapping=d)
354            s.application.getContent().edit(mapping=da)
355            s.application.getContent().content_status_modify(workflow_action="open")
356            s.application.manage_setLocalRoles(s_id, ['Owner',])
357        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
358    ###)
359
360
361    security.declareProtected(View,"Title")
362    def Title(self):
363        """compose title"""
364        return "Student Section"
365
366InitializeClass(StudentsFolder)
367
368def addStudentsFolder(container, id, REQUEST=None, **kw):
369    """Add a Student."""
370    ob = StudentsFolder(id, **kw)
371    return CPSBase_adder(container, ob, REQUEST=REQUEST)
372###)
373
374class Student(CPSDocument): ###(
375    """
376    WAeUP Student container for the various student data
377    """
378    meta_type = 'Student'
379    portal_type = meta_type
380    security = ClassSecurityInfo()
381
382    security.declareProtected(View,"Title")
383    def Title(self):
384        """compose title"""
385        reg_nr = self.getId()[1:]
386        data = getattr(self,'personal',None)
387        if data:
388            content = data.getContent()
389            return "%s %s" % (content.firstname,content.lastname)
390        data = getattr(self,'application',None)
391        if data:
392            content = data.getContent()
393            return "%s" % (content.jamb_lastname)
394        return self.title
395
396InitializeClass(Student)
397
398def addStudent(container, id, REQUEST=None, **kw):
399    """Add a Student."""
400    ob = Student(id, **kw)
401    return CPSBase_adder(container, ob, REQUEST=REQUEST)
402
403###)
404
405class StudentPersonal(CPSDocument): ###(
406    """
407    WAeUP Student container for the various student data
408    """
409    meta_type = 'StudentPersonal'
410    portal_type = meta_type
411    security = ClassSecurityInfo()
412
413    security.declareProtected(View,"Title")
414    def Title(self):
415        """compose title"""
416        content = self.getContent()
417        #return "Personal Data for %s %s" % (content.firstname,content.lastname)
418        return "Personal Data"
419
420
421InitializeClass(StudentPersonal)
422
423def addStudentPersonal(container, id, REQUEST=None, **kw):
424    """Add a Students personal data."""
425    ob = StudentPersonal(id, **kw)
426    return CPSBase_adder(container, ob, REQUEST=REQUEST)
427
428###)
429
430class StudentClearance(CPSDocument): ###(
431    """
432    WAeUP Student container for the various student data
433    """
434    meta_type = 'StudentClearance'
435    portal_type = meta_type
436    security = ClassSecurityInfo()
437
438    security.declareProtected(View,"Title")
439    def Title(self):
440        """compose title"""
441        content = self.getContent()
442        #return "Clearance Data for %s %s" % (content.firstname,content.lastname)
443        return "Clearance Data"
444
445
446InitializeClass(StudentClearance)
447
448def addStudentClearance(container, id, REQUEST=None, **kw):
449    """Add a Students personal data."""
450    ob = StudentClearance(id, **kw)
451    return CPSBase_adder(container, ob, REQUEST=REQUEST)
452
453###)
454
455class StudyLevel(CPSDocument): ###(
456    """
457    WAeUP StudyLevel containing the courses and students
458    """
459    meta_type = 'StudyLevel'
460    portal_type = meta_type
461    security = ClassSecurityInfo()
462
463    security.declareProtected(View,"Title")
464    def Title(self):
465        """compose title"""
466        return "Level %s" % self.aq_parent.getId()
467
468
469InitializeClass(StudyLevel)
470
471def addStudyLevel(container, id, REQUEST=None, **kw):
472    """Add a StudyLevel."""
473    ob = StudyLevel(id, **kw)
474    return CPSBase_adder(container, ob, REQUEST=REQUEST)
475
476###)
477
478class StudentStudyLevel(CPSDocument): ###(
479    """
480    WAeUP Student container for the various student data
481    """
482    meta_type = 'StudentStudyLevel'
483    portal_type = meta_type
484    security = ClassSecurityInfo()
485
486    security.declareProtected(View,"Title")
487    def Title(self):
488        """compose title"""
489        return "Level %s" % self.aq_parent.getId()
490
491    security.declareProtected(View,"gpa")
492    def gpa(self):
493        """calculate the gpa"""
494        sum = 0
495        course_count = 0
496        for semester in ('first','second'):
497            sf=getattr(self,semester)
498            for sc in sf.objectValues():
499                result = sc.getContent()
500                res = self.portal_catalog({'meta_type': 'Course',
501                                              'id': sc.aq_parent.id})
502                if len(res) != 1:
503                    continue
504                course = res[0].getObject().getContent()
505                sum += course.credits * ['F','E','D','C','B','A'].index(result.grade)
506                course_count += 1
507        if course_count:
508            return sum/course_count
509        return 0.0
510
511InitializeClass(StudentStudyLevel)
512
513def addStudentStudyLevel(container, id, REQUEST=None, **kw):
514    """Add a Students personal data."""
515    ob = StudentStudyLevel(id, **kw)
516    return CPSBase_adder(container, ob, REQUEST=REQUEST)
517
518###)
519
520class StudentStudyCourse(CPSDocument): ###(
521    """
522    WAeUP Student container for the various student data
523    """
524    meta_type = 'StudentStudyCourse'
525    portal_type = meta_type
526    security = ClassSecurityInfo()
527
528    security.declareProtected(View,"Title")
529    def Title(self):
530        """compose title"""
531        content = self.getContent()
532        return "Study Course"
533
534
535InitializeClass(StudentStudyCourse)
536
537def addStudentStudyCourse(container, id, REQUEST=None, **kw):
538    """Add a Students personal data."""
539    ob = StudentStudyCourse(id, **kw)
540    return CPSBase_adder(container, ob, REQUEST=REQUEST)
541
542###)
543
544class StudentApplication(CPSDocument): ###(
545    """
546    WAeUP Student container for the various student data
547    """
548    meta_type = 'StudentApplication'
549    portal_type = meta_type
550    security = ClassSecurityInfo()
551
552    security.declareProtected(View,"Title")
553    def Title(self):
554        """compose title"""
555        return "Application Data"
556
557
558InitializeClass(StudentApplication)
559
560def addStudentApplication(container, id, REQUEST=None, **kw):
561    """Add a Students eligibility data."""
562    ob = StudentApplication(id, **kw)
563    return CPSBase_adder(container, ob, REQUEST=REQUEST)
564
565###)
566
567class StudentSemester(CPSDocument): ###(
568    """
569    WAeUP StudentSemester containing the courses and students
570    """
571    meta_type = 'StudentSemester'
572    portal_type = meta_type
573    security = ClassSecurityInfo()
574
575InitializeClass(StudentSemester)
576
577def addStudentSemester(container, id, REQUEST=None, **kw):
578    """Add a StudentSemester."""
579    ob = StudentSemester(id, **kw)
580    return CPSBase_adder(container, ob, REQUEST=REQUEST)
581
582###)
583
584class Semester(CPSDocument): ###(
585    """
586    WAeUP Semester containing the courses and students
587    """
588    meta_type = 'Semester'
589    portal_type = meta_type
590    security = ClassSecurityInfo()
591
592InitializeClass(Semester)
593
594def addSemester(container, id, REQUEST=None, **kw):
595    """Add a Semester."""
596    ob = Semester(id, **kw)
597    return CPSBase_adder(container, ob, REQUEST=REQUEST)
598
599###)
600
601class StudentCourseResult(CPSDocument): ###(
602    """
603    WAeUP StudentCourseResult
604    """
605    meta_type = 'StudentCourseResult'
606    portal_type = meta_type
607    security = ClassSecurityInfo()
608
609    def getCourseEntry(self,cid):
610        res = self.portal_catalog({'meta_type': "StudentCourse",
611                                           'id': cid})
612        if res:
613            return res[-1]
614        else:
615            return None
616
617    security.declareProtected(View,"Title")
618    def Title(self):
619        """compose title"""
620        cid = self.getId()
621        ce = self.getCourseEntry(cid)
622        if ce:
623            return "%s" % ce.Title
624        return "No course with id %s" % cid
625
626InitializeClass(StudentCourseResult)
627
628def addStudentCourseResult(container, id, REQUEST=None, **kw):
629    """Add a StudentCourseResult."""
630    ob = StudentCourseResult(id, **kw)
631    return CPSBase_adder(container, ob, REQUEST=REQUEST)
632###)
633
Note: See TracBrowser for help on using the repository browser.