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