source: WAeUP_SRP/trunk/Students.py @ 1019

Last change on this file since 1019 was 1005, checked in by joachim, 18 years ago

pume import check for duplicate on import

  • Property svn:keywords set to Id
File size: 53.5 KB
RevLine 
[57]1#-*- mode: python; mode: fold -*-
[200]2# $Id: Students.py 1005 2006-12-07 09:29:29Z 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
[361]64class StudentsFolder(CPSDocument): ###(
65    """
66    WAeUP container for the various WAeUP containers data
67    """
[362]68    meta_type = 'StudentsFolder'
[361]69    portal_type = meta_type
70    security = ClassSecurityInfo()
[154]71
[361]72    security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsFromCSV")###(
73    def loadFullTimeStudentsFromCSV(self):
74        """load Fulltime Studentdata from CSV values"""
[398]75        import transaction
[708]76        import random
[398]77        tr_count = 0
[361]78        name = 'short_full_time'
79        no_import = False
[395]80        if not no_import:
81            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
82            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')
[361]83        logger = logging.getLogger('%s_import' % name)
84        logger.info('Start loading from %s.csv' % name)
[708]85        pwlist  = []
86        pwlist.append('"student_id","firstname","middlename","lastname","matric_no","jamb_reg_no","access_code"')
87        pwl_template = Template('"$student_id","$firstname","$middlename","$lastname","$matric_no","$jamb_reg_no","$access_code"')
[361]88        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
89        try:
90            students = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
91        except:
92            logger.error('Error reading %s.csv' % name)
93            return
[422]94        l = self.portal_catalog({'meta_type': "StudentClearance",})
95        matrics = []
[361]96        for s in l:
[422]97            matrics.append(s.getObject().getContent().matric_no)
[423]98        print matrics
[361]99        l = self.portal_catalog({'meta_type': "Certificate"})
100        certs = {}
101        for c in l:
[727]102            ca,ac,fa,dep_id,co,certcode = c.relative_path.split('/')
103            cid = "%(dep_id)s_%(certcode)s" % vars()
104            certs[cid] = c.getObject()
[361]105        for student in students:
[393]106            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]107            sid = student.get('MatricNo')
[396]108            if sid == "":
109                em = 'Empty MatricNo\n'
110                logger.info(em)
111                no_import.write(em)
112                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)
113                continue
[361]114            certcode = makeCertificateCode(student.get('CourseMajor'))
[727]115            dep_id = student.get('Dept')
116            fac_id = student.get('Faculty')
117            cid = "%(dep_id)s_%(certcode)s" % vars()
118            if cid not in certs.keys():
[393]119                em = 'Certificate with ID %s %s not found\n' % (certcode, student.get('CourseMajor'))
[361]120                logger.info(em)
[393]121                no_import.write(em)
122                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]123                continue
[727]124            certificate_doc = certs[cid].getContent()
[395]125            level = student.get('StudentLevel')
[426]126            try:
[395]127                int(level)
128            except:
129                em = 'Student with ID %(MatricNo)s StudentLevel is empty\n' % student
130                logger.info(em)
131                no_import.write(em)
132                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)
133                continue
[422]134            matric_no = student.get('MatricNo')
135            if matric_no not in matrics:
136                matrics.append(matric_no)
[714]137                sid = self.generateStudentId(student.get('Lastname')[0])
[361]138                #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
[714]139                students_folder.invokeFactory('Student', sid)
[426]140                logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars())
[714]141                student_obj = getattr(self,sid)
[708]142                access_code = "%d" % random.randint(1000000000,9999999999)
[746]143                student_obj.getContent().makeStudentMember(sid,access_code,)
[708]144                pwl_dict = {'student_id': sid,'access_code':access_code}
[714]145                student_obj.invokeFactory('StudentApplication','application')
146                application = student_obj.application
[472]147                da = {'Title': 'Application Data'}
[714]148                student_obj.invokeFactory('StudentPersonal','personal')
[446]149                da['jamb_reg_no'] = student.get('EntryRegNo')
[714]150                personal = student_obj.personal
[708]151                dp = {'Title': 'Personal Data'}
[714]152                student_obj.invokeFactory('StudentClearance','clearance')
153                clearance = student_obj.clearance
[840]154                dc = {'Title': 'Clearance/Eligibility Record'}
[422]155                dc['matric_no'] = matric_no
[714]156                state = student.get('State')
157                lga = student.get('LGA')
158                if state and lga:
159                    lga =  state + ' / ' + lga
160                else:
161                    lga = "None"
[427]162                dc['lga'] = lga
[422]163                dc['nationality'] = student.get('Nationality')
164                dc['email'] = student.get('Emailaddress')
[708]165                dp['firstname'] = student.get('FirstName')
166                dp['middlename'] = student.get('MiddleName')
167                dp['lastname'] = student.get('Lastname')
168                dp['former_surname'] = student.get('FormerSurname')
169                dp['sex'] = student.get('Sex') == 'F'
170                dp['perm_address'] = student.get('PermanentAddress')
171                dp['perm_city'] = student.get('PermanentAddressCity')
172                dp['campus_address'] = student.get('CampusAddress')
173                dp['phone'] = student.get('PhoneNumber')
[714]174                application.getContent().edit(mapping=da)
175                personal.getContent().edit(mapping=dp)
176                clearance.getContent().edit(mapping=dc)
[362]177                #
178                # Study Course
179                #
[714]180                student_obj.invokeFactory('StudentStudyCourse','study_course')
181                studycourse = student_obj.study_course
[708]182                dsc = {}
[727]183                from_certificate = ['title',
184                                   'max_elect',
185                                   'max_pass',
186                                   'n_core',
187                                   'nr_years',
188                                   'probation_credits',
189                                   'promotion_credits',
190                                   'start_level',
191                                  ]
192                for f in from_certificate:
193                    dsc[f] = getattr(certificate_doc,f)
194                dsc['faculty'] = fac_id
195                dsc['department'] = dep_id
[708]196                dsc['study_course'] = certcode
[454]197                css = student.get('CurrentSession') or '2004-2005'
198                cs = int(css.split('-')[0]) - 2000
[714]199                cl = int(student.get('StudentLevel') or '100')/100
[708]200                dsc['entry_session'] = "200%s" % (cs - cl)
201                dsc['clr_ac_pin'] = access_code
[714]202                studycourse.getContent().edit(mapping=dsc)
[364]203                #
204                # Level
205                #
[723]206##                l = getattr(studycourse,level,None)
207##                if 0 and l is None:
208##                    #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
209##                    logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student)
210##                    studycourse.invokeFactory('StudentStudyLevel', level)
211##                    l = getattr(studycourse, level)
212##                    certificate = certs[certcode]
213##                    cert_level = getattr(certificate,level,None)
214##                    if cert_level is None:
215##                        logger.info('Level %(level)s not in %(certcode)s' % vars())
216##                    l.getContent().edit(mapping={'Title': "Level %s" % level})
[361]217            else:
[393]218                em = 'Student with ID %(MatricNo)s %(fullname)s already exists\n' % student
[361]219                logger.info(em)
[393]220                no_import.write(em)
221                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]222                continue
[398]223            if tr_count > MAX_TRANS:
[422]224                transaction.commit()
225                em = 'Transaction commited\n' % student
[398]226                logger.info(em)
227                tr_count = 0
228            tr_count += 1
[708]229            pwl_dict.update(dc)
230            pwl_dict.update(da)
231            pwl_dict.update(dp)
[714]232            wftool = self.portal_workflow
[708]233            pwlist.append(pwl_template.substitute(pwl_dict))
[714]234            wftool.doActionFor(student_obj,'clear_and_validate')
[742]235            student_obj.manage_setLocalRoles(sid, ['Owner',])
[714]236            wftool.doActionFor(application,'close')
[742]237            application.manage_setLocalRoles(sid, ['Owner',])
[714]238            wftool.doActionFor(clearance,'close')
[742]239            clearance.manage_setLocalRoles(sid, ['Owner',])
[714]240            wftool.doActionFor(personal,'close')
[742]241            personal.manage_setLocalRoles(sid, ['Owner',])
[727]242            wftool.doActionFor(studycourse,'close_for_edit')
[742]243            studycourse.manage_setLocalRoles(sid, ['Owner',])
[714]244        open("%s/import/pwlist-%s.csv" % (i_home,name),"w+").write('\n'.join(pwlist))
[423]245        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
[361]246    ###)
[382]247
[742]248    security.declareProtected(ModifyPortalContent,"loadPumeResultsFromCSV")###(
249    def loadPumeResultsFromCSV(self):
[966]250        """load Fulltime Studentdata from CSV values into pumeresults catalog"""
251        import transaction
252        import random
253        from pdb import set_trace
254        csv_d = {'jamb_reg_no': "RegNumber",
255                 'status': "Admission Status",
256                 'name': "Name",
257                 'score': "Score",
258                 'sex': "Sex",
259                 'faculty': "Faculty",
260                 'department': "Dept",
261                 'course': "Course",
262                 'course_code_org': "Course Code",
263                 }
264        csv_fields = [f[1] for f in csv_d.items()]
265        tr_count = 0
266        total = 0
[971]267        #name = 'pup_new'
268        name = 'pup_update'
269        update = name.endswith('update')
[966]270        no_import = []
[1005]271        s = ','.join(['"%s"' % fn for fn in csv_fields])
[966]272        no_import.append('%s' % s)
[1005]273        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
274        no_import_name = "%s/import/%s_not_imported_%s.csv" % (i_home,name,current)
275        open(no_import_name,"w").write('\n'.join(no_import))
[966]276        no_import = []
277        logger = logging.getLogger('%s_import' % name)
278        starttime = DateTime.now()
279        logger.info('Start loading from %s.csv' % name)
280        try:
281            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
282        except:
283            logger.error('Error reading %s.csv' % name)
284            return
285        pume = self.portal_pumeresults
286        format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
[975]287        eduplicate = '"dupplicate",%s' % format
[1005]288        added = 'added ,%s' % format
[966]289        for jamb in result:
290            dict = {}
291            #set_trace()
292            for f,fn in csv_d.items():
293                dict[f] = jamb.get(csv_d[f])
[971]294            res = pume(jamb_reg_no=jamb.get(csv_d['jamb_reg_no']))
295            if len(res) > 0:
296                if update:
[1005]297                    try:
298                        pume.modifyRecord(**dict)
299                    except ValueError:
300                        logger.info(eduplicate % jamb)
301                        continue
302                    except KeyError:
303                        pume.addRecord(**dict)
304                        logger.info(added % jamb)
305                        continue
[971]306                else:
307                    data = res[0]
308                    if data.name != jamb.get(csv_d['name']):
309                        #set_trace()
310                        logger.info(eduplicate % jamb)
311                        #em = 'Student with REG-NO %(jamb_reg_no)s already exists\n' % dict
312                        #logger.info(em)
313                        dd = {}
314                        for f,fn in csv_d.items():
315                            dd[fn] = getattr(data,f)
316                        no_import.append(eduplicate % dd)
317                        no_import.append(eduplicate % jamb)
318                    continue
[966]319            try:
320                pume.addRecord(**dict)
321            except ValueError:
322                logger.info(eduplicate % jamb)
323                #em = 'Student with REG-NO %(jamb_reg_no)s already exists\n' % dict
324                #logger.info(em)
325                no_import.append(eduplicate % jamb)
326        logger.info('End loading from %s.csv' % name)
327        if len(no_import) > 1:
[1005]328            open(no_import_name,"w+").write('\n'.join(no_import))
[966]329        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
[971]330    ###)
[966]331
332    security.declareProtected(ModifyPortalContent,"createNewStudents")###(
333    def createNewStudents(self):
[742]334        """load Fulltime Studentdata from CSV values"""
335        import transaction
336        import random
[971]337        #from pdb import set_trace
[763]338        wftool = self.portal_workflow
[757]339        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
[971]340        csv_d = {'jamb_reg_no': "RegNumber",
[958]341                 'jamb_lastname': "Name",
[971]342                 'session': "Session",
343                 'pume_tot_score': "PUME SCORE",
344                 'jamb_score': "JambScore",
[958]345                 'jamb_sex': "Sex",
[971]346                 'jamb_state': "State",
[980]347##                 'jamb_first_cos': "AdminCourse",
[971]348                 'faculty': "AdminFaculty",
349                 'course_code': "AdmitCoscode",
350                 'stud_status':"AdmitStatus",
351                 'department': "AdmitDept",
352                 'jamb_lga': "LGA",
353                 'app_email': "email",
[980]354                 'app_mobile': "PhoneNumbers",
[958]355                 }
356        csv_fields = [f[1] for f in csv_d.items()]
357        tr_count = 0
[961]358        total = 0
[958]359        #name = 'pume_results'
[971]360        name = 'Admitted'
[958]361        no_import = []
362        s = ','.join(['"(%s)"' % fn for fn in csv_fields])
[971]363        no_import.append('"Error",%s' % s)
364        format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
365        no_certificate = "no certificate %s" % format
[966]366        open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write(
367                    '\n'.join(no_import))
[958]368        logger = logging.getLogger('%s_import' % name)
369        logger.info('Start loading from %s.csv' % name)
[971]370        l = self.portal_catalog({'meta_type': "Certificate"})
371        certs = {}
372        cert_docs = {}
373        for f in l:
374            certs[f.getId] = f.getObject().getContent()
[958]375        try:
376            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
377        except:
378            logger.error('Error reading %s.csv' % name)
379            return
380        for jamb in result:
[971]381            jamb['Error'] = "Processing "
382            logger.info(format % jamb)
[958]383            jamb_reg_no = jamb.get(csv_d['jamb_reg_no'])
384            res = self.portal_catalog({'portal_type': "StudentApplication",
[959]385                                     'SearchableText': jamb_reg_no })
[958]386            if res:
[980]387                em = 'Student with RegNo %s already exists\n' % jamb_reg_no
[958]388                logger.info(em)
[971]389                jamb['Error'] = "Student exists"
[958]390                no_import.append(format % jamb)
391                continue
[971]392            cert_id = makeCertificateCode(jamb.get(csv_d['course_code']))
393            if cert_id not in certs.keys():
[958]394                em = 'No Certificate with ID %s \n' % cert_id
395                logger.info(em)
[971]396                jamb['Error'] = "No Certificate %s" % cert_id
397                no_import.append( format % jamb)
[958]398                continue
[971]399            cert_doc = certs[cert_id]
400            catalog_entry = {}
401            catalog_entry['jamb_reg_no'] = jamb_reg_no
[958]402            jamb_name = jamb.get(csv_d['jamb_lastname'])
403            jamb_name.replace('>','')
[966]404            jamb_name.replace('<','')
[958]405            names = jamb_name.split()
406            letter = names[-1][0].upper()
407            sid = self.generateStudentId(letter)
408            not_created = True
409            while not_created:
410                try:
411                    students_folder.invokeFactory('Student', sid)
412                    not_created = False
413                except BadRequest:
414                    sid = self.generateStudentId(letter)
[971]415            catalog_entry['id'] = sid
[958]416            tr_count += 1
[961]417            logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
[958]418            student = getattr(self,sid)
419            student.manage_setLocalRoles(sid, ['Owner',])
420            student.invokeFactory('StudentPume','pume')
421            dp = {'Title': 'Pume Data'}
422            student.invokeFactory('StudentApplication','application')
423            da = {'Title': 'Application Data'}
424            da["jamb_lastname"] = jamb_name
425            da_fields = ('jamb_reg_no',
426                         'jamb_sex',
427                         #'jamb_state',
[966]428                         'jamb_score',
[980]429##                         'jamb_first_cos',
[958]430                         'jamb_sex',
[971]431                         'jamb_state',
432                         'jamb_lga',
433                         'app_email',
[980]434                         'app_mobile',
[958]435                         )
436            for f in da_fields:
437                da[f] = jamb.get(csv_d[f])
[971]438            catalog_entry['email'] = jamb.get(csv_d['app_email'])
[958]439            app = student.application
[971]440            app_doc = app.getContent()
[975]441            picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no)
[971]442            #import pdb;pdb.set_trace()
443            if os.path.exists(picture):
444                file = open(picture)
[974]445                if False:
446                    img = PIL.Image.open(file)
447                    img.thumbnail((150,200),
448                                  resample=PIL.Image.ANTIALIAS)
449                    # We now need a buffer to write to. It can't be the same
450                    # as the inbuffer as the PNG writer will write over itself.
451                    outfile = StringIO()
452                    img.save(outfile, format=img.format)
453                else:
454                    outfile = file.read()
[971]455                app_doc.manage_addFile('passport',
456                                       file=outfile,
457                                       title="%s.jpg" % jamb_reg_no)
[958]458            app.getContent().edit(mapping=da)
459            app.manage_setLocalRoles(sid, ['Owner',])
460            #wftool.doActionFor(app,'close')
461            dp_fields = (
462                         #'pume_eng_score',
463                         #'pume_gen_score',
464                         'pume_tot_score',
465                         )
[964]466            dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded"
[958]467            pume = student.pume
468            pume.getContent().edit(mapping=dp)
469            #wftool.doActionFor(pume,'close')
470            pume.manage_setLocalRoles(sid, ['Owner',])
[966]471            #student.getContent().createSubObjects()
[975]472            dp = {}
[966]473            if len(names) == 3:
474                dp['firstname'] = names[0].capitalize()
475                dp['middlename'] = names[1].capitalize()
476                dp['lastname'] = names[2].capitalize()
477            elif len(names) == 2:
478                dp['firstname'] = names[0].capitalize()
[971]479                dp['middlename'] = ''
[966]480                dp['lastname'] = names[1].capitalize()
481            else:
[971]482                dp['firstname'] = ''
483                dp['middlename'] = ''
[966]484                dp['lastname'] = jamb_name
485            dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F'
[971]486            catalog_entry['sex'] = dp['sex']
487            catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp
[966]488            student.invokeFactory('StudentPersonal','personal')
489            per = student.personal
490            per_doc = per.getContent()
491            per_doc.edit(mapping = dp)
492            per.manage_setLocalRoles(sid, ['Owner',])
[958]493            if jamb.get(csv_d['stud_status']) == "Admitted":
494                wftool.doActionFor(student,'pume_pass')
495                wftool.doActionFor(student,'admit')
496            else:
497                wftool.doActionFor(student,'pume_fail')
498                wftool.doActionFor(student,'reject_admission')
499                continue
[964]500            #
[966]501            # Clearance
502            #
503            student.invokeFactory('StudentClearance','clearance')
504            #wftool.doActionFor(student.clearance,'open')
505            dp = {'Title': 'Clearance/Eligibility Record'}
506            student.clearance.manage_setLocalRoles(sid, ['Owner',])
507            #
[964]508            # Study Course
509            #
[958]510            student.invokeFactory('StudentStudyCourse','study_course')
511            study_course = student.study_course
512            dsc = {}
513            from_certificate = ['title',
514                               'max_elect',
515                               'max_pass',
516                               'n_core',
517                               'nr_years',
518                               'probation_credits',
519                               'promotion_credits',
520                               'start_level',
521                              ]
522            for f in from_certificate:
523                dsc[f] = getattr(cert_doc,f)
[971]524            dsc['faculty'] = jamb.get(csv_d['faculty'])
525            dsc['department'] = jamb.get(csv_d['department'])
526            catalog_entry['faculty'] = jamb.get(csv_d['faculty'])
527            catalog_entry['department'] = jamb.get(csv_d['department'])
528            catalog_entry['course'] = cert_id
529            catalog_entry['level'] = getattr(cert_doc,'start_level')
[958]530            dsc['study_course'] = cert_id
[971]531            dsc['entry_session'] = jamb.get(csv_d['session'])
[958]532            study_course.getContent().edit(mapping=dsc)
[971]533            self.students_catalog.addRecord(**catalog_entry)
[981]534            if tr_count > MAX_TRANS:
[966]535                if len(no_import) > 1:
536                    open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write(
537                             '\n'.join(no_import))
538                    no_import = []
[961]539                em = '%d transactions commited\n' % tr_count
[958]540                transaction.commit()
541                logger.info(em)
[961]542                total += tr_count
[958]543                tr_count = 0
544        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
545    ###)
546
547    security.declareProtected(ModifyPortalContent,"OLDloadPumeResultsFromCSV")###(
548    def OLDloadPumeResultsFromCSV(self):
549        """load Fulltime Studentdata from CSV values"""
550        import transaction
551        import random
552        wftool = self.portal_workflow
553        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
554        csv_d = {'jamb_reg_no': "JAMBRegno",
555                 'jamb_lastname': "Name",
[757]556                 'pume_options': "Options",
557                 'session': "Session",
558                 'days': "Days",
559                 'response': "Responce",
560                 'wrong': "Wrong",
561                 'pume_eng_score': "EngScore",
[775]562                 'pume_gen_score': "GenScore",
[958]563                 'pume_tot_score': "Score",
[757]564                 'batch': "Batch",
565                 'serial': "SerialNo",
566                 'jamb_score': "JambScore",
567                 'omitted':"Omitted",
568                 'search_key': "SearchKey",
569                 'jamb_sex': "Sex",
570                 'fac1': "Fac1",
571                 'fac2': "Fac2",
572                 'jamb_first_cos': "CourseofStudy",
573                 'stud_status':"StudStatus",
574                 'registered': "Registered",
575                 'jamb_state': "State",
576                 'eng_fail': "EngFail",
577                 'gen_fail': "GenFail",
578                 'un_ans_eng': "UnAnsEng",
579                 'un_ans_eng': "UnAnsGen",
580                 'total_ans': "TotalUnAns",
581                 'dept': "Dept",
582                 'jamb_second_cos': "Course2",
583                 'jamb_third_cos': "course3",
584                 }
585        csv_fields = [f[1] for f in csv_d.items()]
[742]586        tr_count = 0
587        name = 'pume_results'
[757]588        no_import = []
589        s = ','.join(['"(%s)"' % fn for fn in csv_fields])
590        no_import.append('%s\n' % s)
[742]591        logger = logging.getLogger('%s_import' % name)
592        logger.info('Start loading from %s.csv' % name)
593        try:
[757]594            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
[742]595        except:
596            logger.error('Error reading %s.csv' % name)
597            return
[757]598        for jamb in result:
599            format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields])
600            processing = "processing %s" % format
601            logger.info(processing % jamb)
602            jamb_reg_no = jamb.get(csv_d['jamb_reg_no'])
[763]603            #import pdb;pdb.set_trace()
604            res = self.portal_catalog({'portal_type': "StudentApplication",
[757]605                                     'jamb_reg_no': jamb_reg_no })
606            if res:
607                em = 'Student with REG-NO %s already exists\n' % jamb_reg_no
[742]608                logger.info(em)
[757]609                no_import.append(em)
610                no_import.append(format % jamb)
[742]611                continue
[785]612            cert_id = jamb.get(csv_d['jamb_first_cos']).upper()
613            res = self.portal_catalog({'portal_type': "Certificate",
614                                     'id': cert_id })
615            if len(res) < 1:
616                em = 'No Certificate with ID %s \n' % cert_id
617                logger.info(em)
618                no_import.append(em)
619                no_import.append(format % jamb)
620                continue
621            cert = res[0].getObject()
622            cert_path = res[0].getPath()
623            cert_doc = cert.getContent()
[757]624            jamb_name = jamb.get(csv_d['jamb_lastname'])
625            jamb_name.replace('>','')
626            names = jamb_name.split()
627            letter = names[-1][0].upper()
628            sid = self.generateStudentId(letter)
629            not_created = True
630            while not_created:
631                try:
632                    students_folder.invokeFactory('Student', sid)
633                    not_created = False
634                except BadRequest:
635                    sid = self.generateStudentId(letter)
636            logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
637            student = getattr(self,sid)
638            student.manage_setLocalRoles(sid, ['Owner',])
[766]639            student.invokeFactory('StudentClearance','clearance')
[775]640            #wftool.doActionFor(student.clearance,'open')
[840]641            dp = {'Title': 'Clearance/Eligibility Record'}
[766]642            student.clearance.manage_setLocalRoles(sid, ['Owner',])
[763]643            student.invokeFactory('StudentPume','pume')
644            dp = {'Title': 'Pume Data'}
[757]645            student.invokeFactory('StudentApplication','application')
646            da = {'Title': 'Application Data'}
647            da["jamb_lastname"] = jamb_name
648            da_fields = ('jamb_reg_no',
649                         'jamb_sex',
650                         'jamb_state',
651                         'jamb_score',
652                         'jamb_first_cos',
653                         'jamb_sex',
654                         'jamb_state',
655                         'jamb_first_cos',
656                         'jamb_second_cos',
657                         )
[763]658            for f in da_fields:
659                da[f] = jamb.get(csv_d[f])
[757]660            app = student.application
[763]661            app.getContent().edit(mapping=da)
[757]662            app.manage_setLocalRoles(sid, ['Owner',])
[780]663            #wftool.doActionFor(app,'close')
[763]664            dp_fields = (
665                         'pume_eng_score',
[764]666                         'pume_gen_score',
[763]667                         'pume_tot_score',
668                         )
669            for f in dp_fields:
[775]670                dp[f] = float(jamb.get(csv_d[f]))
[765]671            pume = student.pume
672            pume.getContent().edit(mapping=dp)
[780]673            #wftool.doActionFor(pume,'close')
[763]674            pume.manage_setLocalRoles(sid, ['Owner',])
[785]675            #
676            # Study Course
677            #
678            student.invokeFactory('StudentStudyCourse','study_course')
679            study_course = student.study_course
680            dsc = {}
681            from_certificate = ['title',
682                               'max_elect',
683                               'max_pass',
684                               'n_core',
685                               'nr_years',
686                               'probation_credits',
687                               'promotion_credits',
688                               'start_level',
689                              ]
690            for f in from_certificate:
691                dsc[f] = getattr(cert_doc,f)
692            cpl = cert_path.split('/')
693            dsc['faculty'] = cpl[-4]
694            dsc['department'] = cpl[-3]
695            dsc['study_course'] = cert_id
696            dsc['entry_session'] = jamb.get(csv_d['session'])
697            study_course.getContent().edit(mapping=dsc)
[757]698            student.getContent().createSubObjects()
[775]699            if dp['pume_tot_score']>49:
[780]700                wftool.doActionFor(student,'pume_pass')
[785]701                wftool.doActionFor(student,'admit')
[775]702            else:
[780]703                wftool.doActionFor(student,'pume_fail')
[790]704                wftool.doActionFor(student,'reject_admission')
[757]705            if len(no_import) > 1:
706                open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write(
707                     '\n'.join(no_import))
[742]708        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
709    ###)
710
[398]711    security.declareProtected(ModifyPortalContent,"loadFullTimeStudentsResultsFromCSV") ###(
[396]712    def loadFullTimeStudentsResultsFromCSV(self):
713        """load Fulltime Studentdata from CSV values"""
714        #return
[723]715        level_wf_actions = {}
716        level_wf_actions["SUCCESSFUL STUDENT"] = "pass_A"
717        level_wf_actions["STUDENT WITH CARRYOVER COURSES"] = "pass_B"
[727]718        level_wf_actions["STUDENT FOR PROBATION"] = "probate_C"
719        level_wf_actions["STUDENT ON PROBATION/TRANSFER"] = "reject_D"
[398]720        import transaction
[723]721        wftool = self.portal_workflow
[398]722        tr_count = 0
723        name = 'short_full_time_results_2004_2005'
[396]724        no_import = False
725        if not no_import:
726            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
727            no_import.write('"Matnumber","CosCode","Ansbook","CosStuatus","Session","Mat_Cos","Score","CarryLevel","Grade","Weight","Semster","Verdict","Level","id","GPA"\n')
728        logger = logging.getLogger('%s_import' % name)
729        logger.info('Start loading from %s.csv' % name)
730        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
731        try:
732            results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
733        except:
734            logger.error('Error reading %s.csv' % name)
735            return
[398]736        l = self.portal_catalog({'meta_type': "Course"})
737        courses = {}
738        for c in l:
739            courses[c.id] = c.getObject()
[723]740        level_changed = False
741        student_changed = False
742        sid = ''
743        #import pdb;pdb.set_trace()
[396]744        for result in results:
[723]745            temp_sid = result.get('Matnumber')
746            if temp_sid != sid:
747                student_changed = True
748                res = self.portal_catalog({'meta_type': "StudentClearance",
749                                         'SearchableText': temp_sid })
750                if not res:
751                    em = 'Student with ID %(Matnumber)s not found\n' % result
752                    logger.info(em)
753                    no_import.write(em)
754                    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)
755                    continue
756                elif len(res) > 1:
757                    em = 'More than one Student with ID %(Matnumber)s found\n' % result
758                    logger.info(em)
759                    no_import.write(em)
760                    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)
761                    continue
762                sid = temp_sid
763                sf = res[0].getObject().aq_parent
764                sc = getattr(sf,'study_course')
765                level = ''
766            else:
767                student_changed = False
[398]768            course = result.get('CosCode')
769            if course not in courses.keys():
770                em = 'Course with ID %(CosCode)s not found\n' % result
[396]771                logger.info(em)
772                no_import.write(em)
[398]773                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]774                continue
[727]775            course_doc = courses[course].getContent()
[723]776            temp_level = result.get('Level')
[742]777            student_id = sf.getId()
778            result['StudentId'] = student_id
[723]779            if temp_level != level:
780                try:
781                    int(temp_level)
782                except:
783                    em = 'Result with ID %(Matnumber)s Course %(CosCode)s Level is empty\n' % result
784                    logger.info(em)
785                    no_import.write(em)
786                    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)
787                    continue
[727]788                level_changed = True
789                if 'dlev' in vars().keys():
[723]790                    wftool.doActionFor(l,level_wf_actions[dlev['verdict']])
791                level = temp_level
792                l = getattr(sc,level,None)
793                if l is None:
794                    logger.info('Creating Level %(Level)s for %(StudentId)s %(Matnumber)s' % result)
795                    sc.invokeFactory('StudentStudyLevel', level)
796                    l = getattr(sc, level)
[742]797                    l.manage_setLocalRoles(student_id, ['Owner',])
[723]798            else:
799                level_changed = False
800            cr = getattr(l,course,None)
801            if cr is None:
802                logger.info('Creating Course %(CosCode)s for %(StudentId)s %(Matnumber)s in Level %(Level)s' % result)
803                l.invokeFactory('StudentCourseResult',course)
804            cr = getattr(l,course)
805            dcr = {}
[727]806            from_course = ['title',
807                           'credits',
808                           'passmark',
809                           ]
810            for f in from_course:
811                dcr[f] = getattr(course_doc,f)
[454]812            dlev = {}
[723]813            dcr['ansbook'] = result.get('Ansbook')
814            dcr['semester'] = getInt(result.get('Semster'))
815            dcr['status'] = result.get('CosStuatus')
816            dcr['score'] = getInt(result.get('Score'))
[454]817            dlev['session'] = result.get('Session')
[723]818            dcr['carry_level'] = result.get('CarryLevel')
819            dcr['grade'] = result.get('Grade')
[725]820            dcr['weight'] = result.get('Weight')
[454]821            dlev['verdict'] = result.get('Verdict')
[725]822            dcr['import_id'] = result.get('id')
823            gpa = result.get('GPA').replace(',','.')
824            dlev['imported_gpa'] = getFloat(gpa)
[723]825            cr.getContent().edit(mapping = dcr)
[742]826            cr.manage_setLocalRoles(student_id, ['Owner',])
[454]827            l.getContent().edit(mapping = dlev)
[398]828            if tr_count > MAX_TRANS:
829                transaction.commit()
830                tr_count = 0
831            tr_count += 1
[723]832            wftool.doActionFor(cr,'close')
833        wftool.doActionFor(l,level_wf_actions[dlev['verdict']])
[681]834        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
[426]835
[398]836###)
[396]837
[457]838    security.declareProtected(ModifyPortalContent,"loadJAMBFromCSV")###(
839    def loadJAMBFromCSV(self):
840        """load JAMB data from CSV values"""
841        #return
842        students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject()
843        import transaction
844        tr_count = 0
[572]845        name = 'SampleJAMBDataII'
[511]846        wftool = self.portal_workflow
[457]847        no_import = False
848        if not no_import:
849            no_import = open("%s/import/%s_not_imported.csv" % (i_home,name),"w")
850            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')
851        logger = logging.getLogger('%s_import' % name)
852        logger.info('Start loading from %s.csv' % name)
853        try:
854            result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))
855        except:
856            logger.error('Error reading %s.csv' % name)
857            return
858        for jamb in result:
859            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)
860            jamb_reg_no = jamb.get('REG-NO')
[472]861            res = self.portal_catalog({'meta_type': "StudentApplication",
[457]862                                     'jamb_reg_no': jamb_reg_no })
863            if res:
864                em = 'Student with REG-NO %(REG-NO)s already exists\n' % jamb
865                logger.info(em)
866                no_import.write(em)
867                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)
868                continue
[511]869            jamb_name = jamb.get("NAME")
[584]870            jamb_name.replace('>','')
[511]871            names = jamb_name.split()
872            letter = names[-1][0].upper()
[714]873            sid = self.generateStudentId(letter)
[457]874            not_created = True
875            while not_created:
876                try:
877                    students_folder.invokeFactory('Student', sid)
878                    not_created = False
879                except BadRequest:
[714]880                    sid = self.generateStudentId(letter)
[457]881            logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
[511]882            student = getattr(self,sid)
[519]883            student.manage_setLocalRoles(sid, ['Owner',])
[511]884            student.invokeFactory('StudentApplication','application')
[472]885            da = {'Title': 'Application Data'}
[457]886            da["jamb_reg_no"] = jamb.get("REG-NO")
[511]887            da["jamb_lastname"] = jamb_name
[457]888            da["jamb_sex"] = jamb.get("SEX")
889            da["jamb_state"] = jamb.get("STATE")
890            da["jamb_lga"] = jamb.get("LGA")
891            da["jamb_score"] = jamb.get("AGGREGATE")
892            da["jamb_first_cos"] = jamb.get("COURSE1")
893            da["jamb_second_cos"] = jamb.get("COURSE2")
894            da["jamb_first_uni"] = jamb.get("UNIV1")
895            da["jamb_second_uni"] = jamb.get("UNIV2")
[511]896            app = student.application
897            app_doc = app.getContent()
898            app_doc.edit(mapping=da)
[658]899            #wftool.doActionFor(app,'open',dest_container=app)
[511]900            app.manage_setLocalRoles(sid, ['Owner',])
901            student.getContent().createSubObjects()
[457]902        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
903    ###)
[426]904
[472]905
[511]906    security.declareProtected(View,"fixOwnership")
907    def fixOwnership(self):
908        """fix Ownership"""
909        for s in self.portal_catalog(meta_type = 'Student'):
910            student = s.getObject()
911            sid = s.getId
912            import pdb;pdb.set_trace()
913            student.application.manage_setLocalRoles(sid, ['Owner',])
914            student.personal.manage_setLocalRoles(sid, ['Owner',])
[603]915
[364]916    security.declareProtected(View,"Title")
917    def Title(self):
918        """compose title"""
[382]919        return "Student Section"
[361]920
[714]921    def generateStudentId(self,letter): ###(
922        import random
923        r = random
924        if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'):
925            letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY')
926        students = self.portal_catalog(meta_type = "StudentsFolder")[-1]
927        sid = "%c%d" % (letter,r.randint(99999,1000000))
928        while hasattr(students, sid):
929            sid = "%c%d" % (letter,r.randint(99999,1000000))
[758]930        return sid
[714]931        #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000))
932    ###)
933
[361]934InitializeClass(StudentsFolder)
935
936def addStudentsFolder(container, id, REQUEST=None, **kw):
937    """Add a Student."""
938    ob = StudentsFolder(id, **kw)
939    return CPSBase_adder(container, ob, REQUEST=REQUEST)
940###)
941
[57]942class Student(CPSDocument): ###(
943    """
[154]944    WAeUP Student container for the various student data
[57]945    """
946    meta_type = 'Student'
947    portal_type = meta_type
948    security = ClassSecurityInfo()
[154]949
[152]950    security.declareProtected(View,"Title")
951    def Title(self):
952        """compose title"""
[153]953        reg_nr = self.getId()[1:]
[362]954        data = getattr(self,'personal',None)
[152]955        if data:
956            content = data.getContent()
957            return "%s %s" % (content.firstname,content.lastname)
[472]958        data = getattr(self,'application',None)
[464]959        if data:
960            content = data.getContent()
961            return "%s" % (content.jamb_lastname)
[152]962        return self.title
[154]963
[511]964    security.declarePrivate('makeStudentMember') ###(
965    def makeStudentMember(self,sid,password='uNsEt'):
966        """make the student a member"""
967        membership = self.portal_membership
[603]968        membership.addMember(sid,
[511]969                             password ,
970                             roles=('Member',
971                                     'Student',
[522]972                                     ),
[511]973                             domains='',
[904]974                             properties = {'memberareaCreationFlag': False,
975                                           'homeless': True},)
[511]976        member = membership.getMemberById(sid)
977        self.portal_registration.afterAdd(member, sid, password, None)
978        self.manage_setLocalRoles(sid, ['Owner',])
979
980###)
981
[764]982    security.declareProtected(View,'createSubObjects') ###(
983    def createSubObjects(self):
984        """make the student a member"""
985        dp = {'Title': 'Personal Data'}
986        app_doc = self.application.getContent()
987        names = app_doc.jamb_lastname.split()
988        if len(names) == 3:
989            dp['firstname'] = names[0].capitalize()
990            dp['middlename'] = names[1].capitalize()
991            dp['lastname'] = names[2].capitalize()
992        elif len(names) == 2:
993            dp['firstname'] = names[0].capitalize()
994            dp['lastname'] = names[1].capitalize()
995        else:
996            dp['lastname'] = app_doc.jamb_lastname
997        dp['sex'] = app_doc.jamb_sex == 'F'
998        dp['lga'] = "%s/%s" % (app_doc.jamb_state,app_doc.jamb_lga )
999        proxy = self.aq_parent
1000        proxy.invokeFactory('StudentPersonal','personal')
1001        per = proxy.personal
1002        per_doc = per.getContent()
1003        per_doc.edit(mapping = dp)
[927]1004        per.manage_setLocalRoles(proxy.getId(), ['Owner',])
[764]1005        #self.portal_workflow.doActionFor(per,'open',dest_container=per)
[603]1006
[511]1007###)
1008
[57]1009InitializeClass(Student)
1010
1011def addStudent(container, id, REQUEST=None, **kw):
1012    """Add a Student."""
1013    ob = Student(id, **kw)
1014    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1015
1016###)
[91]1017
[639]1018class StudentAccommodation(CPSDocument): ###(
1019    """
1020    WAeUP Student container for the various student data
1021    """
1022    meta_type = 'StudentAccommodation'
1023    portal_type = meta_type
1024    security = ClassSecurityInfo()
1025
1026    security.declareProtected(View,"Title")
1027    def Title(self):
1028        """compose title"""
1029        content = self.getContent()
1030        #return "Accommodation Data for %s %s" % (content.firstname,content.lastname)
1031        return "Accommodation Data for Session %s" % content.session
1032
1033
1034InitializeClass(StudentAccommodation)
1035
1036def addStudentAccommodation(container, id, REQUEST=None, **kw):
1037    """Add a Students personal data."""
1038    ob = StudentAccommodation(id, **kw)
1039    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1040
1041###)
1042
[89]1043class StudentPersonal(CPSDocument): ###(
1044    """
[154]1045    WAeUP Student container for the various student data
[89]1046    """
1047    meta_type = 'StudentPersonal'
1048    portal_type = meta_type
1049    security = ClassSecurityInfo()
[152]1050
1051    security.declareProtected(View,"Title")
1052    def Title(self):
1053        """compose title"""
1054        content = self.getContent()
[364]1055        #return "Personal Data for %s %s" % (content.firstname,content.lastname)
1056        return "Personal Data"
[152]1057
[154]1058
[89]1059InitializeClass(StudentPersonal)
1060
1061def addStudentPersonal(container, id, REQUEST=None, **kw):
1062    """Add a Students personal data."""
1063    ob = StudentPersonal(id, **kw)
1064    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1065
1066###)
1067
[423]1068class StudentClearance(CPSDocument): ###(
1069    """
1070    WAeUP Student container for the various student data
1071    """
1072    meta_type = 'StudentClearance'
1073    portal_type = meta_type
1074    security = ClassSecurityInfo()
1075
1076    security.declareProtected(View,"Title")
1077    def Title(self):
1078        """compose title"""
1079        content = self.getContent()
[840]1080        #return "Clearance/Eligibility Record for %s %s" % (content.firstname,content.lastname)
1081        return "Clearance/Eligibility Record"
[423]1082
1083
1084InitializeClass(StudentClearance)
1085
1086def addStudentClearance(container, id, REQUEST=None, **kw):
1087    """Add a Students personal data."""
1088    ob = StudentClearance(id, **kw)
1089    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1090
1091###)
1092
[454]1093class StudentStudyLevel(CPSDocument): ###(
1094    """
1095    WAeUP Student container for the various student data
1096    """
1097    meta_type = 'StudentStudyLevel'
1098    portal_type = meta_type
1099    security = ClassSecurityInfo()
1100
1101    security.declareProtected(View,"Title")
1102    def Title(self):
1103        """compose title"""
1104        return "Level %s" % self.aq_parent.getId()
1105
[723]1106##    security.declarePublic("gpa")
1107##    def gpa(self):
1108##        """calculate the gpa"""
1109##        sum = 0
1110##        course_count = 0
1111##        for sc in self.objectValues():
1112##            result = sc.getContent()
1113##            if not result.grade:
1114##                continue
1115##            res = self.portal_catalog({'meta_type': 'Course',
1116##                                          'id': sc.aq_parent.id})
1117##            if len(res) != 1:
1118##                continue
1119##            course = res[0].getObject().getContent()
1120##            sum += course.credits * ['F','E','D','C','B','A'].index(result.grade)
1121##            course_count += 1
1122##        if course_count:
1123##            return sum/course_count
1124##        return 0.0
[472]1125
[454]1126InitializeClass(StudentStudyLevel)
1127
1128def addStudentStudyLevel(container, id, REQUEST=None, **kw):
1129    """Add a Students personal data."""
1130    ob = StudentStudyLevel(id, **kw)
1131    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1132
1133###)
1134
[362]1135class StudentStudyCourse(CPSDocument): ###(
1136    """
1137    WAeUP Student container for the various student data
1138    """
1139    meta_type = 'StudentStudyCourse'
1140    portal_type = meta_type
1141    security = ClassSecurityInfo()
1142
[364]1143    security.declareProtected(View,"Title")
1144    def Title(self):
1145        """compose title"""
1146        content = self.getContent()
[453]1147        return "Study Course"
[362]1148
1149
1150InitializeClass(StudentStudyCourse)
1151
1152def addStudentStudyCourse(container, id, REQUEST=None, **kw):
1153    """Add a Students personal data."""
1154    ob = StudentStudyCourse(id, **kw)
1155    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1156
1157###)
1158
[472]1159class StudentApplication(CPSDocument): ###(
[179]1160    """
1161    WAeUP Student container for the various student data
1162    """
[472]1163    meta_type = 'StudentApplication'
[179]1164    portal_type = meta_type
1165    security = ClassSecurityInfo()
1166
[181]1167    security.declareProtected(View,"Title")
1168    def Title(self):
1169        """compose title"""
[472]1170        return "Application Data"
[179]1171
[181]1172
[472]1173InitializeClass(StudentApplication)
[179]1174
[472]1175def addStudentApplication(container, id, REQUEST=None, **kw):
[179]1176    """Add a Students eligibility data."""
[472]1177    ob = StudentApplication(id, **kw)
[179]1178    return CPSBase_adder(container, ob, REQUEST=REQUEST)
[763]1179###)
[179]1180
[758]1181
1182class StudentPume(CPSDocument): ###(
1183    """
1184    WAeUP Student container for the various student data
1185    """
1186    meta_type = 'StudentPume'
1187    portal_type = meta_type
1188    security = ClassSecurityInfo()
1189
1190    security.declareProtected(View,"Title")
1191    def Title(self):
1192        """compose title"""
1193        return "PUME Results"
1194
1195
1196InitializeClass(StudentPume)
1197
1198def addStudentPume(container, id, REQUEST=None, **kw):
1199    """Add a Students PUME data."""
1200    ob = StudentPume(id, **kw)
1201    return CPSBase_adder(container, ob, REQUEST=REQUEST)
[179]1202###)
[181]1203
[565]1204##class StudentSemester(CPSDocument): ###(
1205##    """
1206##    WAeUP StudentSemester containing the courses and students
1207##    """
1208##    meta_type = 'StudentSemester'
1209##    portal_type = meta_type
1210##    security = ClassSecurityInfo()
1211##
1212##InitializeClass(StudentSemester)
1213##
1214##def addStudentSemester(container, id, REQUEST=None, **kw):
1215##    """Add a StudentSemester."""
1216##    ob = StudentSemester(id, **kw)
1217##    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1218##
1219#####)
[464]1220
[758]1221##class Semester(CPSDocument): ###(
1222##    """
1223##    WAeUP Semester containing the courses and students
1224##    """
1225##    meta_type = 'Semester'
1226##    portal_type = meta_type
1227##    security = ClassSecurityInfo()
1228##
1229##InitializeClass(Semester)
1230##
1231##def addSemester(container, id, REQUEST=None, **kw):
1232##    """Add a Semester."""
1233##    ob = Semester(id, **kw)
1234##    return CPSBase_adder(container, ob, REQUEST=REQUEST)
1235##
1236#####)
[464]1237
1238class StudentCourseResult(CPSDocument): ###(
[89]1239    """
[464]1240    WAeUP StudentCourseResult
[89]1241    """
[464]1242    meta_type = 'StudentCourseResult'
[89]1243    portal_type = meta_type
1244    security = ClassSecurityInfo()
[472]1245
[454]1246    def getCourseEntry(self,cid):
[723]1247        res = self.portal_catalog({'meta_type': "Course",
[454]1248                                           'id': cid})
1249        if res:
1250            return res[-1]
1251        else:
1252            return None
[154]1253
[454]1254    security.declareProtected(View,"Title")
1255    def Title(self):
1256        """compose title"""
[723]1257        cid = self.aq_parent.getId()
[454]1258        ce = self.getCourseEntry(cid)
1259        if ce:
1260            return "%s" % ce.Title
1261        return "No course with id %s" % cid
[152]1262
[464]1263InitializeClass(StudentCourseResult)
[454]1264
[464]1265def addStudentCourseResult(container, id, REQUEST=None, **kw):
1266    """Add a StudentCourseResult."""
1267    ob = StudentCourseResult(id, **kw)
[89]1268    return CPSBase_adder(container, ob, REQUEST=REQUEST)
[139]1269###)
1270
[579]1271# Backward Compatibility StudyLevel
1272
1273from Products.WAeUP_SRP.Academics import StudyLevel
1274
1275from Products.WAeUP_SRP.Academics import addStudyLevel
1276
Note: See TracBrowser for help on using the repository browser.