source: WAeUP_SRP/trunk/Students.py @ 461

Last change on this file since 461 was 459, checked in by Henrik Bettermann, 18 years ago

importing sex to personal too

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