source: WAeUP_SRP/trunk/Students.py @ 1125

Last change on this file since 1125 was 1125, checked in by joachim, 18 years ago
  • Property svn:keywords set to Id
File size: 69.0 KB
RevLine 
[57]1#-*- mode: python; mode: fold -*-
[200]2# $Id: Students.py 1125 2006-12-21 23:06:14Z joachim $
[708]3from string import Template
[45]4from Globals import InitializeClass
5from AccessControl import ClassSecurityInfo
[164]6from AccessControl.SecurityManagement import newSecurityManager
[429]7from zExceptions import BadRequest
[502]8from Products.ZCatalog.ZCatalog import ZCatalog
[47]9from Products.CMFCore.utils import UniqueObject, getToolByName
[45]10from Products.CMFCore.permissions import View
11from Products.CMFCore.permissions import ModifyPortalContent
[154]12from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder
13#from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument
14from Products.CPSDocument.CPSDocument import CPSDocument
15from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder
[164]16from Products.CPSCore.CPSMembershipTool import CPSUnrestrictedUser
[361]17from Products.WAeUP_SRP.Academics import makeCertificateCode
[362]18import logging
[971]19import csv,re,os
[362]20import Globals
21p_home = Globals.package_home(globals())
22i_home = Globals.INSTANCE_HOME
[981]23MAX_TRANS = 1000
[966]24import DateTime
[971]25import PIL.Image
26from StringIO import StringIO
[154]27
[958]28def makeCertificateCode(code): ###(
29    code = code.replace('.','')
30    code = code.replace('(','')
31    code = code.replace(')','')
32    code = code.replace('/','')
33    code = code.replace(' ','')
34    code = code.replace('_','')
35    return code
36
37###)
38
39def getInt(s): ###(
[723]40    try:
41        return int(s)
42    except:
43        return 0
[422]44
[725]45def getFloat(s):
46    try:
47        return float(s)
48    except:
49        return 0.0
50
[958]51###)
52
[714]53def getStudentByRegNo(self,reg_no): ###(
[502]54    """search student by JAMB Reg No and return StudentFolder"""
55    search = ZCatalog.searchResults(self.portal_catalog,{'meta_type': 'StudentApplication',
[606]56                                  'SearchableText': reg_no,
[502]57                                  })
58    if len(search) < 1:
59        return None
60    return search[0].getObject().aq_parent
61
[714]62###)
63
[1111]64def checkJambNo(jnr):
65    try:
66        if len(jnr) != 10:
67            return False
68    except:
69        return False
70    try:
71        int(jnr[:8])
72        return True
73    except:
74        return False
[1119]75
[361]76class StudentsFolder(CPSDocument): ###(
77    """
78    WAeUP container for the various WAeUP containers data
79    """
[362]80    meta_type = 'StudentsFolder'
[361]81    portal_type = meta_type
82    security = ClassSecurityInfo()
[154]83
[361]84    security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsFromCSV")###(
85    def loadFullTimeStudentsFromCSV(self):
86        """load Fulltime Studentdata from CSV values"""
[398]87        import transaction
[708]88        import random
[398]89        tr_count = 0
[361]90        name = 'short_full_time'
91        no_import = False
[395]92        if not no_import:
93            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
94            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')
[1082]95        logger = logging.getLogger('Import.%s' % name)
[361]96        logger.info('Start loading from %s.csv' % name)
[708]97        pwlist  = []
98        pwlist.append('"student_id","firstname","middlename","lastname","matric_no","jamb_reg_no","access_code"')
99        pwl_template = Template('"$student_id","$firstname","$middlename","$lastname","$matric_no","$jamb_reg_no","$access_code"')
[361]100        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
101        try:
102            students = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
103        except:
104            logger.error('Error reading %s.csv' % name)
105            return
[422]106        l = self.portal_catalog({'meta_type': "StudentClearance",})
107        matrics = []
[361]108        for s in l:
[422]109            matrics.append(s.getObject().getContent().matric_no)
[423]110        print matrics
[361]111        l = self.portal_catalog({'meta_type': "Certificate"})
112        certs = {}
113        for c in l:
[727]114            ca,ac,fa,dep_id,co,certcode = c.relative_path.split('/')
115            cid = "%(dep_id)s_%(certcode)s" % vars()
116            certs[cid] = c.getObject()
[361]117        for student in students:
[393]118            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)
[361]119            sid = student.get('MatricNo')
[396]120            if sid == "":
121                em = 'Empty MatricNo\n'
122                logger.info(em)
123                no_import.write(em)
124                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)
125                continue
[361]126            certcode = makeCertificateCode(student.get('CourseMajor'))
[727]127            dep_id = student.get('Dept')
128            fac_id = student.get('Faculty')
129            cid = "%(dep_id)s_%(certcode)s" % vars()
130            if cid not in certs.keys():
[393]131                em = 'Certificate with ID %s %s not found\n' % (certcode, student.get('CourseMajor'))
[361]132                logger.info(em)
[393]133                no_import.write(em)
134                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)
[361]135                continue
[727]136            certificate_doc = certs[cid].getContent()
[395]137            level = student.get('StudentLevel')
[426]138            try:
[395]139                int(level)
140            except:
141                em = 'Student with ID %(MatricNo)s StudentLevel is empty\n' % student
142                logger.info(em)
143                no_import.write(em)
144                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)
145                continue
[422]146            matric_no = student.get('MatricNo')
147            if matric_no not in matrics:
148                matrics.append(matric_no)
[714]149                sid = self.generateStudentId(student.get('Lastname')[0])
[361]150                #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
[714]151                students_folder.invokeFactory('Student', sid)
[426]152                logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars())
[714]153                student_obj = getattr(self,sid)
[708]154                access_code = "%d" % random.randint(1000000000,9999999999)
[746]155                student_obj.getContent().makeStudentMember(sid,access_code,)
[708]156                pwl_dict = {'student_id': sid,'access_code':access_code}
[714]157                student_obj.invokeFactory('StudentApplication','application')
158                application = student_obj.application
[472]159                da = {'Title': 'Application Data'}
[714]160                student_obj.invokeFactory('StudentPersonal','personal')
[446]161                da['jamb_reg_no'] = student.get('EntryRegNo')
[714]162                personal = student_obj.personal
[708]163                dp = {'Title': 'Personal Data'}
[714]164                student_obj.invokeFactory('StudentClearance','clearance')
165                clearance = student_obj.clearance
[840]166                dc = {'Title': 'Clearance/Eligibility Record'}
[422]167                dc['matric_no'] = matric_no
[714]168                state = student.get('State')
169                lga = student.get('LGA')
170                if state and lga:
171                    lga =  state + ' / ' + lga
172                else:
173                    lga = "None"
[427]174                dc['lga'] = lga
[422]175                dc['nationality'] = student.get('Nationality')
176                dc['email'] = student.get('Emailaddress')
[708]177                dp['firstname'] = student.get('FirstName')
178                dp['middlename'] = student.get('MiddleName')
179                dp['lastname'] = student.get('Lastname')
180                dp['former_surname'] = student.get('FormerSurname')
181                dp['sex'] = student.get('Sex') == 'F'
182                dp['perm_address'] = student.get('PermanentAddress')
183                dp['perm_city'] = student.get('PermanentAddressCity')
184                dp['campus_address'] = student.get('CampusAddress')
185                dp['phone'] = student.get('PhoneNumber')
[714]186                application.getContent().edit(mapping=da)
187                personal.getContent().edit(mapping=dp)
188                clearance.getContent().edit(mapping=dc)
[362]189                #
190                # Study Course
191                #
[714]192                student_obj.invokeFactory('StudentStudyCourse','study_course')
193                studycourse = student_obj.study_course
[708]194                dsc = {}
[727]195                from_certificate = ['title',
196                                   'max_elect',
197                                   'max_pass',
198                                   'n_core',
199                                   'nr_years',
200                                   'probation_credits',
201                                   'promotion_credits',
202                                   'start_level',
203                                  ]
204                for f in from_certificate:
205                    dsc[f] = getattr(certificate_doc,f)
206                dsc['faculty'] = fac_id
207                dsc['department'] = dep_id
[708]208                dsc['study_course'] = certcode
[454]209                css = student.get('CurrentSession') or '2004-2005'
210                cs = int(css.split('-')[0]) - 2000
[714]211                cl = int(student.get('StudentLevel') or '100')/100
[708]212                dsc['entry_session'] = "200%s" % (cs - cl)
213                dsc['clr_ac_pin'] = access_code
[714]214                studycourse.getContent().edit(mapping=dsc)
[364]215                #
216                # Level
217                #
[723]218##                l = getattr(studycourse,level,None)
219##                if 0 and l is None:
220##                    #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
221##                    logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student)
222##                    studycourse.invokeFactory('StudentStudyLevel', level)
223##                    l = getattr(studycourse, level)
224##                    certificate = certs[certcode]
225##                    cert_level = getattr(certificate,level,None)
226##                    if cert_level is None:
227##                        logger.info('Level %(level)s not in %(certcode)s' % vars())
228##                    l.getContent().edit(mapping={'Title': "Level %s" % level})
[361]229            else:
[393]230                em = 'Student with ID %(MatricNo)s %(fullname)s already exists\n' % student
[361]231                logger.info(em)
[393]232                no_import.write(em)
233                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)
[714]234                continue
[398]235            if tr_count > MAX_TRANS:
[422]236                transaction.commit()
237                em = 'Transaction commited\n' % student
[398]238                logger.info(em)
239                tr_count = 0
240            tr_count += 1
[708]241            pwl_dict.update(dc)
242            pwl_dict.update(da)
243            pwl_dict.update(dp)
[714]244            wftool = self.portal_workflow
[708]245            pwlist.append(pwl_template.substitute(pwl_dict))
[714]246            wftool.doActionFor(student_obj,'clear_and_validate')
[742]247            student_obj.manage_setLocalRoles(sid, ['Owner',])
[714]248            wftool.doActionFor(application,'close')
[742]249            application.manage_setLocalRoles(sid, ['Owner',])
[714]250            wftool.doActionFor(clearance,'close')
[742]251            clearance.manage_setLocalRoles(sid, ['Owner',])
[714]252            wftool.doActionFor(personal,'close')
[742]253            personal.manage_setLocalRoles(sid, ['Owner',])
[727]254            wftool.doActionFor(studycourse,'close_for_edit')
[742]255            studycourse.manage_setLocalRoles(sid, ['Owner',])
[714]256        open("%s/import/pwlist-%s.csv" % (i_home,name),"w+").write('\n'.join(pwlist))
[423]257        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
[361]258    ###)
[382]259
[742]260    security.declareProtected(ModifyPortalContent,"loadPumeResultsFromCSV")###(
261    def loadPumeResultsFromCSV(self):
[966]262        """load Fulltime Studentdata from CSV values into pumeresults catalog"""
263        import transaction
264        import random
[1111]265##        csv_d = {'jamb_reg_no': "RegNumber", ###(
266##                 'status': "Admission Status",
267##                 'name': "Name",
268##                 'score': "Score",
269##                 'sex': "Sex",
270##                 'faculty': "Faculty",
271##                 'department': "Dept",
272##                 'course': "Course",
273##                 'course_code_org': "Course Code",
274##                 }
275###)
276        csv_d = {'jamb_reg_no': "JAMBRegno",
[966]277                 'name': "Name",
278                 'score': "Score",
279                 'sex': "Sex",
[1119]280                 'course': "Course",
[966]281                 'faculty': "Faculty",
282                 'department': "Dept",
283                 'course_code_org': "Course Code",
[1111]284                 'status': "Admission Status",
285                 'result_type': None,
[966]286                 }
[1111]287        csv_fields = [f[1] for f in csv_d.items() if f[1]]
[966]288        tr_count = 0
289        total = 0
[1111]290        name = 'pup_new'
291        #name = 'pup_update'
[971]292        update = name.endswith('update')
[966]293        no_import = []
[1111]294        ok_import = []
295        ok_import.append('%s' % ','.join(['"%s"' % fn for fn in csv_d.keys()]))
296        no_import.append('%s' % ','.join(['"%s"' % fn for fn in csv_fields]))
[1005]297        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
[1111]298        ok_import_name = "%s/import/%s_imported_%s.csv" % (i_home,name,current)
299        #open(ok_import_name,"w").write('\n'.join(no_import))
[1005]300        no_import_name = "%s/import/%s_not_imported_%s.csv" % (i_home,name,current)
[1111]301        #open(no_import_name,"w").write('\n'.join(no_import))
[1082]302        logger = logging.getLogger('Import.%s' % name)
[966]303        starttime = DateTime.now()
304        logger.info('Start loading from %s.csv' % name)
305        try:
306            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
307        except:
308            logger.error('Error reading %s.csv' % name)
309            return
310        pume = self.portal_pumeresults
311        format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
[1111]312        import_format = ','.join(['"%%(%s)s"' % fn for fn in csv_d.keys()])
[1119]313        eduplicate = '%s,"duplicate"' % format
314        einvalidjamb = '%s,"invalid JambRegNo"' % format
[1005]315        added = 'added ,%s' % format
[1111]316        #from pdb import set_trace;set_trace()
[966]317        for jamb in result:
318            dict = {}
319            for f,fn in csv_d.items():
320                dict[f] = jamb.get(csv_d[f])
[1111]321            dict['result_type'] = 'DE'
322            jnr = jamb.get(csv_d['jamb_reg_no'])
323            if not checkJambNo(jnr):
324                logger.info(einvalidjamb % jamb)
325                dd = {}
326                for f,fn in csv_d.items():
327                    dd[fn] = getattr(data,f)
328                    no_import.append(eduplicate % dd)
329                    no_import.append(eduplicate % jamb)
330                continue
331            res = pume(jamb_reg_no=jnr)
[971]332            if len(res) > 0:
333                if update:
[1005]334                    try:
335                        pume.modifyRecord(**dict)
336                    except ValueError:
337                        logger.info(eduplicate % jamb)
338                        continue
339                    except KeyError:
340                        pume.addRecord(**dict)
341                        logger.info(added % jamb)
342                        continue
[971]343                else:
344                    data = res[0]
345                    if data.name != jamb.get(csv_d['name']):
346                        #set_trace()
347                        logger.info(eduplicate % jamb)
348                        #em = 'Student with REG-NO %(jamb_reg_no)s already exists\n' % dict
349                        #logger.info(em)
350                        dd = {}
351                        for f,fn in csv_d.items():
352                            dd[fn] = getattr(data,f)
353                        no_import.append(eduplicate % dd)
354                        no_import.append(eduplicate % jamb)
355                    continue
[966]356            try:
357                pume.addRecord(**dict)
[1111]358                ok_import.append(import_format % dict)
[966]359            except ValueError:
360                logger.info(eduplicate % jamb)
361                #em = 'Student with REG-NO %(jamb_reg_no)s already exists\n' % dict
362                #logger.info(em)
363                no_import.append(eduplicate % jamb)
364        logger.info('End loading from %s.csv' % name)
365        if len(no_import) > 1:
[1005]366            open(no_import_name,"w+").write('\n'.join(no_import))
[1111]367        open(ok_import_name,"w+").write('\n'.join(ok_import))
[966]368        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
[971]369    ###)
[966]370
[1121]371    security.declareProtected(ModifyPortalContent,"createDEStudents")###(
372    def createDEStudents(self):
373        """load Fulltime Studentdata from CSV values"""
374        import transaction
375        import random
376        #from pdb import set_trace
377        wftool = self.portal_workflow
378        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
379        csv_d = {'jamb_reg_no': "RegNumber",
380                 'jamb_lastname': "Name",
381                 'session': "Session",
382                 'pume_tot_score': "PUDE SCORE",
383                 ##'jamb_score': "JambScore",
384                 'entry_mode': "EntryMode",
385                 'jamb_sex': "Sex",
386                 'jamb_state': "State",
387                 'jamb_first_cos': "AdminCourse",
388                 'faculty': "AdminFaculty",
389                 'course_code': "AdmitCoscode",
390                 'stud_status':"AdmitStatus",
391                 'department': "AdmitDept",
392                 'jamb_lga': "LGA",
393                 'app_email': "email",
394                 'app_mobile': "PhoneNumbers",
395                 }
396        csv_fields = [f[1] for f in csv_d.items()]
397        tr_count = 0
398        total = 0
399        #name = 'pume_results'
400        name = 'DE_Admitted'
401        no_import = []
402        s = ','.join(['"(%s)"' % fn for fn in csv_fields])
403        no_import.append('"Error",%s' % s)
404        format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
405        no_certificate = "no certificate %s" % format
406        open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import))
407        logger = logging.getLogger('Import.%s' % name)
408        logger.info('start loading from %s.csv' % name)
409        l = self.portal_catalog({'meta_type': "Certificate"})
410        certs = {}
411        cert_docs = {}
412        for f in l:
413            certs[f.getId] = f.getObject().getContent()
414        try:
415            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
416        except:
417            logger.error('Error reading %s.csv' % name)
418            return
419        for jamb in result:
420            jamb['Error'] = "Processing "
421            logger.info(format % jamb)
422            jamb_reg_no = jamb.get(csv_d['jamb_reg_no'])
423            res = self.portal_catalog({'portal_type': "StudentApplication",
424                                     'SearchableText': jamb_reg_no })
425            if res:
426                em = 'Student with RegNo %s already exists\n' % jamb_reg_no
427                logger.info(em)
428                jamb['Error'] = "Student exists"
429                no_import.append(format % jamb)
430                continue
431            cert_id = makeCertificateCode(jamb.get(csv_d['course_code']))
432            if cert_id not in certs.keys():
433                em = 'No Certificate with ID %s \n' % cert_id
434                logger.info(em)
435                jamb['Error'] = "No Certificate %s" % cert_id
436                no_import.append( format % jamb)
437                continue
438            jamb_reg_no =jamb.get(csv_d['jamb_reg_no'])
439            cert_doc = certs[cert_id]
440            catalog_entry = {}
441            catalog_entry['jamb_reg_no'] = jamb_reg_no
442            jamb_name = jamb.get(csv_d['jamb_lastname'])
443            jamb_name.replace('>','')
444            jamb_name.replace('<','')
445            names = jamb_name.split()
446            letter = names[-1][0].upper()
447            sid = self.generateStudentId(letter)
448            not_created = True
449            while not_created:
450                try:
451                    students_folder.invokeFactory('Student', sid)
452                    not_created = False
453                except BadRequest:
454                    sid = self.generateStudentId(letter)
455            catalog_entry['id'] = sid
456            tr_count += 1
457            logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
458            student = getattr(self,sid)
459            student.manage_setLocalRoles(sid, ['Owner',])
460            student.invokeFactory('StudentPume','pume')
461            dp = {'Title': 'Pume Data'}
462            student.invokeFactory('StudentApplication','application')
463            da = {'Title': 'Application Data'}
464            da["jamb_lastname"] = jamb_name
465            da_fields = ('jamb_reg_no',
466                         'jamb_sex',
467                         'entry_mode',
468                         #'jamb_score',
469                         'jamb_first_cos',
470                         'jamb_sex',
471                         'jamb_state',
472                         'jamb_lga',
473                         'app_email',
474                         'app_mobile',
475                         )
476            for f in da_fields:
477                da[f] = jamb.get(csv_d[f])
478            catalog_entry['email'] = jamb.get(csv_d['app_email'])
479            app = student.application
480            app_doc = app.getContent()
481            picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no)
482            #import pdb;pdb.set_trace()
483            if os.path.exists(picture):
484                file = open(picture)
485                if False:
486                    img = PIL.Image.open(file)
487                    img.thumbnail((150,200),
488                                  resample=PIL.Image.ANTIALIAS)
489                    # We now need a buffer to write to. It can't be the same
490                    # as the inbuffer as the PNG writer will write over itself.
491                    outfile = StringIO()
492                    img.save(outfile, format=img.format)
493                else:
494                    outfile = file.read()
495                app_doc.manage_addFile('passport',
496                                       file=outfile,
497                                       title="%s.jpg" % jamb_reg_no)
498            app.getContent().edit(mapping=da)
499            app.manage_setLocalRoles(sid, ['Owner',])
500            #wftool.doActionFor(app,'close')
501            dp_fields = (
502                         #'pume_eng_score',
503                         #'pume_gen_score',
504                         'pume_tot_score',
505                         )
506            dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded"
507            pume = student.pume
508            pume.getContent().edit(mapping=dp)
509            #wftool.doActionFor(pume,'close')
510            pume.manage_setLocalRoles(sid, ['Owner',])
511            #student.getContent().createSubObjects()
512            dp = {}
513            if len(names) == 3:
514                dp['firstname'] = names[0].capitalize()
515                dp['middlename'] = names[1].capitalize()
516                dp['lastname'] = names[2].capitalize()
517            elif len(names) == 2:
518                dp['firstname'] = names[0].capitalize()
519                dp['middlename'] = ''
520                dp['lastname'] = names[1].capitalize()
521            else:
522                dp['firstname'] = ''
523                dp['middlename'] = ''
524                dp['lastname'] = jamb_name
525            dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F'
526            catalog_entry['sex'] = dp['sex']
527            catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp
528            student.invokeFactory('StudentPersonal','personal')
529            per = student.personal
530            per_doc = per.getContent()
531            per_doc.edit(mapping = dp)
532            per.manage_setLocalRoles(sid, ['Owner',])
533            if jamb.get(csv_d['stud_status']) == "Admitted":
534                wftool.doActionFor(student,'pume_pass')
535                wftool.doActionFor(student,'admit')
536            else:
537                wftool.doActionFor(student,'pume_fail')
538                wftool.doActionFor(student,'reject_admission')
539                continue
540            #
541            # Clearance
542            #
543            student.invokeFactory('StudentClearance','clearance')
544            #wftool.doActionFor(student.clearance,'open')
545            dp = {'Title': 'Clearance/Eligibility Record'}
546            student.clearance.manage_setLocalRoles(sid, ['Owner',])
547            #
548            # Study Course
549            #
550            student.invokeFactory('StudentStudyCourse','study_course')
551            study_course = student.study_course
552            dsc = {}
553            from_certificate = ['title',
554                               'max_elect',
555                               'max_pass',
556                               'n_core',
557                               'nr_years',
558                               'probation_credits',
559                               'promotion_credits',
560                               'start_level',
561                              ]
562            for f in from_certificate:
563                dsc[f] = getattr(cert_doc,f)
564            dsc['faculty'] = jamb.get(csv_d['faculty'])
565            dsc['department'] = jamb.get(csv_d['department'])
566            catalog_entry['faculty'] = jamb.get(csv_d['faculty'])
567            catalog_entry['department'] = jamb.get(csv_d['department'])
568            catalog_entry['course'] = cert_id
569            catalog_entry['level'] = getattr(cert_doc,'start_level')
570            dsc['study_course'] = cert_id
571            dsc['entry_session'] = jamb.get(csv_d['session'])
572            study_course.getContent().edit(mapping=dsc)
573            self.students_catalog.addRecord(**catalog_entry)
[1124]574            if tr_count > 10:
[1121]575                if len(no_import) > 1:
576                    open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write(
577                             '\n'.join(no_import))
578                    no_import = []
579                em = '%d transactions commited\n' % tr_count
580                transaction.commit()
581                logger.info(em)
582                total += tr_count
583                tr_count = 0
[1125]584        open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write(
585                                               '\n'.join(no_import))
[1121]586        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
587    ###)
588
[966]589    security.declareProtected(ModifyPortalContent,"createNewStudents")###(
590    def createNewStudents(self):
[742]591        """load Fulltime Studentdata from CSV values"""
592        import transaction
593        import random
[971]594        #from pdb import set_trace
[763]595        wftool = self.portal_workflow
[757]596        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
[971]597        csv_d = {'jamb_reg_no': "RegNumber",
[958]598                 'jamb_lastname': "Name",
[971]599                 'session': "Session",
600                 'pume_tot_score': "PUME SCORE",
601                 'jamb_score': "JambScore",
[958]602                 'jamb_sex': "Sex",
[971]603                 'jamb_state': "State",
[980]604##                 'jamb_first_cos': "AdminCourse",
[971]605                 'faculty': "AdminFaculty",
606                 'course_code': "AdmitCoscode",
607                 'stud_status':"AdmitStatus",
608                 'department': "AdmitDept",
609                 'jamb_lga': "LGA",
610                 'app_email': "email",
[980]611                 'app_mobile': "PhoneNumbers",
[958]612                 }
613        csv_fields = [f[1] for f in csv_d.items()]
614        tr_count = 0
[961]615        total = 0
[958]616        #name = 'pume_results'
[971]617        name = 'Admitted'
[958]618        no_import = []
619        s = ','.join(['"(%s)"' % fn for fn in csv_fields])
[971]620        no_import.append('"Error",%s' % s)
621        format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
622        no_certificate = "no certificate %s" % format
[1121]623        open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import))
[1082]624        logger = logging.getLogger('Import.%s' % name)
[1121]625        logger.info('start loading from %s.csv' % name)
[971]626        l = self.portal_catalog({'meta_type': "Certificate"})
627        certs = {}
628        cert_docs = {}
629        for f in l:
630            certs[f.getId] = f.getObject().getContent()
[958]631        try:
632            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
633        except:
634            logger.error('Error reading %s.csv' % name)
635            return
636        for jamb in result:
[971]637            jamb['Error'] = "Processing "
638            logger.info(format % jamb)
[958]639            jamb_reg_no = jamb.get(csv_d['jamb_reg_no'])
640            res = self.portal_catalog({'portal_type': "StudentApplication",
[959]641                                     'SearchableText': jamb_reg_no })
[958]642            if res:
[980]643                em = 'Student with RegNo %s already exists\n' % jamb_reg_no
[958]644                logger.info(em)
[971]645                jamb['Error'] = "Student exists"
[958]646                no_import.append(format % jamb)
647                continue
[971]648            cert_id = makeCertificateCode(jamb.get(csv_d['course_code']))
649            if cert_id not in certs.keys():
[958]650                em = 'No Certificate with ID %s \n' % cert_id
651                logger.info(em)
[971]652                jamb['Error'] = "No Certificate %s" % cert_id
653                no_import.append( format % jamb)
[958]654                continue
[1121]655            res = self.portal_pumeresults(jamb_reg_no = jamb_reg_no)
656            if len(res) == 1:
657                self.portal_pumeresults.modifyRecord(jamb_reg_no = jamb_reg_no,
658                                                     status = jamb.get(csv_d['stud_status']),
659                                                     )
660            jamb_reg_no =jamb.get(csv_d['jamb_reg_no'])
[971]661            cert_doc = certs[cert_id]
662            catalog_entry = {}
663            catalog_entry['jamb_reg_no'] = jamb_reg_no
[958]664            jamb_name = jamb.get(csv_d['jamb_lastname'])
665            jamb_name.replace('>','')
[966]666            jamb_name.replace('<','')
[958]667            names = jamb_name.split()
668            letter = names[-1][0].upper()
669            sid = self.generateStudentId(letter)
670            not_created = True
671            while not_created:
672                try:
673                    students_folder.invokeFactory('Student', sid)
674                    not_created = False
675                except BadRequest:
676                    sid = self.generateStudentId(letter)
[971]677            catalog_entry['id'] = sid
[958]678            tr_count += 1
[961]679            logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
[958]680            student = getattr(self,sid)
681            student.manage_setLocalRoles(sid, ['Owner',])
682            student.invokeFactory('StudentPume','pume')
683            dp = {'Title': 'Pume Data'}
684            student.invokeFactory('StudentApplication','application')
685            da = {'Title': 'Application Data'}
686            da["jamb_lastname"] = jamb_name
687            da_fields = ('jamb_reg_no',
688                         'jamb_sex',
689                         #'jamb_state',
[966]690                         'jamb_score',
[980]691##                         'jamb_first_cos',
[958]692                         'jamb_sex',
[971]693                         'jamb_state',
694                         'jamb_lga',
695                         'app_email',
[980]696                         'app_mobile',
[958]697                         )
698            for f in da_fields:
699                da[f] = jamb.get(csv_d[f])
[971]700            catalog_entry['email'] = jamb.get(csv_d['app_email'])
[958]701            app = student.application
[971]702            app_doc = app.getContent()
[975]703            picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no)
[971]704            #import pdb;pdb.set_trace()
705            if os.path.exists(picture):
706                file = open(picture)
[974]707                if False:
708                    img = PIL.Image.open(file)
709                    img.thumbnail((150,200),
710                                  resample=PIL.Image.ANTIALIAS)
711                    # We now need a buffer to write to. It can't be the same
712                    # as the inbuffer as the PNG writer will write over itself.
713                    outfile = StringIO()
714                    img.save(outfile, format=img.format)
715                else:
716                    outfile = file.read()
[971]717                app_doc.manage_addFile('passport',
718                                       file=outfile,
719                                       title="%s.jpg" % jamb_reg_no)
[958]720            app.getContent().edit(mapping=da)
721            app.manage_setLocalRoles(sid, ['Owner',])
722            #wftool.doActionFor(app,'close')
723            dp_fields = (
724                         #'pume_eng_score',
725                         #'pume_gen_score',
726                         'pume_tot_score',
727                         )
[964]728            dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded"
[958]729            pume = student.pume
730            pume.getContent().edit(mapping=dp)
731            #wftool.doActionFor(pume,'close')
732            pume.manage_setLocalRoles(sid, ['Owner',])
[966]733            #student.getContent().createSubObjects()
[975]734            dp = {}
[966]735            if len(names) == 3:
736                dp['firstname'] = names[0].capitalize()
737                dp['middlename'] = names[1].capitalize()
738                dp['lastname'] = names[2].capitalize()
739            elif len(names) == 2:
740                dp['firstname'] = names[0].capitalize()
[971]741                dp['middlename'] = ''
[966]742                dp['lastname'] = names[1].capitalize()
743            else:
[971]744                dp['firstname'] = ''
745                dp['middlename'] = ''
[966]746                dp['lastname'] = jamb_name
747            dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F'
[971]748            catalog_entry['sex'] = dp['sex']
749            catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp
[966]750            student.invokeFactory('StudentPersonal','personal')
751            per = student.personal
752            per_doc = per.getContent()
753            per_doc.edit(mapping = dp)
754            per.manage_setLocalRoles(sid, ['Owner',])
[958]755            if jamb.get(csv_d['stud_status']) == "Admitted":
756                wftool.doActionFor(student,'pume_pass')
757                wftool.doActionFor(student,'admit')
758            else:
759                wftool.doActionFor(student,'pume_fail')
760                wftool.doActionFor(student,'reject_admission')
761                continue
[964]762            #
[966]763            # Clearance
764            #
765            student.invokeFactory('StudentClearance','clearance')
766            #wftool.doActionFor(student.clearance,'open')
767            dp = {'Title': 'Clearance/Eligibility Record'}
768            student.clearance.manage_setLocalRoles(sid, ['Owner',])
769            #
[964]770            # Study Course
771            #
[958]772            student.invokeFactory('StudentStudyCourse','study_course')
773            study_course = student.study_course
774            dsc = {}
775            from_certificate = ['title',
776                               'max_elect',
777                               'max_pass',
778                               'n_core',
779                               'nr_years',
780                               'probation_credits',
781                               'promotion_credits',
782                               'start_level',
783                              ]
784            for f in from_certificate:
785                dsc[f] = getattr(cert_doc,f)
[971]786            dsc['faculty'] = jamb.get(csv_d['faculty'])
787            dsc['department'] = jamb.get(csv_d['department'])
788            catalog_entry['faculty'] = jamb.get(csv_d['faculty'])
789            catalog_entry['department'] = jamb.get(csv_d['department'])
790            catalog_entry['course'] = cert_id
791            catalog_entry['level'] = getattr(cert_doc,'start_level')
[958]792            dsc['study_course'] = cert_id
[971]793            dsc['entry_session'] = jamb.get(csv_d['session'])
[958]794            study_course.getContent().edit(mapping=dsc)
[971]795            self.students_catalog.addRecord(**catalog_entry)
[981]796            if tr_count > MAX_TRANS:
[966]797                if len(no_import) > 1:
798                    open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write(
799                             '\n'.join(no_import))
800                    no_import = []
[961]801                em = '%d transactions commited\n' % tr_count
[958]802                transaction.commit()
803                logger.info(em)
[961]804                total += tr_count
[958]805                tr_count = 0
806        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
807    ###)
808
[1065]809    security.declareProtected(ModifyPortalContent,"updateStudyCourse")###(
810    def updateStudyCourse(self):
811        """update StudyCourse from CSV values"""
812        import transaction
813        import random
814        from pdb import set_trace
815        wftool = self.portal_workflow
816        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
817        csv_d = {'jamb_reg_no': "RegNumber",
818                 'jamb_lastname': "Name",
819                 'session': "Session",
820                 'pume_tot_score': "PUME SCORE",
821                 'jamb_score': "JambScore",
822                 'jamb_sex': "Sex",
823                 'jamb_state': "State",
824##                 'jamb_first_cos': "AdminCourse",
825                 'faculty': "AdminFaculty",
826                 'course_code': "AdmitCoscode",
827                 'stud_status':"AdmitStatus",
828                 'department': "AdmitDept",
829                 'jamb_lga': "LGA",
830                 'app_email': "email",
831                 'app_mobile': "PhoneNumbers",
832                 }
833        csv_fields = [f[1] for f in csv_d.items()]
834        tr_count = 0
835        total = 0
836        #name = 'pume_results'
837        name = 'StudyCourseChange'
838        no_import = []
839        s = ','.join(['"(%s)"' % fn for fn in csv_fields])
840        no_import.append('"Error",%s' % s)
841        format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
842        no_certificate = "no certificate %s" % format
843        open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write(
844                    '\n'.join(no_import))
[1082]845        logger = logging.getLogger('Import.%s' % name)
[1065]846        logger.info('Start loading from %s.csv' % name)
847        l = self.portal_catalog({'meta_type': "Certificate"})
848        try:
849            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
850        except:
851            logger.error('Error reading %s.csv' % name)
852            return
853        for jamb in result:
854            jamb['Error'] = "Processing "
855            logger.info(format % jamb)
856            jamb_reg_no = jamb.get(csv_d['jamb_reg_no'])
857            res = self.portal_catalog({'portal_type': "StudentApplication",
858                                     'SearchableText': jamb_reg_no })
859            if not res:
860                em = 'Student with RegNo %s does not exists\n' % jamb_reg_no
861                logger.info(em)
862                jamb['Error'] = "Student not exists"
863                no_import.append(format % jamb)
864                continue
865            sid = res[0].getPath().split('/')[-2]
866            cert_id = makeCertificateCode(jamb.get(csv_d['course_code']))
867            res = self.portal_catalog(portal_type = "Certificate", id = cert_id)
868            if not res:
869                em = 'No Certificate with ID %s \n' % cert_id
870                logger.info(em)
871                jamb['Error'] = "No Certificate %s" % cert_id
872                no_import.append( format % jamb)
873                continue
874            cert_brain = res[0]
875            catalog_entry = {}
876            student = getattr(self,sid)
877            #
878            # Study Course
879            #
880            study_course = student.study_course
881            dsc = {}
882            cert_pl = cert_brain.getPath().split('/')
883            catalog_entry['id'] = sid
884            catalog_entry['faculty'] = cert_pl[-4]
885            catalog_entry['department'] = cert_pl[-3]
886            catalog_entry['course'] = cert_id
887            dsc['study_course'] = cert_id
888            study_course.getContent().edit(mapping=dsc)
889            self.students_catalog.modifyRecord(**catalog_entry)
890            if tr_count > 10:
891                if len(no_import) > 1:
892                    open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write(
893                             '\n'.join(no_import))
894                    no_import = []
895                em = '%d transactions commited\n' % tr_count
896                transaction.commit()
897                logger.info(em)
898                total += tr_count
899                tr_count = 0
900            tr_count += 1
901        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
902    ###)
903
[958]904    security.declareProtected(ModifyPortalContent,"OLDloadPumeResultsFromCSV")###(
905    def OLDloadPumeResultsFromCSV(self):
906        """load Fulltime Studentdata from CSV values"""
907        import transaction
908        import random
909        wftool = self.portal_workflow
910        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
911        csv_d = {'jamb_reg_no': "JAMBRegno",
912                 'jamb_lastname': "Name",
[757]913                 'pume_options': "Options",
914                 'session': "Session",
915                 'days': "Days",
916                 'response': "Responce",
917                 'wrong': "Wrong",
918                 'pume_eng_score': "EngScore",
[775]919                 'pume_gen_score': "GenScore",
[958]920                 'pume_tot_score': "Score",
[757]921                 'batch': "Batch",
922                 'serial': "SerialNo",
923                 'jamb_score': "JambScore",
924                 'omitted':"Omitted",
925                 'search_key': "SearchKey",
926                 'jamb_sex': "Sex",
927                 'fac1': "Fac1",
928                 'fac2': "Fac2",
929                 'jamb_first_cos': "CourseofStudy",
930                 'stud_status':"StudStatus",
931                 'registered': "Registered",
932                 'jamb_state': "State",
933                 'eng_fail': "EngFail",
934                 'gen_fail': "GenFail",
935                 'un_ans_eng': "UnAnsEng",
936                 'un_ans_eng': "UnAnsGen",
937                 'total_ans': "TotalUnAns",
938                 'dept': "Dept",
939                 'jamb_second_cos': "Course2",
940                 'jamb_third_cos': "course3",
941                 }
942        csv_fields = [f[1] for f in csv_d.items()]
[742]943        tr_count = 0
944        name = 'pume_results'
[757]945        no_import = []
946        s = ','.join(['"(%s)"' % fn for fn in csv_fields])
947        no_import.append('%s\n' % s)
[1082]948        logger = logging.getLogger('Import.%s' % name)
[742]949        logger.info('Start loading from %s.csv' % name)
950        try:
[757]951            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
[742]952        except:
953            logger.error('Error reading %s.csv' % name)
954            return
[757]955        for jamb in result:
956            format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
957            processing = "processing %s" % format
958            logger.info(processing % jamb)
959            jamb_reg_no = jamb.get(csv_d['jamb_reg_no'])
[763]960            #import pdb;pdb.set_trace()
961            res = self.portal_catalog({'portal_type': "StudentApplication",
[757]962                                     'jamb_reg_no': jamb_reg_no })
963            if res:
964                em = 'Student with REG-NO %s already exists\n' % jamb_reg_no
[742]965                logger.info(em)
[757]966                no_import.append(em)
967                no_import.append(format % jamb)
[742]968                continue
[785]969            cert_id = jamb.get(csv_d['jamb_first_cos']).upper()
970            res = self.portal_catalog({'portal_type': "Certificate",
971                                     'id': cert_id })
972            if len(res) < 1:
973                em = 'No Certificate with ID %s \n' % cert_id
974                logger.info(em)
975                no_import.append(em)
976                no_import.append(format % jamb)
977                continue
978            cert = res[0].getObject()
979            cert_path = res[0].getPath()
980            cert_doc = cert.getContent()
[757]981            jamb_name = jamb.get(csv_d['jamb_lastname'])
982            jamb_name.replace('>','')
983            names = jamb_name.split()
984            letter = names[-1][0].upper()
985            sid = self.generateStudentId(letter)
986            not_created = True
987            while not_created:
988                try:
989                    students_folder.invokeFactory('Student', sid)
990                    not_created = False
991                except BadRequest:
992                    sid = self.generateStudentId(letter)
993            logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
994            student = getattr(self,sid)
995            student.manage_setLocalRoles(sid, ['Owner',])
[766]996            student.invokeFactory('StudentClearance','clearance')
[775]997            #wftool.doActionFor(student.clearance,'open')
[840]998            dp = {'Title': 'Clearance/Eligibility Record'}
[766]999            student.clearance.manage_setLocalRoles(sid, ['Owner',])
[763]1000            student.invokeFactory('StudentPume','pume')
1001            dp = {'Title': 'Pume Data'}
[757]1002            student.invokeFactory('StudentApplication','application')
1003            da = {'Title': 'Application Data'}
1004            da["jamb_lastname"] = jamb_name
1005            da_fields = ('jamb_reg_no',
1006                         'jamb_sex',
1007                         'jamb_state',
1008                         'jamb_score',
1009                         'jamb_first_cos',
1010                         'jamb_sex',
1011                         'jamb_state',
1012                         'jamb_first_cos',
1013                         'jamb_second_cos',
1014                         )
[763]1015            for f in da_fields:
1016                da[f] = jamb.get(csv_d[f])
[757]1017            app = student.application
[763]1018            app.getContent().edit(mapping=da)
[757]1019            app.manage_setLocalRoles(sid, ['Owner',])
[780]1020            #wftool.doActionFor(app,'close')
[763]1021            dp_fields = (
1022                         'pume_eng_score',
[764]1023                         'pume_gen_score',
[763]1024                         'pume_tot_score',
1025                         )
1026            for f in dp_fields:
[775]1027                dp[f] = float(jamb.get(csv_d[f]))
[765]1028            pume = student.pume
1029            pume.getContent().edit(mapping=dp)
[780]1030            #wftool.doActionFor(pume,'close')
[763]1031            pume.manage_setLocalRoles(sid, ['Owner',])
[785]1032            #
1033            # Study Course
1034            #
1035            student.invokeFactory('StudentStudyCourse','study_course')
1036            study_course = student.study_course
1037            dsc = {}
1038            from_certificate = ['title',
1039                               'max_elect',
1040                               'max_pass',
1041                               'n_core',
1042                               'nr_years',
1043                               'probation_credits',
1044                               'promotion_credits',
1045                               'start_level',
1046                              ]
1047            for f in from_certificate:
1048                dsc[f] = getattr(cert_doc,f)
1049            cpl = cert_path.split('/')
1050            dsc['faculty'] = cpl[-4]
1051            dsc['department'] = cpl[-3]
1052            dsc['study_course'] = cert_id
1053            dsc['entry_session'] = jamb.get(csv_d['session'])
1054            study_course.getContent().edit(mapping=dsc)
[757]1055            student.getContent().createSubObjects()
[775]1056            if dp['pume_tot_score']>49:
[780]1057                wftool.doActionFor(student,'pume_pass')
[785]1058                wftool.doActionFor(student,'admit')
[775]1059            else:
[780]1060                wftool.doActionFor(student,'pume_fail')
[790]1061                wftool.doActionFor(student,'reject_admission')
[757]1062            if len(no_import) > 1:
1063                open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write(
1064                     '\n'.join(no_import))
[742]1065        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
1066    ###)
1067
[398]1068    security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsResultsFromCSV") ###(
[396]1069    def loadFullTimeStudentsResultsFromCSV(self):
1070        """load Fulltime Studentdata from CSV values"""
1071        #return
[723]1072        level_wf_actions = {}
1073        level_wf_actions["SUCCESSFUL STUDENT"] = "pass_A"
1074        level_wf_actions["STUDENT WITH CARRYOVER COURSES"] = "pass_B"
[727]1075        level_wf_actions["STUDENT FOR PROBATION"] = "probate_C"
1076        level_wf_actions["STUDENT ON PROBATION/TRANSFER"] = "reject_D"
[398]1077        import transaction
[723]1078        wftool = self.portal_workflow
[398]1079        tr_count = 0
1080        name = 'short_full_time_results_2004_2005'
[396]1081        no_import = False
1082        if not no_import:
1083            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
1084            no_import.write('"Matnumber","CosCode","Ansbook","CosStuatus","Session","Mat_Cos","Score","CarryLevel","Grade","Weight","Semster","Verdict","Level","id","GPA"\n')
[1082]1085        logger = logging.getLogger('Ímport.%s' % name)
[396]1086        logger.info('Start loading from %s.csv' % name)
1087        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
1088        try:
1089            results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
1090        except:
1091            logger.error('Error reading %s.csv' % name)
1092            return
[398]1093        l = self.portal_catalog({'meta_type': "Course"})
1094        courses = {}
1095        for c in l:
1096            courses[c.id] = c.getObject()
[723]1097        level_changed = False
1098        student_changed = False
1099        sid = ''
1100        #import pdb;pdb.set_trace()
[396]1101        for result in results:
[723]1102            temp_sid = result.get('Matnumber')
1103            if temp_sid != sid:
1104                student_changed = True
1105                res = self.portal_catalog({'meta_type': "StudentClearance",
1106                                         'SearchableText': temp_sid })
1107                if not res:
1108                    em = 'Student with ID %(Matnumber)s not found\n' % result
1109                    logger.info(em)
1110                    no_import.write(em)
1111                    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)
1112                    continue
1113                elif len(res) > 1:
1114                    em = 'More than one Student with ID %(Matnumber)s found\n' % result
1115                    logger.info(em)
1116                    no_import.write(em)
1117                    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)
1118                    continue
1119                sid = temp_sid
1120                sf = res[0].getObject().aq_parent
1121                sc = getattr(sf,'study_course')
1122                level = ''
1123            else:
1124                student_changed = False
[398]1125            course = result.get('CosCode')
1126            if course not in courses.keys():
1127                em = 'Course with ID %(CosCode)s not found\n' % result
[396]1128                logger.info(em)
1129                no_import.write(em)
[398]1130                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)
[396]1131                continue
[727]1132            course_doc = courses[course].getContent()
[723]1133            temp_level = result.get('Level')
[742]1134            student_id = sf.getId()
1135            result['StudentId'] = student_id
[723]1136            if temp_level != level:
1137                try:
1138                    int(temp_level)
1139                except:
1140                    em = 'Result with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % result
1141                    logger.info(em)
1142                    no_import.write(em)
1143                    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)
1144                    continue
[727]1145                level_changed = True
1146                if 'dlev' in vars().keys():
[723]1147                    wftool.doActionFor(l,level_wf_actions[dlev['verdict']])
1148                level = temp_level
1149                l = getattr(sc,level,None)
1150                if l is None:
1151                    logger.info('Creating Level %(Level)s for %(StudentId)s %(Matnumber)s' % result)
1152                    sc.invokeFactory('StudentStudyLevel', level)
1153                    l = getattr(sc, level)
[742]1154                    l.manage_setLocalRoles(student_id, ['Owner',])
[723]1155            else:
1156                level_changed = False
1157            cr = getattr(l,course,None)
1158            if cr is None:
1159                logger.info('Creating Course %(CosCode)s for %(StudentId)s %(Matnumber)s in Level %(Level)s' % result)
1160                l.invokeFactory('StudentCourseResult',course)
1161            cr = getattr(l,course)
1162            dcr = {}
[727]1163            from_course = ['title',
1164                           'credits',
1165                           'passmark',
1166                           ]
1167            for f in from_course:
1168                dcr[f] = getattr(course_doc,f)
[454]1169            dlev = {}
[723]1170            dcr['ansbook'] = result.get('Ansbook')
1171            dcr['semester'] = getInt(result.get('Semster'))
1172            dcr['status'] = result.get('CosStuatus')
1173            dcr['score'] = getInt(result.get('Score'))
[454]1174            dlev['session'] = result.get('Session')
[723]1175            dcr['carry_level'] = result.get('CarryLevel')
1176            dcr['grade'] = result.get('Grade')
[725]1177            dcr['weight'] = result.get('Weight')
[454]1178            dlev['verdict'] = result.get('Verdict')
[725]1179            dcr['import_id'] = result.get('id')
1180            gpa = result.get('GPA').replace(',','.')
1181            dlev['imported_gpa'] = getFloat(gpa)
[723]1182            cr.getContent().edit(mapping = dcr)
[742]1183            cr.manage_setLocalRoles(student_id, ['Owner',])
[454]1184            l.getContent().edit(mapping = dlev)
[398]1185            if tr_count > MAX_TRANS:
1186                transaction.commit()
1187                tr_count = 0
1188            tr_count += 1
[723]1189            wftool.doActionFor(cr,'close')
1190        wftool.doActionFor(l,level_wf_actions[dlev['verdict']])
[681]1191        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
[426]1192
[398]1193###)
[396]1194
[457]1195    security.declareProtected(ModifyPortalContent,"loadJAMBFromCSV")###(
1196    def loadJAMBFromCSV(self):
1197        """load JAMB data from CSV values"""
1198        #return
1199        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
1200        import transaction
1201        tr_count = 0
[572]1202        name = 'SampleJAMBDataII'
[511]1203        wftool = self.portal_workflow
[457]1204        no_import = False
1205        if not no_import:
1206            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
1207            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')
[1082]1208        logger = logging.getLogger('Import.%s' % name)
[457]1209        logger.info('Start loading from %s.csv' % name)
1210        try:
1211            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
1212        except:
1213            logger.error('Error reading %s.csv' % name)
1214            return
1215        for jamb in result:
1216            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)
1217            jamb_reg_no = jamb.get('REG-NO')
[472]1218            res = self.portal_catalog({'meta_type': "StudentApplication",
[457]1219                                     'jamb_reg_no': jamb_reg_no })
1220            if res:
1221                em = 'Student with REG-NO %(REG-NO)s already exists\n' % jamb
1222                logger.info(em)
1223                no_import.write(em)
1224                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)
1225                continue
[511]1226            jamb_name = jamb.get("NAME")
[584]1227            jamb_name.replace('>','')
[511]1228            names = jamb_name.split()
1229            letter = names[-1][0].upper()
[714]1230            sid = self.generateStudentId(letter)
[457]1231            not_created = True
1232            while not_created:
1233                try:
1234                    students_folder.invokeFactory('Student', sid)
1235                    not_created = False
1236                except BadRequest:
[714]1237                    sid = self.generateStudentId(letter)
[457]1238            logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
[511]1239            student = getattr(self,sid)
[519]1240            student.manage_setLocalRoles(sid, ['Owner',])
[511]1241            student.invokeFactory('StudentApplication','application')
[472]1242            da = {'Title': 'Application Data'}
[457]1243            da["jamb_reg_no"] = jamb.get("REG-NO")
[511]1244            da["jamb_lastname"] = jamb_name
[457]1245            da["jamb_sex"] = jamb.get("SEX")
1246            da["jamb_state"] = jamb.get("STATE")
1247            da["jamb_lga"] = jamb.get("LGA")
1248            da["jamb_score"] = jamb.get("AGGREGATE")
1249            da["jamb_first_cos"] = jamb.get("COURSE1")
1250            da["jamb_second_cos"] = jamb.get("COURSE2")
1251            da["jamb_first_uni"] = jamb.get("UNIV1")
1252            da["jamb_second_uni"] = jamb.get("UNIV2")
[511]1253            app = student.application
1254            app_doc = app.getContent()
1255            app_doc.edit(mapping=da)
[658]1256            #wftool.doActionFor(app,'open',dest_container=app)
[511]1257            app.manage_setLocalRoles(sid, ['Owner',])
1258            student.getContent().createSubObjects()
[457]1259        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
1260    ###)
[426]1261
[472]1262
[511]1263    security.declareProtected(View,"fixOwnership")
1264    def fixOwnership(self):
1265        """fix Ownership"""
1266        for s in self.portal_catalog(meta_type = 'Student'):
1267            student = s.getObject()
1268            sid = s.getId
1269            import pdb;pdb.set_trace()
1270            student.application.manage_setLocalRoles(sid, ['Owner',])
1271            student.personal.manage_setLocalRoles(sid, ['Owner',])
[603]1272
[364]1273    security.declareProtected(View,"Title")
1274    def Title(self):
1275        """compose title"""
[382]1276        return "Student Section"
[361]1277
[714]1278    def generateStudentId(self,letter): ###(
1279        import random
1280        r = random
1281        if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'):
1282            letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY')
1283        students = self.portal_catalog(meta_type = "StudentsFolder")[-1]
1284        sid = "%c%d" % (letter,r.randint(99999,1000000))
1285        while hasattr(students, sid):
1286            sid = "%c%d" % (letter,r.randint(99999,1000000))
[758]1287        return sid
[714]1288        #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000))
1289    ###)
1290
[361]1291InitializeClass(StudentsFolder)
1292
1293def addStudentsFolder(container, id, REQUEST=None, **kw):
1294    """Add a Student."""
1295    ob = StudentsFolder(id, **kw)
1296    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1297###)
1298
[57]1299class Student(CPSDocument): ###(
1300    """
[154]1301    WAeUP Student container for the various student data
[57]1302    """
1303    meta_type = 'Student'
1304    portal_type = meta_type
1305    security = ClassSecurityInfo()
[154]1306
[152]1307    security.declareProtected(View,"Title")
1308    def Title(self):
1309        """compose title"""
[153]1310        reg_nr = self.getId()[1:]
[362]1311        data = getattr(self,'personal',None)
[152]1312        if data:
1313            content = data.getContent()
1314            return "%s %s" % (content.firstname,content.lastname)
[472]1315        data = getattr(self,'application',None)
[464]1316        if data:
1317            content = data.getContent()
1318            return "%s" % (content.jamb_lastname)
[152]1319        return self.title
[154]1320
[511]1321    security.declarePrivate('makeStudentMember') ###(
1322    def makeStudentMember(self,sid,password='uNsEt'):
1323        """make the student a member"""
1324        membership = self.portal_membership
[603]1325        membership.addMember(sid,
[511]1326                             password ,
1327                             roles=('Member',
1328                                     'Student',
[522]1329                                     ),
[511]1330                             domains='',
[904]1331                             properties = {'memberareaCreationFlag': False,
1332                                           'homeless': True},)
[511]1333        member = membership.getMemberById(sid)
1334        self.portal_registration.afterAdd(member, sid, password, None)
1335        self.manage_setLocalRoles(sid, ['Owner',])
1336
1337###)
1338
[764]1339    security.declareProtected(View,'createSubObjects') ###(
1340    def createSubObjects(self):
1341        """make the student a member"""
1342        dp = {'Title': 'Personal Data'}
1343        app_doc = self.application.getContent()
1344        names = app_doc.jamb_lastname.split()
1345        if len(names) == 3:
1346            dp['firstname'] = names[0].capitalize()
1347            dp['middlename'] = names[1].capitalize()
1348            dp['lastname'] = names[2].capitalize()
1349        elif len(names) == 2:
1350            dp['firstname'] = names[0].capitalize()
1351            dp['lastname'] = names[1].capitalize()
1352        else:
1353            dp['lastname'] = app_doc.jamb_lastname
1354        dp['sex'] = app_doc.jamb_sex == 'F'
1355        dp['lga'] = "%s/%s" % (app_doc.jamb_state,app_doc.jamb_lga )
1356        proxy = self.aq_parent
1357        proxy.invokeFactory('StudentPersonal','personal')
1358        per = proxy.personal
1359        per_doc = per.getContent()
1360        per_doc.edit(mapping = dp)
[927]1361        per.manage_setLocalRoles(proxy.getId(), ['Owner',])
[764]1362        #self.portal_workflow.doActionFor(per,'open',dest_container=per)
[603]1363
[511]1364###)
1365
[57]1366InitializeClass(Student)
1367
1368def addStudent(container, id, REQUEST=None, **kw):
1369    """Add a Student."""
1370    ob = Student(id, **kw)
1371    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1372
1373###)
[91]1374
[639]1375class StudentAccommodation(CPSDocument): ###(
1376    """
1377    WAeUP Student container for the various student data
1378    """
1379    meta_type = 'StudentAccommodation'
1380    portal_type = meta_type
1381    security = ClassSecurityInfo()
1382
1383    security.declareProtected(View,"Title")
1384    def Title(self):
1385        """compose title"""
1386        content = self.getContent()
1387        #return "Accommodation Data for %s %s" % (content.firstname,content.lastname)
1388        return "Accommodation Data for Session %s" % content.session
1389
1390
1391InitializeClass(StudentAccommodation)
1392
1393def addStudentAccommodation(container, id, REQUEST=None, **kw):
1394    """Add a Students personal data."""
1395    ob = StudentAccommodation(id, **kw)
1396    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1397
1398###)
1399
[89]1400class StudentPersonal(CPSDocument): ###(
1401    """
[154]1402    WAeUP Student container for the various student data
[89]1403    """
1404    meta_type = 'StudentPersonal'
1405    portal_type = meta_type
1406    security = ClassSecurityInfo()
[152]1407
1408    security.declareProtected(View,"Title")
1409    def Title(self):
1410        """compose title"""
1411        content = self.getContent()
[364]1412        #return "Personal Data for %s %s" % (content.firstname,content.lastname)
1413        return "Personal Data"
[152]1414
[154]1415
[89]1416InitializeClass(StudentPersonal)
1417
1418def addStudentPersonal(container, id, REQUEST=None, **kw):
1419    """Add a Students personal data."""
1420    ob = StudentPersonal(id, **kw)
1421    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1422
1423###)
1424
[423]1425class StudentClearance(CPSDocument): ###(
1426    """
1427    WAeUP Student container for the various student data
1428    """
1429    meta_type = 'StudentClearance'
1430    portal_type = meta_type
1431    security = ClassSecurityInfo()
1432
1433    security.declareProtected(View,"Title")
1434    def Title(self):
1435        """compose title"""
1436        content = self.getContent()
[840]1437        #return "Clearance/Eligibility Record for %s %s" % (content.firstname,content.lastname)
1438        return "Clearance/Eligibility Record"
[423]1439
1440
1441InitializeClass(StudentClearance)
1442
1443def addStudentClearance(container, id, REQUEST=None, **kw):
1444    """Add a Students personal data."""
1445    ob = StudentClearance(id, **kw)
1446    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1447
1448###)
1449
[454]1450class StudentStudyLevel(CPSDocument): ###(
1451    """
1452    WAeUP Student container for the various student data
1453    """
1454    meta_type = 'StudentStudyLevel'
1455    portal_type = meta_type
1456    security = ClassSecurityInfo()
1457
1458    security.declareProtected(View,"Title")
1459    def Title(self):
1460        """compose title"""
1461        return "Level %s" % self.aq_parent.getId()
1462
[723]1463##    security.declarePublic("gpa")
1464##    def gpa(self):
1465##        """calculate the gpa"""
1466##        sum = 0
1467##        course_count = 0
1468##        for sc in self.objectValues():
1469##            result = sc.getContent()
1470##            if not result.grade:
1471##                continue
1472##            res = self.portal_catalog({'meta_type': 'Course',
1473##                                          'id': sc.aq_parent.id})
1474##            if len(res) != 1:
1475##                continue
1476##            course = res[0].getObject().getContent()
1477##            sum += course.credits * ['F','E','D','C','B','A'].index(result.grade)
1478##            course_count += 1
1479##        if course_count:
1480##            return sum/course_count
1481##        return 0.0
[472]1482
[454]1483InitializeClass(StudentStudyLevel)
1484
1485def addStudentStudyLevel(container, id, REQUEST=None, **kw):
1486    """Add a Students personal data."""
1487    ob = StudentStudyLevel(id, **kw)
1488    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1489
1490###)
1491
[362]1492class StudentStudyCourse(CPSDocument): ###(
1493    """
1494    WAeUP Student container for the various student data
1495    """
1496    meta_type = 'StudentStudyCourse'
1497    portal_type = meta_type
1498    security = ClassSecurityInfo()
1499
[364]1500    security.declareProtected(View,"Title")
1501    def Title(self):
1502        """compose title"""
1503        content = self.getContent()
[453]1504        return "Study Course"
[362]1505
1506
1507InitializeClass(StudentStudyCourse)
1508
1509def addStudentStudyCourse(container, id, REQUEST=None, **kw):
1510    """Add a Students personal data."""
1511    ob = StudentStudyCourse(id, **kw)
1512    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1513
1514###)
1515
[472]1516class StudentApplication(CPSDocument): ###(
[179]1517    """
1518    WAeUP Student container for the various student data
1519    """
[472]1520    meta_type = 'StudentApplication'
[179]1521    portal_type = meta_type
1522    security = ClassSecurityInfo()
1523
[181]1524    security.declareProtected(View,"Title")
1525    def Title(self):
1526        """compose title"""
[472]1527        return "Application Data"
[179]1528
[181]1529
[472]1530InitializeClass(StudentApplication)
[179]1531
[472]1532def addStudentApplication(container, id, REQUEST=None, **kw):
[179]1533    """Add a Students eligibility data."""
[472]1534    ob = StudentApplication(id, **kw)
[179]1535    return CPSBase_adder(container, ob, REQUEST=REQUEST)
[763]1536###)
[179]1537
[758]1538
1539class StudentPume(CPSDocument): ###(
1540    """
1541    WAeUP Student container for the various student data
1542    """
1543    meta_type = 'StudentPume'
1544    portal_type = meta_type
1545    security = ClassSecurityInfo()
1546
1547    security.declareProtected(View,"Title")
1548    def Title(self):
1549        """compose title"""
1550        return "PUME Results"
1551
1552
1553InitializeClass(StudentPume)
1554
1555def addStudentPume(container, id, REQUEST=None, **kw):
1556    """Add a Students PUME data."""
1557    ob = StudentPume(id, **kw)
1558    return CPSBase_adder(container, ob, REQUEST=REQUEST)
[179]1559###)
[181]1560
[565]1561##class StudentSemester(CPSDocument): ###(
1562##    """
1563##    WAeUP StudentSemester containing the courses and students
1564##    """
1565##    meta_type = 'StudentSemester'
1566##    portal_type = meta_type
1567##    security = ClassSecurityInfo()
1568##
1569##InitializeClass(StudentSemester)
1570##
1571##def addStudentSemester(container, id, REQUEST=None, **kw):
1572##    """Add a StudentSemester."""
1573##    ob = StudentSemester(id, **kw)
1574##    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1575##
1576#####)
[464]1577
[758]1578##class Semester(CPSDocument): ###(
1579##    """
1580##    WAeUP Semester containing the courses and students
1581##    """
1582##    meta_type = 'Semester'
1583##    portal_type = meta_type
1584##    security = ClassSecurityInfo()
1585##
1586##InitializeClass(Semester)
1587##
1588##def addSemester(container, id, REQUEST=None, **kw):
1589##    """Add a Semester."""
1590##    ob = Semester(id, **kw)
1591##    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1592##
1593#####)
[464]1594
1595class StudentCourseResult(CPSDocument): ###(
[89]1596    """
[464]1597    WAeUP StudentCourseResult
[89]1598    """
[464]1599    meta_type = 'StudentCourseResult'
[89]1600    portal_type = meta_type
1601    security = ClassSecurityInfo()
[472]1602
[454]1603    def getCourseEntry(self,cid):
[723]1604        res = self.portal_catalog({'meta_type': "Course",
[454]1605                                           'id': cid})
1606        if res:
1607            return res[-1]
1608        else:
1609            return None
[154]1610
[454]1611    security.declareProtected(View,"Title")
1612    def Title(self):
1613        """compose title"""
[723]1614        cid = self.aq_parent.getId()
[454]1615        ce = self.getCourseEntry(cid)
1616        if ce:
1617            return "%s" % ce.Title
1618        return "No course with id %s" % cid
[152]1619
[464]1620InitializeClass(StudentCourseResult)
[454]1621
[464]1622def addStudentCourseResult(container, id, REQUEST=None, **kw):
1623    """Add a StudentCourseResult."""
1624    ob = StudentCourseResult(id, **kw)
[89]1625    return CPSBase_adder(container, ob, REQUEST=REQUEST)
[139]1626###)
1627
[579]1628# Backward Compatibility StudyLevel
1629
1630from Products.WAeUP_SRP.Academics import StudyLevel
1631
1632from Products.WAeUP_SRP.Academics import addStudyLevel
1633
Note: See TracBrowser for help on using the repository browser.