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