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