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