[57] | 1 | #-*- mode: python; mode: fold -*- |
---|
[200] | 2 | # $Id: Students.py 1751 2007-05-08 06:17:53Z henrik $ |
---|
[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 |
---|
[1649] | 18 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
[362] | 19 | import logging |
---|
[971] | 20 | import csv,re,os |
---|
[362] | 21 | import Globals |
---|
| 22 | p_home = Globals.package_home(globals()) |
---|
| 23 | i_home = Globals.INSTANCE_HOME |
---|
[981] | 24 | MAX_TRANS = 1000 |
---|
[1599] | 25 | from urllib import urlencode |
---|
| 26 | |
---|
[966] | 27 | import DateTime |
---|
[1711] | 28 | import PIL.Image |
---|
[971] | 29 | from StringIO import StringIO |
---|
[154] | 30 | |
---|
[958] | 31 | def makeCertificateCode(code): ###( |
---|
| 32 | code = code.replace('.','') |
---|
| 33 | code = code.replace('(','') |
---|
| 34 | code = code.replace(')','') |
---|
| 35 | code = code.replace('/','') |
---|
| 36 | code = code.replace(' ','') |
---|
| 37 | code = code.replace('_','') |
---|
| 38 | return code |
---|
| 39 | |
---|
| 40 | ###) |
---|
| 41 | |
---|
[1599] | 42 | def response_write(response,s): |
---|
| 43 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 44 | while s.find('<') > -1: |
---|
| 45 | s = s.replace('<','<') |
---|
| 46 | while s.find('>') > -1: |
---|
| 47 | #from pdb import set_trace;set_trace() |
---|
| 48 | s = s.replace('>','>') |
---|
| 49 | response.write("%s<br>\n" % s) |
---|
| 50 | |
---|
[958] | 51 | def getInt(s): ###( |
---|
[723] | 52 | try: |
---|
| 53 | return int(s) |
---|
| 54 | except: |
---|
| 55 | return 0 |
---|
[422] | 56 | |
---|
[725] | 57 | def getFloat(s): |
---|
| 58 | try: |
---|
| 59 | return float(s) |
---|
| 60 | except: |
---|
| 61 | return 0.0 |
---|
| 62 | |
---|
[958] | 63 | ###) |
---|
| 64 | |
---|
[714] | 65 | def getStudentByRegNo(self,reg_no): ###( |
---|
[502] | 66 | """search student by JAMB Reg No and return StudentFolder""" |
---|
| 67 | search = ZCatalog.searchResults(self.portal_catalog,{'meta_type': 'StudentApplication', |
---|
[606] | 68 | 'SearchableText': reg_no, |
---|
[502] | 69 | }) |
---|
| 70 | if len(search) < 1: |
---|
| 71 | return None |
---|
| 72 | return search[0].getObject().aq_parent |
---|
| 73 | |
---|
[714] | 74 | ###) |
---|
| 75 | |
---|
[1111] | 76 | def checkJambNo(jnr): |
---|
| 77 | try: |
---|
| 78 | if len(jnr) != 10: |
---|
| 79 | return False |
---|
| 80 | except: |
---|
| 81 | return False |
---|
| 82 | try: |
---|
| 83 | int(jnr[:8]) |
---|
| 84 | return True |
---|
| 85 | except: |
---|
| 86 | return False |
---|
[1119] | 87 | |
---|
[361] | 88 | class StudentsFolder(CPSDocument): ###( |
---|
| 89 | """ |
---|
| 90 | WAeUP container for the various WAeUP containers data |
---|
| 91 | """ |
---|
[362] | 92 | meta_type = 'StudentsFolder' |
---|
[361] | 93 | portal_type = meta_type |
---|
| 94 | security = ClassSecurityInfo() |
---|
[154] | 95 | |
---|
[1121] | 96 | security.declareProtected(ModifyPortalContent,"createDEStudents")###( |
---|
| 97 | def createDEStudents(self): |
---|
| 98 | """load Fulltime Studentdata from CSV values""" |
---|
| 99 | import transaction |
---|
| 100 | import random |
---|
| 101 | #from pdb import set_trace |
---|
| 102 | wftool = self.portal_workflow |
---|
| 103 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 104 | csv_d = {'jamb_reg_no': "RegNumber", |
---|
| 105 | 'jamb_lastname': "Name", |
---|
| 106 | 'session': "Session", |
---|
| 107 | 'pume_tot_score': "PUDE SCORE", |
---|
| 108 | ##'jamb_score': "JambScore", |
---|
| 109 | 'entry_mode': "EntryMode", |
---|
| 110 | 'jamb_sex': "Sex", |
---|
| 111 | 'jamb_state': "State", |
---|
| 112 | 'jamb_first_cos': "AdminCourse", |
---|
| 113 | 'faculty': "AdminFaculty", |
---|
| 114 | 'course_code': "AdmitCoscode", |
---|
| 115 | 'stud_status':"AdmitStatus", |
---|
| 116 | 'department': "AdmitDept", |
---|
| 117 | 'jamb_lga': "LGA", |
---|
| 118 | 'app_email': "email", |
---|
| 119 | 'app_mobile': "PhoneNumbers", |
---|
| 120 | } |
---|
| 121 | csv_fields = [f[1] for f in csv_d.items()] |
---|
| 122 | tr_count = 0 |
---|
| 123 | total = 0 |
---|
| 124 | #name = 'pume_results' |
---|
| 125 | name = 'DE_Admitted' |
---|
| 126 | no_import = [] |
---|
[1321] | 127 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
---|
[1121] | 128 | no_import.append('"Error",%s' % s) |
---|
| 129 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
---|
| 130 | no_certificate = "no certificate %s" % format |
---|
| 131 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import)) |
---|
[1571] | 132 | logger = logging.getLogger('Students.StudentsFolder.createDEStudents') |
---|
| 133 | logger.info('Start loading from %s.csv' % name) |
---|
[1121] | 134 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 135 | certs = {} |
---|
| 136 | cert_docs = {} |
---|
| 137 | for f in l: |
---|
| 138 | certs[f.getId] = f.getObject().getContent() |
---|
| 139 | try: |
---|
| 140 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 141 | except: |
---|
| 142 | logger.error('Error reading %s.csv' % name) |
---|
| 143 | return |
---|
| 144 | for jamb in result: |
---|
[1571] | 145 | jamb['Error'] = "Processing" |
---|
[1121] | 146 | logger.info(format % jamb) |
---|
| 147 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) |
---|
| 148 | res = self.portal_catalog({'portal_type': "StudentApplication", |
---|
| 149 | 'SearchableText': jamb_reg_no }) |
---|
| 150 | if res: |
---|
| 151 | em = 'Student with RegNo %s already exists\n' % jamb_reg_no |
---|
| 152 | logger.info(em) |
---|
| 153 | jamb['Error'] = "Student exists" |
---|
| 154 | no_import.append(format % jamb) |
---|
| 155 | continue |
---|
| 156 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) |
---|
| 157 | if cert_id not in certs.keys(): |
---|
| 158 | em = 'No Certificate with ID %s \n' % cert_id |
---|
| 159 | logger.info(em) |
---|
| 160 | jamb['Error'] = "No Certificate %s" % cert_id |
---|
| 161 | no_import.append( format % jamb) |
---|
| 162 | continue |
---|
| 163 | jamb_reg_no =jamb.get(csv_d['jamb_reg_no']) |
---|
| 164 | cert_doc = certs[cert_id] |
---|
| 165 | catalog_entry = {} |
---|
| 166 | catalog_entry['jamb_reg_no'] = jamb_reg_no |
---|
| 167 | jamb_name = jamb.get(csv_d['jamb_lastname']) |
---|
| 168 | jamb_name.replace('>','') |
---|
| 169 | jamb_name.replace('<','') |
---|
| 170 | names = jamb_name.split() |
---|
| 171 | letter = names[-1][0].upper() |
---|
| 172 | sid = self.generateStudentId(letter) |
---|
| 173 | not_created = True |
---|
| 174 | while not_created: |
---|
| 175 | try: |
---|
| 176 | students_folder.invokeFactory('Student', sid) |
---|
| 177 | not_created = False |
---|
| 178 | except BadRequest: |
---|
| 179 | sid = self.generateStudentId(letter) |
---|
| 180 | catalog_entry['id'] = sid |
---|
| 181 | tr_count += 1 |
---|
| 182 | logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) |
---|
| 183 | student = getattr(self,sid) |
---|
| 184 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 185 | student.invokeFactory('StudentPume','pume') |
---|
| 186 | dp = {'Title': 'Pume Data'} |
---|
| 187 | student.invokeFactory('StudentApplication','application') |
---|
| 188 | da = {'Title': 'Application Data'} |
---|
| 189 | da["jamb_lastname"] = jamb_name |
---|
| 190 | da_fields = ('jamb_reg_no', |
---|
| 191 | 'jamb_sex', |
---|
| 192 | 'entry_mode', |
---|
| 193 | #'jamb_score', |
---|
| 194 | 'jamb_first_cos', |
---|
| 195 | 'jamb_sex', |
---|
| 196 | 'jamb_state', |
---|
| 197 | 'jamb_lga', |
---|
| 198 | 'app_email', |
---|
| 199 | 'app_mobile', |
---|
| 200 | ) |
---|
| 201 | for f in da_fields: |
---|
| 202 | da[f] = jamb.get(csv_d[f]) |
---|
| 203 | catalog_entry['email'] = jamb.get(csv_d['app_email']) |
---|
| 204 | app = student.application |
---|
| 205 | app_doc = app.getContent() |
---|
| 206 | picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no) |
---|
| 207 | #import pdb;pdb.set_trace() |
---|
| 208 | if os.path.exists(picture): |
---|
| 209 | file = open(picture) |
---|
| 210 | if False: |
---|
| 211 | img = PIL.Image.open(file) |
---|
| 212 | img.thumbnail((150,200), |
---|
| 213 | resample=PIL.Image.ANTIALIAS) |
---|
| 214 | # We now need a buffer to write to. It can't be the same |
---|
| 215 | # as the inbuffer as the PNG writer will write over itself. |
---|
| 216 | outfile = StringIO() |
---|
| 217 | img.save(outfile, format=img.format) |
---|
| 218 | else: |
---|
| 219 | outfile = file.read() |
---|
| 220 | app_doc.manage_addFile('passport', |
---|
| 221 | file=outfile, |
---|
| 222 | title="%s.jpg" % jamb_reg_no) |
---|
| 223 | app.getContent().edit(mapping=da) |
---|
| 224 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 225 | #wftool.doActionFor(app,'close') |
---|
| 226 | dp_fields = ( |
---|
| 227 | #'pume_eng_score', |
---|
| 228 | #'pume_gen_score', |
---|
| 229 | 'pume_tot_score', |
---|
| 230 | ) |
---|
| 231 | dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded" |
---|
| 232 | pume = student.pume |
---|
| 233 | pume.getContent().edit(mapping=dp) |
---|
| 234 | #wftool.doActionFor(pume,'close') |
---|
| 235 | pume.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 236 | #student.getContent().createSubObjects() |
---|
| 237 | dp = {} |
---|
| 238 | if len(names) == 3: |
---|
| 239 | dp['firstname'] = names[0].capitalize() |
---|
| 240 | dp['middlename'] = names[1].capitalize() |
---|
| 241 | dp['lastname'] = names[2].capitalize() |
---|
| 242 | elif len(names) == 2: |
---|
| 243 | dp['firstname'] = names[0].capitalize() |
---|
| 244 | dp['middlename'] = '' |
---|
| 245 | dp['lastname'] = names[1].capitalize() |
---|
| 246 | else: |
---|
| 247 | dp['firstname'] = '' |
---|
| 248 | dp['middlename'] = '' |
---|
| 249 | dp['lastname'] = jamb_name |
---|
| 250 | dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F' |
---|
| 251 | catalog_entry['sex'] = dp['sex'] |
---|
| 252 | catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp |
---|
| 253 | student.invokeFactory('StudentPersonal','personal') |
---|
| 254 | per = student.personal |
---|
| 255 | per_doc = per.getContent() |
---|
| 256 | per_doc.edit(mapping = dp) |
---|
| 257 | per.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 258 | if jamb.get(csv_d['stud_status']) == "Admitted": |
---|
| 259 | wftool.doActionFor(student,'pume_pass') |
---|
| 260 | wftool.doActionFor(student,'admit') |
---|
| 261 | else: |
---|
| 262 | wftool.doActionFor(student,'pume_fail') |
---|
| 263 | wftool.doActionFor(student,'reject_admission') |
---|
| 264 | continue |
---|
| 265 | # |
---|
| 266 | # Clearance |
---|
| 267 | # |
---|
| 268 | student.invokeFactory('StudentClearance','clearance') |
---|
| 269 | #wftool.doActionFor(student.clearance,'open') |
---|
| 270 | dp = {'Title': 'Clearance/Eligibility Record'} |
---|
| 271 | student.clearance.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 272 | # |
---|
| 273 | # Study Course |
---|
| 274 | # |
---|
| 275 | student.invokeFactory('StudentStudyCourse','study_course') |
---|
| 276 | study_course = student.study_course |
---|
| 277 | dsc = {} |
---|
[1386] | 278 | #from_certificate = ['title', |
---|
| 279 | # 'max_elect', |
---|
| 280 | # 'max_pass', |
---|
| 281 | # 'n_core', |
---|
| 282 | # 'nr_years', |
---|
| 283 | # 'probation_credits', |
---|
| 284 | # 'promotion_credits', |
---|
| 285 | # 'start_level', |
---|
| 286 | # ] |
---|
| 287 | #for f in from_certificate: |
---|
| 288 | # dsc[f] = getattr(cert_doc,f) |
---|
| 289 | #dsc['faculty'] = jamb.get(csv_d['faculty']) |
---|
| 290 | #dsc['department'] = jamb.get(csv_d['department']) |
---|
[1121] | 291 | catalog_entry['faculty'] = jamb.get(csv_d['faculty']) |
---|
| 292 | catalog_entry['department'] = jamb.get(csv_d['department']) |
---|
| 293 | catalog_entry['course'] = cert_id |
---|
[1386] | 294 | #catalog_entry['level'] = getattr(cert_doc,'start_level') |
---|
| 295 | catalog_entry['level'] = '200' |
---|
[1121] | 296 | dsc['study_course'] = cert_id |
---|
[1386] | 297 | dsc['current_level'] = '200' |
---|
| 298 | #dsc['entry_session'] = jamb.get(csv_d['session']) |
---|
[1121] | 299 | study_course.getContent().edit(mapping=dsc) |
---|
| 300 | self.students_catalog.addRecord(**catalog_entry) |
---|
[1124] | 301 | if tr_count > 10: |
---|
[1121] | 302 | if len(no_import) > 1: |
---|
[1127] | 303 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
[1262] | 304 | '\n'.join(no_import)+'\n') |
---|
[1121] | 305 | no_import = [] |
---|
| 306 | em = '%d transactions commited\n' % tr_count |
---|
| 307 | transaction.commit() |
---|
| 308 | logger.info(em) |
---|
| 309 | total += tr_count |
---|
| 310 | tr_count = 0 |
---|
[1127] | 311 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
[1125] | 312 | '\n'.join(no_import)) |
---|
[1121] | 313 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 314 | ###) |
---|
| 315 | |
---|
[966] | 316 | security.declareProtected(ModifyPortalContent,"createNewStudents")###( |
---|
| 317 | def createNewStudents(self): |
---|
[742] | 318 | """load Fulltime Studentdata from CSV values""" |
---|
| 319 | import transaction |
---|
| 320 | import random |
---|
[971] | 321 | #from pdb import set_trace |
---|
[763] | 322 | wftool = self.portal_workflow |
---|
[757] | 323 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
[971] | 324 | csv_d = {'jamb_reg_no': "RegNumber", |
---|
[958] | 325 | 'jamb_lastname': "Name", |
---|
[971] | 326 | 'session': "Session", |
---|
| 327 | 'pume_tot_score': "PUME SCORE", |
---|
| 328 | 'jamb_score': "JambScore", |
---|
[958] | 329 | 'jamb_sex': "Sex", |
---|
[971] | 330 | 'jamb_state': "State", |
---|
[980] | 331 | ## 'jamb_first_cos': "AdminCourse", |
---|
[971] | 332 | 'faculty': "AdminFaculty", |
---|
| 333 | 'course_code': "AdmitCoscode", |
---|
| 334 | 'stud_status':"AdmitStatus", |
---|
| 335 | 'department': "AdmitDept", |
---|
| 336 | 'jamb_lga': "LGA", |
---|
| 337 | 'app_email': "email", |
---|
[980] | 338 | 'app_mobile': "PhoneNumbers", |
---|
[958] | 339 | } |
---|
| 340 | csv_fields = [f[1] for f in csv_d.items()] |
---|
| 341 | tr_count = 0 |
---|
[961] | 342 | total = 0 |
---|
[958] | 343 | #name = 'pume_results' |
---|
[971] | 344 | name = 'Admitted' |
---|
[958] | 345 | no_import = [] |
---|
[1319] | 346 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
---|
[971] | 347 | no_import.append('"Error",%s' % s) |
---|
| 348 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
---|
| 349 | no_certificate = "no certificate %s" % format |
---|
[1121] | 350 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import)) |
---|
[1571] | 351 | logger = logging.getLogger('Students.StudentsFolder.createNewStudents') |
---|
| 352 | logger.info('Start loading from %s.csv' % name) |
---|
[971] | 353 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 354 | certs = {} |
---|
| 355 | cert_docs = {} |
---|
| 356 | for f in l: |
---|
| 357 | certs[f.getId] = f.getObject().getContent() |
---|
[958] | 358 | try: |
---|
| 359 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 360 | except: |
---|
| 361 | logger.error('Error reading %s.csv' % name) |
---|
| 362 | return |
---|
| 363 | for jamb in result: |
---|
[971] | 364 | jamb['Error'] = "Processing " |
---|
| 365 | logger.info(format % jamb) |
---|
[958] | 366 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) |
---|
| 367 | res = self.portal_catalog({'portal_type': "StudentApplication", |
---|
[959] | 368 | 'SearchableText': jamb_reg_no }) |
---|
[958] | 369 | if res: |
---|
[980] | 370 | em = 'Student with RegNo %s already exists\n' % jamb_reg_no |
---|
[958] | 371 | logger.info(em) |
---|
[971] | 372 | jamb['Error'] = "Student exists" |
---|
[958] | 373 | no_import.append(format % jamb) |
---|
| 374 | continue |
---|
[971] | 375 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) |
---|
| 376 | if cert_id not in certs.keys(): |
---|
[958] | 377 | em = 'No Certificate with ID %s \n' % cert_id |
---|
| 378 | logger.info(em) |
---|
[971] | 379 | jamb['Error'] = "No Certificate %s" % cert_id |
---|
| 380 | no_import.append( format % jamb) |
---|
[958] | 381 | continue |
---|
[1121] | 382 | res = self.portal_pumeresults(jamb_reg_no = jamb_reg_no) |
---|
| 383 | if len(res) == 1: |
---|
| 384 | self.portal_pumeresults.modifyRecord(jamb_reg_no = jamb_reg_no, |
---|
| 385 | status = jamb.get(csv_d['stud_status']), |
---|
| 386 | ) |
---|
| 387 | jamb_reg_no =jamb.get(csv_d['jamb_reg_no']) |
---|
[971] | 388 | cert_doc = certs[cert_id] |
---|
| 389 | catalog_entry = {} |
---|
| 390 | catalog_entry['jamb_reg_no'] = jamb_reg_no |
---|
[958] | 391 | jamb_name = jamb.get(csv_d['jamb_lastname']) |
---|
| 392 | jamb_name.replace('>','') |
---|
[966] | 393 | jamb_name.replace('<','') |
---|
[958] | 394 | names = jamb_name.split() |
---|
| 395 | letter = names[-1][0].upper() |
---|
| 396 | sid = self.generateStudentId(letter) |
---|
| 397 | not_created = True |
---|
| 398 | while not_created: |
---|
| 399 | try: |
---|
| 400 | students_folder.invokeFactory('Student', sid) |
---|
| 401 | not_created = False |
---|
| 402 | except BadRequest: |
---|
| 403 | sid = self.generateStudentId(letter) |
---|
[971] | 404 | catalog_entry['id'] = sid |
---|
[958] | 405 | tr_count += 1 |
---|
[1720] | 406 | logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s reg_no %(jamb_reg_no)s ' % vars()) |
---|
[958] | 407 | student = getattr(self,sid) |
---|
| 408 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 409 | student.invokeFactory('StudentPume','pume') |
---|
| 410 | dp = {'Title': 'Pume Data'} |
---|
| 411 | student.invokeFactory('StudentApplication','application') |
---|
| 412 | da = {'Title': 'Application Data'} |
---|
| 413 | da["jamb_lastname"] = jamb_name |
---|
| 414 | da_fields = ('jamb_reg_no', |
---|
| 415 | 'jamb_sex', |
---|
| 416 | #'jamb_state', |
---|
[966] | 417 | 'jamb_score', |
---|
[980] | 418 | ## 'jamb_first_cos', |
---|
[958] | 419 | 'jamb_sex', |
---|
[971] | 420 | 'jamb_state', |
---|
| 421 | 'jamb_lga', |
---|
| 422 | 'app_email', |
---|
[980] | 423 | 'app_mobile', |
---|
[958] | 424 | ) |
---|
| 425 | for f in da_fields: |
---|
| 426 | da[f] = jamb.get(csv_d[f]) |
---|
[971] | 427 | catalog_entry['email'] = jamb.get(csv_d['app_email']) |
---|
[958] | 428 | app = student.application |
---|
[971] | 429 | app_doc = app.getContent() |
---|
| 430 | #import pdb;pdb.set_trace() |
---|
[1707] | 431 | picture ="%s/import/pictures/%s.jpg" % (i_home,picture_id) |
---|
[971] | 432 | if os.path.exists(picture): |
---|
| 433 | file = open(picture) |
---|
[974] | 434 | if False: |
---|
| 435 | img = PIL.Image.open(file) |
---|
| 436 | img.thumbnail((150,200), |
---|
| 437 | resample=PIL.Image.ANTIALIAS) |
---|
| 438 | # We now need a buffer to write to. It can't be the same |
---|
| 439 | # as the inbuffer as the PNG writer will write over itself. |
---|
| 440 | outfile = StringIO() |
---|
| 441 | img.save(outfile, format=img.format) |
---|
| 442 | else: |
---|
| 443 | outfile = file.read() |
---|
[971] | 444 | app_doc.manage_addFile('passport', |
---|
| 445 | file=outfile, |
---|
| 446 | title="%s.jpg" % jamb_reg_no) |
---|
[958] | 447 | app.getContent().edit(mapping=da) |
---|
| 448 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 449 | #wftool.doActionFor(app,'close') |
---|
| 450 | dp_fields = ( |
---|
| 451 | #'pume_eng_score', |
---|
| 452 | #'pume_gen_score', |
---|
| 453 | 'pume_tot_score', |
---|
| 454 | ) |
---|
[964] | 455 | dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded" |
---|
[958] | 456 | pume = student.pume |
---|
| 457 | pume.getContent().edit(mapping=dp) |
---|
| 458 | #wftool.doActionFor(pume,'close') |
---|
| 459 | pume.manage_setLocalRoles(sid, ['Owner',]) |
---|
[966] | 460 | #student.getContent().createSubObjects() |
---|
[975] | 461 | dp = {} |
---|
[966] | 462 | if len(names) == 3: |
---|
| 463 | dp['firstname'] = names[0].capitalize() |
---|
| 464 | dp['middlename'] = names[1].capitalize() |
---|
| 465 | dp['lastname'] = names[2].capitalize() |
---|
| 466 | elif len(names) == 2: |
---|
| 467 | dp['firstname'] = names[0].capitalize() |
---|
[971] | 468 | dp['middlename'] = '' |
---|
[966] | 469 | dp['lastname'] = names[1].capitalize() |
---|
| 470 | else: |
---|
[971] | 471 | dp['firstname'] = '' |
---|
| 472 | dp['middlename'] = '' |
---|
[966] | 473 | dp['lastname'] = jamb_name |
---|
| 474 | dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F' |
---|
[971] | 475 | catalog_entry['sex'] = dp['sex'] |
---|
| 476 | catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp |
---|
[966] | 477 | student.invokeFactory('StudentPersonal','personal') |
---|
| 478 | per = student.personal |
---|
| 479 | per_doc = per.getContent() |
---|
| 480 | per_doc.edit(mapping = dp) |
---|
| 481 | per.manage_setLocalRoles(sid, ['Owner',]) |
---|
[958] | 482 | if jamb.get(csv_d['stud_status']) == "Admitted": |
---|
| 483 | wftool.doActionFor(student,'pume_pass') |
---|
| 484 | wftool.doActionFor(student,'admit') |
---|
| 485 | else: |
---|
| 486 | wftool.doActionFor(student,'pume_fail') |
---|
| 487 | wftool.doActionFor(student,'reject_admission') |
---|
| 488 | continue |
---|
[964] | 489 | # |
---|
[966] | 490 | # Clearance |
---|
| 491 | # |
---|
| 492 | student.invokeFactory('StudentClearance','clearance') |
---|
| 493 | #wftool.doActionFor(student.clearance,'open') |
---|
| 494 | dp = {'Title': 'Clearance/Eligibility Record'} |
---|
| 495 | student.clearance.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 496 | # |
---|
[964] | 497 | # Study Course |
---|
| 498 | # |
---|
[958] | 499 | student.invokeFactory('StudentStudyCourse','study_course') |
---|
| 500 | study_course = student.study_course |
---|
| 501 | dsc = {} |
---|
[1386] | 502 | #from_certificate = ['title', |
---|
| 503 | # 'max_elect', |
---|
| 504 | # 'max_pass', |
---|
| 505 | # 'n_core', |
---|
| 506 | # 'nr_years', |
---|
| 507 | # 'probation_credits', |
---|
| 508 | # 'promotion_credits', |
---|
| 509 | # 'start_level', |
---|
| 510 | # ] |
---|
| 511 | #for f in from_certificate: |
---|
| 512 | # dsc[f] = getattr(cert_doc,f) |
---|
| 513 | #dsc['faculty'] = jamb.get(csv_d['faculty']) |
---|
| 514 | #dsc['department'] = jamb.get(csv_d['department']) |
---|
[971] | 515 | catalog_entry['faculty'] = jamb.get(csv_d['faculty']) |
---|
| 516 | catalog_entry['department'] = jamb.get(csv_d['department']) |
---|
| 517 | catalog_entry['course'] = cert_id |
---|
[1386] | 518 | #catalog_entry['level'] = getattr(cert_doc,'start_level') |
---|
| 519 | catalog_entry['level'] = '100' |
---|
[958] | 520 | dsc['study_course'] = cert_id |
---|
[1749] | 521 | #dsc['entry_level'] = '100' |
---|
[1386] | 522 | #dsc['entry_session'] = jamb.get(csv_d['session']) |
---|
[958] | 523 | study_course.getContent().edit(mapping=dsc) |
---|
[971] | 524 | self.students_catalog.addRecord(**catalog_entry) |
---|
[1126] | 525 | if tr_count > 10: |
---|
| 526 | if len(no_import) > 0: |
---|
[1127] | 527 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
[1264] | 528 | '\n'.join(no_import) + "\n") |
---|
[966] | 529 | no_import = [] |
---|
[961] | 530 | em = '%d transactions commited\n' % tr_count |
---|
[958] | 531 | transaction.commit() |
---|
| 532 | logger.info(em) |
---|
[961] | 533 | total += tr_count |
---|
[958] | 534 | tr_count = 0 |
---|
[1127] | 535 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
[1126] | 536 | '\n'.join(no_import)) |
---|
[958] | 537 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 538 | ###) |
---|
| 539 | |
---|
[1707] | 540 | security.declareProtected(ModifyPortalContent,"createStudents")###( |
---|
| 541 | def createStudents(self): |
---|
| 542 | """load Studentdata from CSV values""" |
---|
[1700] | 543 | import transaction |
---|
| 544 | import random |
---|
| 545 | #from pdb import set_trace |
---|
| 546 | wftool = self.portal_workflow |
---|
| 547 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
[1749] | 548 | #entry_levels = {'ume_ft':'100', |
---|
| 549 | # 'de_ft': '200', |
---|
| 550 | # 'ug_pt': '100', |
---|
| 551 | # 'de_pt': '200', |
---|
| 552 | # 'pg_ft': '700', |
---|
| 553 | # 'pg_pt': '700', |
---|
| 554 | # 'dp_pt': '100', |
---|
| 555 | # 'dp_ft': '100', |
---|
[1751] | 556 | # } |
---|
[1707] | 557 | csv_d = {'jamb_reg_no': "reg_no", |
---|
| 558 | 'entry_mode': 'entry_mode', |
---|
| 559 | 'jamb_firstname': "firstname", |
---|
| 560 | 'jamb_middlename': "middlename", |
---|
| 561 | 'jamb_lastname': "lastname", |
---|
| 562 | 'jamb_sex': "sex", |
---|
| 563 | 'jamb_state': "state", |
---|
| 564 | 'birthday': "date_of_birth", |
---|
[1700] | 565 | 'app_email': "email", |
---|
[1707] | 566 | 'study_course': "study_course", |
---|
| 567 | 'perm_address': "address", |
---|
[1700] | 568 | } |
---|
| 569 | csv_fields = [f[1] for f in csv_d.items()] |
---|
| 570 | tr_count = 0 |
---|
| 571 | total = 0 |
---|
| 572 | #name = 'pume_results' |
---|
| 573 | name = 'Admitted' |
---|
| 574 | no_import = [] |
---|
| 575 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
---|
| 576 | no_import.append('"Error",%s' % s) |
---|
| 577 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
---|
| 578 | no_certificate = "no certificate %s" % format |
---|
| 579 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import)) |
---|
[1721] | 580 | logger = logging.getLogger('Students.StudentsFolder.createStudents') |
---|
[1700] | 581 | logger.info('Start loading from %s.csv' % name) |
---|
| 582 | certs = {} |
---|
| 583 | try: |
---|
[1707] | 584 | results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
[1700] | 585 | except: |
---|
| 586 | logger.error('Error reading %s.csv' % name) |
---|
| 587 | return |
---|
[1707] | 588 | for result in results: |
---|
| 589 | #result['Error'] = "Processing " |
---|
| 590 | #logger.info(format % result) |
---|
| 591 | jamb_reg_no = result.get(csv_d['jamb_reg_no']) |
---|
| 592 | res = self.students_catalog(jamb_reg_no = jamb_reg_no) |
---|
[1700] | 593 | if res: |
---|
| 594 | em = 'Student with RegNo %s already exists\n' % jamb_reg_no |
---|
| 595 | logger.info(em) |
---|
[1707] | 596 | result['Error'] = "Student exists" |
---|
| 597 | no_import.append(format % result) |
---|
[1700] | 598 | continue |
---|
[1707] | 599 | cert_id = makeCertificateCode(result.get(csv_d['study_course'])) |
---|
[1700] | 600 | if cert_id not in certs.keys(): |
---|
[1707] | 601 | res = self.portal_catalog(meta_type = "Certificate",id = cert_id) |
---|
| 602 | if not res: |
---|
| 603 | em = 'No Certificate with ID %s \n' % cert_id |
---|
| 604 | logger.info(em) |
---|
| 605 | result['Error'] = "No Certificate %s" % cert_id |
---|
| 606 | no_import.append( format % result) |
---|
| 607 | continue |
---|
| 608 | cert = res[0] |
---|
| 609 | cert_path = cert.getPath().split('/') |
---|
| 610 | certificate = certs[cert_id] = {'faculty': cert_path[-4], |
---|
| 611 | 'department': cert_path[-3]} |
---|
[1700] | 612 | cert_doc = certs[cert_id] |
---|
| 613 | catalog_entry = {} |
---|
| 614 | catalog_entry['jamb_reg_no'] = jamb_reg_no |
---|
[1707] | 615 | firstname = result.get(csv_d['jamb_firstname']) |
---|
| 616 | middlename = result.get(csv_d['jamb_middlename']) |
---|
| 617 | lastname = result.get(csv_d['jamb_lastname']) |
---|
| 618 | sid = self.generateStudentId('x') |
---|
| 619 | students_folder.invokeFactory('Student', sid) |
---|
[1700] | 620 | catalog_entry['id'] = sid |
---|
| 621 | tr_count += 1 |
---|
[1720] | 622 | logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s reg_no %(jamb_reg_no)s ' % vars()) |
---|
[1700] | 623 | student = getattr(self,sid) |
---|
| 624 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 625 | student.invokeFactory('StudentApplication','application') |
---|
| 626 | da = {'Title': 'Application Data'} |
---|
[1707] | 627 | da["jamb_firstname"] = firstname |
---|
| 628 | da["jamb_middlename"] = middlename |
---|
| 629 | da["jamb_lastname"] = lastname |
---|
| 630 | catalog_entry['entry_session'] = da["entry_session"] = self.getSessionId()[-2:] |
---|
| 631 | catalog_entry['sex'] = sex = result.get(csv_d['jamb_sex']).startswith('F') |
---|
[1700] | 632 | da_fields = ('jamb_reg_no', |
---|
| 633 | 'jamb_sex', |
---|
| 634 | 'jamb_state', |
---|
[1707] | 635 | 'entry_mode', |
---|
[1700] | 636 | 'app_email', |
---|
| 637 | ) |
---|
| 638 | for f in da_fields: |
---|
[1707] | 639 | da[f] = result.get(csv_d[f]) |
---|
| 640 | catalog_entry['email'] = da['app_email'] |
---|
| 641 | catalog_entry['entry_mode'] = da['entry_mode'] |
---|
[1749] | 642 | #catalog_entry['entry_level'] = da["entry_level"] = entry_levels.get(da['entry_mode'],'100') |
---|
[1700] | 643 | app = student.application |
---|
| 644 | app_doc = app.getContent() |
---|
[1707] | 645 | app.getContent().edit(mapping=da) |
---|
[1700] | 646 | picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no) |
---|
[1707] | 647 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
[1720] | 648 | |
---|
[1707] | 649 | picture_id = da['jamb_reg_no'].replace('/','_') |
---|
| 650 | file = None |
---|
| 651 | for ext in ('jpg','JPG'): |
---|
[1710] | 652 | picture ="%s/import/pictures_admitted_latest/%s.%s" % (i_home,picture_id,ext) |
---|
[1707] | 653 | if os.path.exists(picture): |
---|
| 654 | file = open(picture) |
---|
| 655 | break |
---|
| 656 | if file is not None: |
---|
[1720] | 657 | |
---|
| 658 | ## file conversion does not work |
---|
[1712] | 659 | #img = PIL.Image.open(file) |
---|
| 660 | #img.thumbnail((150,200), |
---|
| 661 | # resample=PIL.Image.ANTIALIAS) |
---|
| 662 | #outfile = StringIO() |
---|
[1720] | 663 | #img.save(outfile, format=img.format) |
---|
[1712] | 664 | |
---|
| 665 | outfile = file.read() |
---|
[1700] | 666 | app_doc.manage_addFile('passport', |
---|
| 667 | file=outfile, |
---|
| 668 | title="%s.jpg" % jamb_reg_no) |
---|
| 669 | #wftool.doActionFor(app,'close') |
---|
| 670 | dp = {} |
---|
[1707] | 671 | dp['firstname'] = firstname |
---|
| 672 | dp['middlename'] = middlename |
---|
[1710] | 673 | dp['lastname'] = lastname |
---|
[1707] | 674 | dp['email'] = da['app_email'] |
---|
| 675 | dp['sex'] = sex |
---|
[1700] | 676 | catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp |
---|
| 677 | student.invokeFactory('StudentPersonal','personal') |
---|
| 678 | per = student.personal |
---|
| 679 | per_doc = per.getContent() |
---|
| 680 | per_doc.edit(mapping = dp) |
---|
| 681 | per.manage_setLocalRoles(sid, ['Owner',]) |
---|
[1707] | 682 | wftool.doActionFor(student,'pume_pass') |
---|
| 683 | wftool.doActionFor(student,'admit') |
---|
[1700] | 684 | # |
---|
| 685 | # Clearance |
---|
| 686 | # |
---|
| 687 | student.invokeFactory('StudentClearance','clearance') |
---|
| 688 | #wftool.doActionFor(student.clearance,'open') |
---|
[1707] | 689 | clearance = student.clearance |
---|
| 690 | dc = {'Title': 'Clearance/Eligibility Record'} |
---|
| 691 | clearance = student.clearance |
---|
| 692 | date_str = result.get(csv_d['birthday']) |
---|
[1709] | 693 | try: |
---|
| 694 | date = DateTime.DateTime(date_str) |
---|
| 695 | except: |
---|
| 696 | #import pdb;pdb.set_trace() |
---|
| 697 | date = None |
---|
[1707] | 698 | dc['birthday'] = date |
---|
| 699 | clearance.getContent().edit(mapping=dc) |
---|
| 700 | clearance.manage_setLocalRoles(sid, ['Owner',]) |
---|
[1700] | 701 | # |
---|
| 702 | # Study Course |
---|
| 703 | # |
---|
| 704 | student.invokeFactory('StudentStudyCourse','study_course') |
---|
| 705 | study_course = student.study_course |
---|
| 706 | dsc = {} |
---|
| 707 | #catalog_entry['level'] = getattr(cert_doc,'start_level') |
---|
[1707] | 708 | catalog_entry['session'] = dsc['current_session'] = da['entry_session'] |
---|
[1749] | 709 | #catalog_entry['level'] = dsc['current_level'] = entry_levels.get(da['entry_mode'],'100') |
---|
[1707] | 710 | catalog_entry['mode'] = dsc['current_mode'] = da['entry_mode'] |
---|
| 711 | catalog_entry['course'] = dsc['study_course'] = cert_id |
---|
| 712 | catalog_entry['faculty'] = certificate['faculty'] |
---|
| 713 | catalog_entry['department'] = certificate['department'] |
---|
[1710] | 714 | catalog_entry['verdict'] = dsc['current_verdict'] = 'N/A' |
---|
[1707] | 715 | catalog_entry['review_state'] = self.portal_workflow.getInfoFor(student,'review_state',None) |
---|
[1700] | 716 | study_course.getContent().edit(mapping=dsc) |
---|
[1707] | 717 | #import pdb;pdb.set_trace() |
---|
[1700] | 718 | self.students_catalog.addRecord(**catalog_entry) |
---|
| 719 | if tr_count > 10: |
---|
| 720 | if len(no_import) > 0: |
---|
| 721 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
| 722 | '\n'.join(no_import) + "\n") |
---|
| 723 | no_import = [] |
---|
| 724 | em = '%d transactions commited\n' % tr_count |
---|
| 725 | transaction.commit() |
---|
| 726 | logger.info(em) |
---|
| 727 | total += tr_count |
---|
| 728 | tr_count = 0 |
---|
| 729 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
| 730 | '\n'.join(no_import)) |
---|
| 731 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 732 | ###) |
---|
| 733 | |
---|
[1151] | 734 | security.declareProtected(ModifyPortalContent,"importReturningStudents")###( |
---|
| 735 | def importReturningStudents(self): |
---|
| 736 | """load Returning Studentdata from CSV values""" |
---|
[1146] | 737 | import transaction |
---|
| 738 | import random |
---|
| 739 | #from pdb import set_trace |
---|
| 740 | wftool = self.portal_workflow |
---|
| 741 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
[1616] | 742 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 743 | #students_folder = self.portal_url().getPortalObject().campus.students |
---|
[1146] | 744 | tr_count = 1 |
---|
| 745 | total = 0 |
---|
| 746 | #name = 'pume_results' |
---|
[1151] | 747 | name = 'Returning' |
---|
| 748 | table = self.returning_import |
---|
[1146] | 749 | no_import = [] |
---|
| 750 | imported = [] |
---|
[1571] | 751 | logger = logging.getLogger('Students.StudentsFolder.importReturningStudents') |
---|
[1146] | 752 | try: |
---|
[1151] | 753 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
[1146] | 754 | except: |
---|
| 755 | logger.error('Error reading %s.csv' % name) |
---|
| 756 | return |
---|
| 757 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 758 | certs = {} |
---|
| 759 | cert_docs = {} |
---|
| 760 | for f in l: |
---|
| 761 | certs[f.getId] = f.getObject().getContent() |
---|
| 762 | start = True |
---|
| 763 | res = table() |
---|
| 764 | regs = [] |
---|
| 765 | if len(res) > 0: |
---|
| 766 | regs = [s.matric_no for s in res] |
---|
[1319] | 767 | #import pdb;pdb.set_trace() |
---|
[1151] | 768 | for student in returning: |
---|
[1146] | 769 | if start: |
---|
| 770 | start = False |
---|
[1571] | 771 | logger.info('Start loading from %s.csv' % name) |
---|
[1319] | 772 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
---|
[1146] | 773 | imported.append(s) |
---|
| 774 | no_import.append('%s,"Error"' % s) |
---|
| 775 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
---|
| 776 | format_error = format + ',"%(Error)s"' |
---|
| 777 | no_certificate = "no certificate %s" % format |
---|
[1319] | 778 | student['matric_no'] = matric_no = student.get('matric_no').upper() |
---|
| 779 | student['Mode_of_Entry'] = entry_mode = student.get('Mode of Entry').upper() |
---|
| 780 | student['Permanent_Address'] = perm_address = student.get('Permanent Address') |
---|
[1168] | 781 | if matric_no == '': |
---|
[1252] | 782 | student['Error'] = "Empty matric_no" |
---|
[1146] | 783 | no_import.append( format_error % student) |
---|
| 784 | continue |
---|
[1168] | 785 | if matric_no in regs or self.returning_import(matric_no = matric_no): |
---|
[1252] | 786 | student['Error'] = "Duplicate" |
---|
[1146] | 787 | no_import.append( format_error % student) |
---|
| 788 | continue |
---|
| 789 | cert_id = makeCertificateCode(student.get('Coursemajorcode')) |
---|
| 790 | if cert_id not in certs.keys(): |
---|
| 791 | student['Error'] = "No Certificate %s" % cert_id |
---|
| 792 | no_import.append( format_error % student) |
---|
| 793 | continue |
---|
| 794 | try: |
---|
| 795 | table.addRecord(**student) |
---|
| 796 | except ValueError: |
---|
[1252] | 797 | student['Error'] = "Duplicate" |
---|
[1146] | 798 | no_import.append( format_error % student) |
---|
| 799 | continue |
---|
| 800 | regs.append(student.get('matric_no')) |
---|
| 801 | imported.append(format % student) |
---|
| 802 | tr_count += 1 |
---|
| 803 | if tr_count > 1000: |
---|
| 804 | if len(no_import) > 0: |
---|
| 805 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
[1151] | 806 | '\n'.join(no_import) + '\n') |
---|
[1146] | 807 | no_import = [] |
---|
| 808 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
[1151] | 809 | '\n'.join(no_import) + "\n") |
---|
| 810 | imported = [] |
---|
[1146] | 811 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
| 812 | transaction.commit() |
---|
[1168] | 813 | regs = [] |
---|
[1146] | 814 | logger.info(em) |
---|
| 815 | total += tr_count |
---|
| 816 | tr_count = 0 |
---|
| 817 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
[1252] | 818 | '\n'.join(imported)) |
---|
[1146] | 819 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 820 | '\n'.join(no_import)) |
---|
| 821 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 822 | ###) |
---|
| 823 | |
---|
[1529] | 824 | security.declareProtected(ModifyPortalContent,"fixVerdicts")###( |
---|
| 825 | def fixVerdicts(self,csv_file=None): |
---|
| 826 | """fix wrong uploaded verdicts""" |
---|
| 827 | import transaction |
---|
| 828 | import random |
---|
| 829 | wftool = self.portal_workflow |
---|
| 830 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 831 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 832 | tr_count = 1 |
---|
| 833 | total = 0 |
---|
| 834 | if csv_file is None: |
---|
| 835 | name = 'Verdicts' |
---|
| 836 | else: |
---|
| 837 | name = csv_file |
---|
| 838 | st_cat = self.students_catalog |
---|
| 839 | no_import = [] |
---|
| 840 | verdicts_voc = self.portal_vocabularies.verdicts |
---|
| 841 | rverdicts = {} |
---|
| 842 | for k,v in verdicts_voc.items(): |
---|
| 843 | rverdicts[v.upper()] = k |
---|
[1571] | 844 | rverdicts['STUDENT ON PROBATION'] = 'C' |
---|
| 845 | logger = logging.getLogger('Students.StudentsFolder.fixVerdicts') |
---|
[1529] | 846 | try: |
---|
| 847 | verdicts = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 848 | except: |
---|
| 849 | logger.error('Error reading %s.csv' % name) |
---|
| 850 | return |
---|
| 851 | start = True |
---|
| 852 | #import pdb;pdb.set_trace() |
---|
| 853 | for verdict in verdicts: |
---|
| 854 | if start: |
---|
| 855 | start = False |
---|
[1571] | 856 | logger.info('Start loading from %s.csv' % name) |
---|
[1529] | 857 | s = ','.join(['"%s"' % fn for fn in verdict.keys()]) |
---|
| 858 | no_import.append('%s,"Error"' % s) |
---|
| 859 | format = ','.join(['"%%(%s)s"' % fn for fn in verdict.keys()]) |
---|
| 860 | format_error = format + ',"%(Error)s"' |
---|
| 861 | matric_no = verdict.get('MAT NO') |
---|
| 862 | if not matric_no: |
---|
| 863 | continue |
---|
| 864 | matric_no = matric_no.upper() |
---|
| 865 | if matric_no == '': |
---|
| 866 | continue |
---|
| 867 | verdict_code = rverdicts.get(verdict.get('CATEGORY'),None) |
---|
| 868 | if verdict_code is None: |
---|
| 869 | continue |
---|
| 870 | sres = st_cat(matric_no = matric_no) |
---|
| 871 | if sres: |
---|
| 872 | student_id = sres[0].id |
---|
| 873 | student_obj = getattr(students_folder,student_id,None) |
---|
| 874 | if student_obj: |
---|
| 875 | study_course = getattr(student_obj,'study_course',None) |
---|
| 876 | if study_course is None: |
---|
| 877 | verdict['Error'] = "Student did not yet log in" |
---|
| 878 | no_import.append( format_error % verdict) |
---|
| 879 | continue |
---|
[1571] | 880 | st_cat.modifyRecord(id = student_id, |
---|
[1529] | 881 | verdict=verdict_code) |
---|
[1571] | 882 | |
---|
[1529] | 883 | dsc = {} |
---|
| 884 | dsc['current_verdict'] = verdict_code |
---|
| 885 | study_course.getContent().edit(mapping=dsc) |
---|
[1571] | 886 | else: |
---|
[1577] | 887 | verdict['Error'] = "Not found in students_catalog" |
---|
| 888 | no_import.append( format_error % verdict) |
---|
[1571] | 889 | continue |
---|
[1529] | 890 | tr_count += 1 |
---|
| 891 | if tr_count > 1000: |
---|
| 892 | if len(no_import) > 0: |
---|
| 893 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 894 | '\n'.join(no_import) + '\n') |
---|
| 895 | no_import = [] |
---|
| 896 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
| 897 | transaction.commit() |
---|
| 898 | regs = [] |
---|
| 899 | logger.info(em) |
---|
| 900 | total += tr_count |
---|
| 901 | tr_count = 0 |
---|
| 902 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 903 | '\n'.join(no_import)) |
---|
| 904 | total += tr_count |
---|
| 905 | em = '%d total transactions commited' % (total) |
---|
| 906 | logger.info(em) |
---|
| 907 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 908 | ###) |
---|
| 909 | |
---|
[1599] | 910 | security.declareProtected(ModifyPortalContent,"fixAllNames")###( |
---|
[1601] | 911 | def fixAllNames(self): |
---|
[1599] | 912 | "fix all students names" |
---|
| 913 | import transaction |
---|
| 914 | response = self.REQUEST.RESPONSE |
---|
| 915 | logger = logging.getLogger('fixAllNames') |
---|
| 916 | logger.info('Start') |
---|
| 917 | students = self.portal_catalog(portal_type='Student') |
---|
| 918 | count = 0 |
---|
| 919 | total = 0 |
---|
| 920 | for student in students: |
---|
| 921 | scat_res = self.students_catalog(id = student.getId) |
---|
| 922 | if not scat_res: |
---|
| 923 | self.students_catalog.addRecord(id = student.getId) |
---|
| 924 | scat_res = self.students_catalog(id = student.getId) |
---|
| 925 | student_entry = scat_res[0] |
---|
| 926 | old_new = self.fixName(student,student_entry) |
---|
| 927 | count += 1 |
---|
[1602] | 928 | response_write(response,'"%d","%s",%s' % (count + total,student_entry.id,old_new)) |
---|
[1599] | 929 | if count > 2000: |
---|
| 930 | transaction.commit() |
---|
| 931 | logger.info("%d transactions commited" % count) |
---|
| 932 | total += count |
---|
| 933 | count = 0 |
---|
| 934 | ###) |
---|
| 935 | |
---|
| 936 | security.declareProtected(ModifyPortalContent,"fixName")###( |
---|
[1601] | 937 | def fixName(self,student_brain, student_entry): |
---|
[1599] | 938 | "fix the name of a student" |
---|
| 939 | fix = "first" |
---|
| 940 | if student_entry.get('name_fixed',None) == fix: |
---|
| 941 | return "Name already fixed" |
---|
| 942 | student_id = student_entry.id |
---|
[1601] | 943 | new_student = student_entry.jamb_reg_no.startswith('6') |
---|
[1599] | 944 | student_obj = student_brain.getObject() |
---|
| 945 | personal = getattr(student_obj,'personal',None) |
---|
| 946 | invalid = '' |
---|
| 947 | if personal is None: |
---|
[1601] | 948 | return '"%s","Returning","%s","%s"' % (invalid,student_entry.name,"not logged in") |
---|
[1599] | 949 | per_doc = personal.getContent() |
---|
| 950 | old_first = per_doc.firstname |
---|
| 951 | old_middle = per_doc.middlename |
---|
| 952 | old_last = per_doc.lastname |
---|
| 953 | new_first = '' |
---|
| 954 | new_middle = '' |
---|
| 955 | new_last = '' |
---|
| 956 | if new_student: |
---|
| 957 | if not old_first and not old_middle and old_last: |
---|
| 958 | new_names = [n.capitalize() for n in old_last.split()] |
---|
[1611] | 959 | if len(new_names) > 1: |
---|
[1599] | 960 | old_first = new_names[0] |
---|
[1611] | 961 | old_last = new_names[-1] |
---|
| 962 | old_middle = ' '.join(new_names[1:-1]) |
---|
| 963 | else: |
---|
[1599] | 964 | old_last = new_names[0] |
---|
| 965 | old_first = '' |
---|
| 966 | old_middle = '' |
---|
[1611] | 967 | if old_first: |
---|
| 968 | new_first = old_first |
---|
[1599] | 969 | if old_middle: |
---|
| 970 | new_middle = old_middle |
---|
[1611] | 971 | if old_last: |
---|
| 972 | new_last = old_last |
---|
[1599] | 973 | if old_first.find('<') != -1 or\ |
---|
| 974 | old_first.find('>') != -1 or\ |
---|
| 975 | old_middle.find('<') != -1 or\ |
---|
| 976 | old_middle.find('>') != -1 or\ |
---|
| 977 | old_last.find('<') != -1 or\ |
---|
| 978 | old_last.find('>') != -1: |
---|
| 979 | invalid = "invalid characters" |
---|
| 980 | else: |
---|
[1611] | 981 | new_first = old_first |
---|
| 982 | if new_first.strip() == '-': |
---|
[1599] | 983 | new_first = '' |
---|
[1611] | 984 | new_middle = old_middle |
---|
| 985 | if new_middle.strip() == '-': |
---|
[1599] | 986 | new_middle = '' |
---|
[1611] | 987 | new_last = old_last |
---|
| 988 | if new_last.strip() == '-': |
---|
[1599] | 989 | new_last = '' |
---|
[1611] | 990 | name = "%(new_first)s %(new_middle)s %(new_last)s" % vars() |
---|
[1599] | 991 | if new_student: |
---|
| 992 | text = "New" |
---|
| 993 | else: |
---|
| 994 | text = "Returning" |
---|
[1601] | 995 | old_new = '"%s","%s","%s","%s"' % (invalid,text, |
---|
[1599] | 996 | student_entry.name, |
---|
| 997 | name) |
---|
| 998 | if not invalid: |
---|
| 999 | self.students_catalog.modifyRecord(id = student_id, |
---|
| 1000 | name_fixed = fix, |
---|
| 1001 | name = name) |
---|
| 1002 | per_doc.edit(mapping = {'firstname' : new_first, |
---|
| 1003 | 'middlename' : new_middle, |
---|
| 1004 | 'lastname' : new_last, |
---|
| 1005 | }) |
---|
| 1006 | return old_new |
---|
| 1007 | ###) |
---|
| 1008 | |
---|
[1319] | 1009 | security.declareProtected(ModifyPortalContent,"fixAllEntryModeForReturning")###( |
---|
| 1010 | def fixAllEntryModeForReturning(self): |
---|
| 1011 | "read all Returning*.csv" |
---|
| 1012 | ipath = "%s/import/" % i_home |
---|
| 1013 | names = os.listdir(ipath) |
---|
| 1014 | for name in names: |
---|
| 1015 | head,tail = os.path.splitext(name) |
---|
| 1016 | if head.startswith('Returning')\ |
---|
| 1017 | and tail == '.csv'\ |
---|
| 1018 | and name.find('imported') < 0: |
---|
| 1019 | self.fixEntryModeForReturning(csv_file=head) |
---|
[1322] | 1020 | ###) |
---|
[1386] | 1021 | |
---|
[1319] | 1022 | security.declareProtected(ModifyPortalContent,"fixEntryModeForReturning")###( |
---|
| 1023 | def fixEntryModeForReturning(self,csv_file=None): |
---|
| 1024 | """load Returning Studentdata from CSV values""" |
---|
| 1025 | import transaction |
---|
| 1026 | import random |
---|
| 1027 | wftool = self.portal_workflow |
---|
| 1028 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 1029 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1030 | tr_count = 1 |
---|
| 1031 | total = 0 |
---|
| 1032 | if csv_file is None: |
---|
| 1033 | name = 'Returning' |
---|
| 1034 | else: |
---|
| 1035 | name = csv_file |
---|
| 1036 | table = self.returning_import |
---|
| 1037 | st_cat = self.students_catalog |
---|
| 1038 | no_import = [] |
---|
[1571] | 1039 | logger = logging.getLogger('Students.StudentsFolder.fixEntryModeForReturning') |
---|
[1319] | 1040 | try: |
---|
| 1041 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 1042 | except: |
---|
| 1043 | logger.error('Error reading %s.csv' % name) |
---|
| 1044 | return |
---|
| 1045 | start = True |
---|
| 1046 | for student in returning: |
---|
| 1047 | if start: |
---|
| 1048 | start = False |
---|
[1571] | 1049 | logger.info('Start loading from %s.csv' % name) |
---|
[1321] | 1050 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
---|
[1319] | 1051 | no_import.append('%s,"Error"' % s) |
---|
| 1052 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
---|
| 1053 | format_error = format + ',"%(Error)s"' |
---|
| 1054 | matric_no = student.get('matric_no') |
---|
| 1055 | if not matric_no: |
---|
| 1056 | continue |
---|
| 1057 | matric_no = matric_no.upper() |
---|
| 1058 | student['matric_no'] = matric_no |
---|
| 1059 | if matric_no == '': |
---|
| 1060 | continue |
---|
| 1061 | if not table(matric_no = matric_no): |
---|
| 1062 | student['Error'] = "Not imported yet" |
---|
| 1063 | no_import.append( format_error % student) |
---|
| 1064 | continue |
---|
| 1065 | student_id = None |
---|
| 1066 | app = None |
---|
| 1067 | per = None |
---|
| 1068 | if st_cat(matric_no = matric_no): |
---|
| 1069 | student_id = st_cat(matric_no = matric_no)[0].id |
---|
[1322] | 1070 | student_obj = getattr(students_folder,student_id,None) |
---|
| 1071 | if student_obj: |
---|
| 1072 | app = getattr(student_obj,'application',None) |
---|
| 1073 | if app is not None: |
---|
| 1074 | app_doc = app.getContent() |
---|
| 1075 | per = getattr(student_obj,'personal',None) |
---|
| 1076 | if per is not None: |
---|
| 1077 | per_doc = per.getContent() |
---|
[1319] | 1078 | student['Mode_of_Entry'] = entry_mode = student.get('Mode of Entry').upper() |
---|
| 1079 | student['Permanent_Address'] = perm_address = student.get('Permanent Address') |
---|
[1322] | 1080 | #import pdb;pdb.set_trace() |
---|
[1319] | 1081 | if not entry_mode: |
---|
| 1082 | student['Error'] = "'Mode of Entry' empty" |
---|
| 1083 | no_import.append( format_error % student) |
---|
| 1084 | continue |
---|
| 1085 | try: |
---|
| 1086 | table.modifyRecord(matric_no = matric_no, |
---|
| 1087 | Mode_of_Entry = entry_mode, |
---|
| 1088 | Permanent_Address = perm_address) |
---|
| 1089 | except KeyError: |
---|
| 1090 | student['Error'] = "Not found in returning_import" |
---|
| 1091 | no_import.append( format_error % student) |
---|
| 1092 | continue |
---|
| 1093 | if student_id is not None: |
---|
| 1094 | try: |
---|
| 1095 | st_cat.modifyRecord(id = student_id, |
---|
| 1096 | entry_mode=entry_mode) |
---|
| 1097 | except KeyError: |
---|
| 1098 | student['Error'] = "Not found in students_catalog" |
---|
| 1099 | no_import.append( format_error % student) |
---|
| 1100 | continue |
---|
| 1101 | if app is not None: |
---|
| 1102 | da = {} |
---|
| 1103 | da['entry_mode'] = entry_mode |
---|
| 1104 | app_doc.edit(mapping=da) |
---|
| 1105 | if per is not None: |
---|
| 1106 | dp = {} |
---|
[1350] | 1107 | dp['perm_address'] = perm_address |
---|
[1319] | 1108 | per_doc.edit(mapping=dp) |
---|
| 1109 | tr_count += 1 |
---|
| 1110 | if tr_count > 1000: |
---|
| 1111 | if len(no_import) > 0: |
---|
| 1112 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1113 | '\n'.join(no_import) + '\n') |
---|
| 1114 | no_import = [] |
---|
| 1115 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
| 1116 | transaction.commit() |
---|
| 1117 | regs = [] |
---|
| 1118 | logger.info(em) |
---|
| 1119 | total += tr_count |
---|
| 1120 | tr_count = 0 |
---|
| 1121 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1122 | '\n'.join(no_import)) |
---|
| 1123 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 1124 | ###) |
---|
[1289] | 1125 | |
---|
| 1126 | security.declareProtected(ModifyPortalContent,"updateReturningStudents")###( |
---|
| 1127 | def updateReturningStudents(self): |
---|
| 1128 | """load and overwrite Returning Student Data from CSV values""" |
---|
| 1129 | import transaction |
---|
| 1130 | import random |
---|
| 1131 | #from pdb import set_trace |
---|
| 1132 | wftool = self.portal_workflow |
---|
| 1133 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 1134 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 1135 | tr_count = 1 |
---|
| 1136 | total = 0 |
---|
| 1137 | #name = 'pume_results' |
---|
| 1138 | name = 'Returning_update' |
---|
| 1139 | table = self.returning_import |
---|
| 1140 | no_import = [] |
---|
| 1141 | imported = [] |
---|
[1571] | 1142 | logger = logging.getLogger('Students.StudentsFolder.updateReturningStudents') |
---|
[1289] | 1143 | try: |
---|
| 1144 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 1145 | except: |
---|
| 1146 | logger.error('Error reading %s.csv' % name) |
---|
| 1147 | return |
---|
| 1148 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 1149 | certs = {} |
---|
| 1150 | cert_docs = {} |
---|
| 1151 | for f in l: |
---|
| 1152 | certs[f.getId] = f.getObject().getContent() |
---|
| 1153 | start = True |
---|
| 1154 | res = table() |
---|
| 1155 | regs = [] |
---|
| 1156 | if len(res) > 0: |
---|
| 1157 | regs = [s.matric_no for s in res] |
---|
| 1158 | for student in returning: |
---|
| 1159 | if start: |
---|
| 1160 | start = False |
---|
[1571] | 1161 | logger.info('Start loading from %s.csv' % name) |
---|
[1321] | 1162 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
---|
[1289] | 1163 | imported.append(s) |
---|
| 1164 | no_import.append('%s,"Error"' % s) |
---|
| 1165 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
---|
| 1166 | format_error = format + ',"%(Error)s"' |
---|
| 1167 | no_certificate = "no certificate %s" % format |
---|
| 1168 | matric_no = student.get('matric_no').upper() |
---|
| 1169 | student['matric_no'] = matric_no |
---|
| 1170 | if matric_no == '': |
---|
| 1171 | student['Error'] = "Empty matric_no" |
---|
| 1172 | no_import.append( format_error % student) |
---|
| 1173 | continue |
---|
| 1174 | # if matric_no in regs or self.returning_import(matric_no = matric_no): |
---|
| 1175 | # student['Error'] = "Duplicate" |
---|
| 1176 | # no_import.append( format_error % student) |
---|
| 1177 | # continue |
---|
| 1178 | # cert_id = makeCertificateCode(student.get('Coursemajorcode')) |
---|
| 1179 | # if cert_id not in certs.keys(): |
---|
| 1180 | # student['Error'] = "No Certificate %s" % cert_id |
---|
| 1181 | # no_import.append( format_error % student) |
---|
| 1182 | # continue |
---|
| 1183 | try: |
---|
| 1184 | table.modifyRecord(**student) |
---|
| 1185 | except KeyError: |
---|
| 1186 | #import pdb;pdb.set_trace() |
---|
| 1187 | student['Error'] = "no Student found to update" |
---|
| 1188 | no_import.append( format_error % student) |
---|
| 1189 | continue |
---|
[1386] | 1190 | #s = self.students_catalog(matric_no=matric_no) |
---|
| 1191 | #if s: |
---|
| 1192 | # level = "%s" % (int(student.get('Level')) + 100) |
---|
| 1193 | # self.students_catalog.modifyRecord(id = s[0].id, |
---|
| 1194 | # level=level) |
---|
[1289] | 1195 | |
---|
| 1196 | regs.append(student.get('matric_no')) |
---|
| 1197 | imported.append(format % student) |
---|
| 1198 | tr_count += 1 |
---|
| 1199 | if tr_count > 1000: |
---|
| 1200 | if len(no_import) > 0: |
---|
| 1201 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1202 | '\n'.join(no_import) + '\n') |
---|
| 1203 | no_import = [] |
---|
| 1204 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1205 | '\n'.join(no_import) + "\n") |
---|
| 1206 | imported = [] |
---|
| 1207 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
| 1208 | transaction.commit() |
---|
| 1209 | regs = [] |
---|
| 1210 | logger.info(em) |
---|
| 1211 | total += tr_count |
---|
| 1212 | tr_count = 0 |
---|
| 1213 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1214 | '\n'.join(imported)) |
---|
| 1215 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1216 | '\n'.join(no_import)) |
---|
| 1217 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 1218 | ###) |
---|
| 1219 | |
---|
[1146] | 1220 | security.declareProtected(ModifyPortalContent,"importResults")###( |
---|
| 1221 | def importResults(self): |
---|
[1151] | 1222 | """load Returning Students Results from CSV""" |
---|
[1146] | 1223 | import transaction |
---|
| 1224 | import random |
---|
| 1225 | #from pdb import set_trace |
---|
| 1226 | wftool = self.portal_workflow |
---|
| 1227 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 1228 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 1229 | tr_count = 1 |
---|
| 1230 | total = 0 |
---|
| 1231 | #name = 'pume_results' |
---|
| 1232 | name = 'Results' |
---|
| 1233 | table = self.results_import |
---|
| 1234 | no_import = [] |
---|
| 1235 | imported = [] |
---|
[1571] | 1236 | logger = logging.getLogger('Students.StudentsFolder.importResults') |
---|
[1146] | 1237 | try: |
---|
| 1238 | results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 1239 | except: |
---|
| 1240 | logger.error('Error reading %s.csv' % name) |
---|
| 1241 | return |
---|
| 1242 | l = self.portal_catalog({'meta_type': "Course"}) |
---|
| 1243 | courses = [f.getId for f in l] |
---|
| 1244 | start = True |
---|
| 1245 | res = table() |
---|
| 1246 | regs = [] |
---|
| 1247 | if len(res) > 0: |
---|
| 1248 | regs = [s.key for s in res] |
---|
| 1249 | no_course = [] |
---|
| 1250 | no_course_list = [] |
---|
| 1251 | course_count = 0 |
---|
| 1252 | for result in results: |
---|
| 1253 | if start: |
---|
| 1254 | start = False |
---|
[1571] | 1255 | logger.info('Start loading from %s.csv' % name) |
---|
[1321] | 1256 | s = ','.join(['"%s"' % fn for fn in result.keys()]) |
---|
[1146] | 1257 | imported.append(s) |
---|
| 1258 | no_import.append('%s,"Error"' % s) |
---|
| 1259 | format = ','.join(['"%%(%s)s"' % fn for fn in result.keys()]) |
---|
| 1260 | format_error = format + ',"%(Error)s"' |
---|
| 1261 | no_certificate = "no certificate %s" % format |
---|
| 1262 | course_id = result.get('CosCode') |
---|
[1448] | 1263 | if not course_id: |
---|
| 1264 | course_id = 'N/A' |
---|
| 1265 | result['CosCode'] = course_id |
---|
[1168] | 1266 | matric_no = result.get('matric_no').upper() |
---|
| 1267 | result['matric_no'] = matric_no |
---|
| 1268 | key = matric_no+course_id |
---|
| 1269 | if matric_no == '': |
---|
[1252] | 1270 | result['Error'] = "Empty matric_no" |
---|
[1146] | 1271 | no_import.append( format_error % result) |
---|
| 1272 | continue |
---|
[1168] | 1273 | if key in regs or self.results_import(key = key): |
---|
[1252] | 1274 | result['Error'] = "Duplicate" |
---|
[1146] | 1275 | no_import.append( format_error % result) |
---|
| 1276 | continue |
---|
| 1277 | if course_id not in courses: |
---|
| 1278 | if course_id not in no_course: |
---|
| 1279 | course_count +=1 |
---|
| 1280 | no_course.append(course_id) |
---|
| 1281 | no_course_list.append('"%s"' % course_id) |
---|
| 1282 | #result['Error'] = "No Course" |
---|
| 1283 | #logger.info(format_error % result) |
---|
| 1284 | regs.append(key) |
---|
| 1285 | imported.append(format % result) |
---|
| 1286 | tr_count += 1 |
---|
| 1287 | if tr_count > 1000: |
---|
| 1288 | if len(no_import) > 0: |
---|
| 1289 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
[1151] | 1290 | '\n'.join(no_import)+'\n') |
---|
[1146] | 1291 | no_import = [] |
---|
| 1292 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
[1151] | 1293 | '\n'.join(imported) + '\n') |
---|
[1146] | 1294 | imported = [] |
---|
| 1295 | if no_course_list: |
---|
| 1296 | open("%s/import/%sno_courses%s.csv" % (i_home,name,current),"a").write( |
---|
[1151] | 1297 | '\n'.join(no_course_list) + '\n') |
---|
[1146] | 1298 | no_course_list = [] |
---|
| 1299 | em = '%d transactions commited total %s\n courses not found %s' % (tr_count,total,course_count) |
---|
| 1300 | transaction.commit() |
---|
| 1301 | logger.info(em) |
---|
[1168] | 1302 | regs = [] |
---|
[1146] | 1303 | total += tr_count |
---|
| 1304 | tr_count = 0 |
---|
| 1305 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1306 | '\n'.join(imported)) |
---|
| 1307 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1308 | '\n'.join(no_import)) |
---|
| 1309 | if no_course_list: |
---|
| 1310 | open("%s/import/%sno_courses%s.csv" % (i_home,name,current),"a").write( |
---|
| 1311 | '\n'.join(no_course_list)) |
---|
[1393] | 1312 | em = '%d transactions commited total %s\n courses not found %s' % (tr_count,total,course_count) |
---|
| 1313 | logger.info(em) |
---|
[1146] | 1314 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 1315 | ###) |
---|
| 1316 | |
---|
[1700] | 1317 | security.declareProtected(ModifyPortalContent,"importPreviousSessionStudents")###( |
---|
| 1318 | def importPreviousSessionStudents(self): |
---|
| 1319 | """load and create previous session students from CSV""" |
---|
| 1320 | import transaction |
---|
| 1321 | import random |
---|
| 1322 | wftool = self.portal_workflow |
---|
| 1323 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 1324 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1325 | tr_count = 1 |
---|
| 1326 | total = 0 |
---|
| 1327 | #name = 'pume_results' |
---|
| 1328 | name = 'Previous' |
---|
| 1329 | keys = self.portal_schemas.import_student.keys() |
---|
| 1330 | keys += self.portal_schemas.import_student_level_data.keys() |
---|
| 1331 | not_imported = [] |
---|
| 1332 | imported = [] |
---|
| 1333 | certificates = {} |
---|
| 1334 | logger = logging.getLogger('Students.StudentsFolder.importPreviousSessionStudents') |
---|
| 1335 | try: |
---|
| 1336 | records = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 1337 | except: |
---|
| 1338 | logger.error('Error reading %s.csv' % name) |
---|
| 1339 | return |
---|
| 1340 | start = True |
---|
| 1341 | for record in records: |
---|
| 1342 | if start: |
---|
| 1343 | start = False |
---|
| 1344 | logger.info('Start loading from %s.csv' % name) |
---|
| 1345 | false_keys = [k for k in record.keys() if k not in keys] |
---|
| 1346 | right_keys = [k for k in record.keys() if k in keys] |
---|
| 1347 | if false_keys: |
---|
| 1348 | logger.info('Fields %s not in schema' % false_keys) |
---|
| 1349 | s = ','.join(['"%s"' % k for k in right_keys]) |
---|
| 1350 | imported.append(s) |
---|
| 1351 | not_imported.append('%s,"error"' % s) |
---|
| 1352 | format = ','.join(['"%%(%s)s"' % k for k in right_keys]) |
---|
| 1353 | format_error = format + ',"%(error)s"' |
---|
[1728] | 1354 | study_course = makeCertificateCode(record.get('study_course')) |
---|
[1700] | 1355 | matric_no = record.get('matric_no') |
---|
| 1356 | student_res = self.students_catalog(matric_no = matric_no) |
---|
| 1357 | if student_res: |
---|
| 1358 | record['error'] = "Student exists" |
---|
| 1359 | not_imported.append(format_error % record) |
---|
| 1360 | continue |
---|
| 1361 | if study_course not in certificates.keys(): |
---|
| 1362 | cert_res = self.portal_catalog(portal_type='Certificate', |
---|
| 1363 | id = study_course) |
---|
| 1364 | if not cert_res: |
---|
| 1365 | record['error'] = "No such studycourse" |
---|
| 1366 | not_imported.append(format_error % record) |
---|
| 1367 | continue |
---|
| 1368 | certificates[cert_res[0].id] = cert_res[0] |
---|
| 1369 | sid = self.generateStudentId('x',students_folder) |
---|
| 1370 | students_folder.invokeFactory('Student', sid) |
---|
| 1371 | #from pdb import set_trace;set_trace() |
---|
| 1372 | record['student_id'] = sid |
---|
| 1373 | student = getattr(self,sid) |
---|
| 1374 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1375 | student.invokeFactory('StudentApplication','application') |
---|
| 1376 | app = student.application |
---|
| 1377 | app_doc = app.getContent() |
---|
| 1378 | dict = {'Title': 'Application Data'} |
---|
| 1379 | dict["jamb_lastname"] = "%(firstname)s %(lastname)s %(middlename)s" % record |
---|
| 1380 | r2d = [ |
---|
| 1381 | ('entry_mode','entry_mode'), |
---|
| 1382 | ('sex','jamb_sex'), |
---|
| 1383 | ('jamb_score','jamb_score'), |
---|
| 1384 | ('jamb_reg_no','jamb_reg_no'), |
---|
| 1385 | ] |
---|
| 1386 | for r,d in r2d: |
---|
| 1387 | dict[d] = record[r] |
---|
| 1388 | app_doc.edit(mapping=dict) |
---|
| 1389 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1390 | wftool.doActionFor(app,'close') |
---|
| 1391 | record['sex'] = record['sex'] == 'F' |
---|
| 1392 | student.invokeFactory('StudentPersonal','personal') |
---|
| 1393 | dict = {} |
---|
| 1394 | r2d = [('firstname','firstname'), |
---|
| 1395 | ('middlename','middlename'), |
---|
| 1396 | ('lastname','lastname'), |
---|
| 1397 | ('sex','sex'), |
---|
| 1398 | ('email','email'), |
---|
| 1399 | ('phone','phone'), |
---|
[1710] | 1400 | ('address','perm_address'), |
---|
[1700] | 1401 | ] |
---|
| 1402 | for r,d in r2d: |
---|
| 1403 | dict[d] = record[r] |
---|
| 1404 | per = student.personal |
---|
| 1405 | per_doc = per.getContent() |
---|
| 1406 | per_doc.edit(mapping = dict) |
---|
| 1407 | per.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1408 | # |
---|
| 1409 | # Clearance |
---|
| 1410 | # |
---|
| 1411 | student.invokeFactory('StudentClearance','clearance') |
---|
| 1412 | #wftool.doActionFor(student.clearance,'open') |
---|
| 1413 | clearance = getattr(student,'clearance') |
---|
| 1414 | dict = {'Title': 'Clearance/Eligibility Record'} |
---|
| 1415 | clearance.getContent().edit(mapping = dict) |
---|
| 1416 | student.clearance.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1417 | # |
---|
| 1418 | # Study Course |
---|
| 1419 | # |
---|
| 1420 | student.invokeFactory('StudentStudyCourse','study_course') |
---|
| 1421 | study_course = student.study_course |
---|
| 1422 | dict = {} |
---|
| 1423 | r2d = [('session','current_session'), |
---|
[1710] | 1424 | ('level','current_level'), |
---|
| 1425 | ('verdict','current_verdict'), |
---|
[1700] | 1426 | ('study_course','study_course'), |
---|
| 1427 | ] |
---|
| 1428 | for r,d in r2d: |
---|
| 1429 | dict[d] = record[r] |
---|
| 1430 | study_course.getContent().edit(mapping=dict) |
---|
| 1431 | # |
---|
| 1432 | # Study Level |
---|
| 1433 | # |
---|
| 1434 | level = record['level'] |
---|
| 1435 | study_course.invokeFactory('StudentStudyLevel',level) |
---|
| 1436 | study_level = getattr(study_course,level) |
---|
| 1437 | dict = {} |
---|
| 1438 | r2d = [('session','session'), |
---|
[1710] | 1439 | ('level','code'), |
---|
| 1440 | ('verdict','verdict'), |
---|
[1700] | 1441 | ] |
---|
| 1442 | for r,d in r2d: |
---|
| 1443 | dict[d] = record[r] |
---|
| 1444 | study_level.getContent().edit(mapping=dict) |
---|
| 1445 | wftool.doActionFor(student,'return') |
---|
| 1446 | imported.append(format % record) |
---|
| 1447 | tr_count += 1 |
---|
| 1448 | record['tr_count'] = tr_count |
---|
| 1449 | record['total'] = total |
---|
| 1450 | logger.info('%(total)s+%(tr_count)s: Creating Student %(student_id)s %(matric_no)s %(jamb_reg_no)s' % record) |
---|
| 1451 | if tr_count > 1000: |
---|
| 1452 | if len(not_imported) > 0: |
---|
| 1453 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1454 | '\n'.join(not_imported)+'\n') |
---|
| 1455 | not_imported = [] |
---|
| 1456 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1457 | '\n'.join(imported) + '\n') |
---|
| 1458 | imported = [] |
---|
| 1459 | em = '%d transactions commited total %s' % (tr_count,total) |
---|
| 1460 | transaction.commit() |
---|
| 1461 | logger.info(em) |
---|
| 1462 | regs = [] |
---|
| 1463 | total += tr_count |
---|
| 1464 | tr_count = 0 |
---|
| 1465 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1466 | '\n'.join(imported)) |
---|
| 1467 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1468 | '\n'.join(not_imported)) |
---|
| 1469 | em = '%d transactions commited total %d' % (tr_count,total) |
---|
| 1470 | logger.info(em) |
---|
| 1471 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 1472 | ###) |
---|
| 1473 | |
---|
[1065] | 1474 | security.declareProtected(ModifyPortalContent,"updateStudyCourse")###( |
---|
| 1475 | def updateStudyCourse(self): |
---|
| 1476 | """update StudyCourse from CSV values""" |
---|
| 1477 | import transaction |
---|
| 1478 | import random |
---|
| 1479 | from pdb import set_trace |
---|
| 1480 | wftool = self.portal_workflow |
---|
| 1481 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 1482 | csv_d = {'jamb_reg_no': "RegNumber", |
---|
| 1483 | 'jamb_lastname': "Name", |
---|
| 1484 | 'session': "Session", |
---|
| 1485 | 'pume_tot_score': "PUME SCORE", |
---|
| 1486 | 'jamb_score': "JambScore", |
---|
| 1487 | 'jamb_sex': "Sex", |
---|
| 1488 | 'jamb_state': "State", |
---|
| 1489 | ## 'jamb_first_cos': "AdminCourse", |
---|
| 1490 | 'faculty': "AdminFaculty", |
---|
| 1491 | 'course_code': "AdmitCoscode", |
---|
| 1492 | 'stud_status':"AdmitStatus", |
---|
| 1493 | 'department': "AdmitDept", |
---|
| 1494 | 'jamb_lga': "LGA", |
---|
| 1495 | 'app_email': "email", |
---|
| 1496 | 'app_mobile': "PhoneNumbers", |
---|
| 1497 | } |
---|
| 1498 | csv_fields = [f[1] for f in csv_d.items()] |
---|
| 1499 | tr_count = 0 |
---|
| 1500 | total = 0 |
---|
| 1501 | #name = 'pume_results' |
---|
| 1502 | name = 'StudyCourseChange' |
---|
| 1503 | no_import = [] |
---|
[1321] | 1504 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
---|
[1065] | 1505 | no_import.append('"Error",%s' % s) |
---|
| 1506 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
---|
| 1507 | no_certificate = "no certificate %s" % format |
---|
| 1508 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( |
---|
| 1509 | '\n'.join(no_import)) |
---|
[1571] | 1510 | logger = logging.getLogger('Students.StudentsFolder.updateStudyCourse') |
---|
[1065] | 1511 | logger.info('Start loading from %s.csv' % name) |
---|
| 1512 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 1513 | try: |
---|
| 1514 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 1515 | except: |
---|
| 1516 | logger.error('Error reading %s.csv' % name) |
---|
| 1517 | return |
---|
| 1518 | for jamb in result: |
---|
| 1519 | jamb['Error'] = "Processing " |
---|
| 1520 | logger.info(format % jamb) |
---|
| 1521 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) |
---|
| 1522 | res = self.portal_catalog({'portal_type': "StudentApplication", |
---|
| 1523 | 'SearchableText': jamb_reg_no }) |
---|
| 1524 | if not res: |
---|
[1571] | 1525 | em = 'Student with jamb_reg_no %s does not exists\n' % jamb_reg_no |
---|
[1065] | 1526 | logger.info(em) |
---|
[1571] | 1527 | jamb['Error'] = "Student does not exist" |
---|
[1065] | 1528 | no_import.append(format % jamb) |
---|
| 1529 | continue |
---|
| 1530 | sid = res[0].getPath().split('/')[-2] |
---|
| 1531 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) |
---|
| 1532 | res = self.portal_catalog(portal_type = "Certificate", id = cert_id) |
---|
| 1533 | if not res: |
---|
| 1534 | em = 'No Certificate with ID %s \n' % cert_id |
---|
| 1535 | logger.info(em) |
---|
| 1536 | jamb['Error'] = "No Certificate %s" % cert_id |
---|
| 1537 | no_import.append( format % jamb) |
---|
| 1538 | continue |
---|
| 1539 | cert_brain = res[0] |
---|
| 1540 | catalog_entry = {} |
---|
| 1541 | student = getattr(self,sid) |
---|
| 1542 | # |
---|
| 1543 | # Study Course |
---|
| 1544 | # |
---|
| 1545 | study_course = student.study_course |
---|
| 1546 | dsc = {} |
---|
| 1547 | cert_pl = cert_brain.getPath().split('/') |
---|
| 1548 | catalog_entry['id'] = sid |
---|
| 1549 | catalog_entry['faculty'] = cert_pl[-4] |
---|
| 1550 | catalog_entry['department'] = cert_pl[-3] |
---|
| 1551 | catalog_entry['course'] = cert_id |
---|
| 1552 | dsc['study_course'] = cert_id |
---|
| 1553 | study_course.getContent().edit(mapping=dsc) |
---|
| 1554 | self.students_catalog.modifyRecord(**catalog_entry) |
---|
| 1555 | if tr_count > 10: |
---|
| 1556 | if len(no_import) > 1: |
---|
| 1557 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write( |
---|
| 1558 | '\n'.join(no_import)) |
---|
| 1559 | no_import = [] |
---|
| 1560 | em = '%d transactions commited\n' % tr_count |
---|
| 1561 | transaction.commit() |
---|
| 1562 | logger.info(em) |
---|
| 1563 | total += tr_count |
---|
| 1564 | tr_count = 0 |
---|
| 1565 | tr_count += 1 |
---|
| 1566 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 1567 | ###) |
---|
| 1568 | |
---|
[1594] | 1569 | security.declareProtected(View,"fixOwnership") ###( |
---|
[511] | 1570 | def fixOwnership(self): |
---|
| 1571 | """fix Ownership""" |
---|
| 1572 | for s in self.portal_catalog(meta_type = 'Student'): |
---|
| 1573 | student = s.getObject() |
---|
| 1574 | sid = s.getId |
---|
| 1575 | import pdb;pdb.set_trace() |
---|
| 1576 | student.application.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1577 | student.personal.manage_setLocalRoles(sid, ['Owner',]) |
---|
[1594] | 1578 | ###) |
---|
[603] | 1579 | |
---|
[1594] | 1580 | security.declareProtected(View,"Title") ###( |
---|
[364] | 1581 | def Title(self): |
---|
| 1582 | """compose title""" |
---|
[382] | 1583 | return "Student Section" |
---|
[1594] | 1584 | ###) |
---|
[361] | 1585 | |
---|
[1700] | 1586 | def generateStudentId(self,letter,students = None): ###( |
---|
[714] | 1587 | import random |
---|
| 1588 | r = random |
---|
[1700] | 1589 | if students is None: |
---|
| 1590 | students = self.portal_url.getPortalObject().campus.students |
---|
[714] | 1591 | if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'): |
---|
| 1592 | letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY') |
---|
| 1593 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
| 1594 | while hasattr(students, sid): |
---|
| 1595 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
[758] | 1596 | return sid |
---|
[714] | 1597 | #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000)) |
---|
| 1598 | ###) |
---|
| 1599 | |
---|
[361] | 1600 | InitializeClass(StudentsFolder) |
---|
| 1601 | |
---|
[1594] | 1602 | def addStudentsFolder(container, id, REQUEST=None, **kw): ###( |
---|
[361] | 1603 | """Add a Student.""" |
---|
| 1604 | ob = StudentsFolder(id, **kw) |
---|
| 1605 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[1594] | 1606 | ###) |
---|
| 1607 | |
---|
[361] | 1608 | ###) |
---|
| 1609 | |
---|
[57] | 1610 | class Student(CPSDocument): ###( |
---|
| 1611 | """ |
---|
[154] | 1612 | WAeUP Student container for the various student data |
---|
[57] | 1613 | """ |
---|
| 1614 | meta_type = 'Student' |
---|
| 1615 | portal_type = meta_type |
---|
| 1616 | security = ClassSecurityInfo() |
---|
[154] | 1617 | |
---|
[152] | 1618 | security.declareProtected(View,"Title") |
---|
| 1619 | def Title(self): |
---|
| 1620 | """compose title""" |
---|
[153] | 1621 | reg_nr = self.getId()[1:] |
---|
[362] | 1622 | data = getattr(self,'personal',None) |
---|
[152] | 1623 | if data: |
---|
| 1624 | content = data.getContent() |
---|
[1143] | 1625 | return "%s %s %s" % (content.firstname,content.middlename,content.lastname) |
---|
[472] | 1626 | data = getattr(self,'application',None) |
---|
[464] | 1627 | if data: |
---|
| 1628 | content = data.getContent() |
---|
| 1629 | return "%s" % (content.jamb_lastname) |
---|
[152] | 1630 | return self.title |
---|
[154] | 1631 | |
---|
[511] | 1632 | security.declarePrivate('makeStudentMember') ###( |
---|
| 1633 | def makeStudentMember(self,sid,password='uNsEt'): |
---|
| 1634 | """make the student a member""" |
---|
| 1635 | membership = self.portal_membership |
---|
[603] | 1636 | membership.addMember(sid, |
---|
[511] | 1637 | password , |
---|
| 1638 | roles=('Member', |
---|
| 1639 | 'Student', |
---|
[522] | 1640 | ), |
---|
[511] | 1641 | domains='', |
---|
[904] | 1642 | properties = {'memberareaCreationFlag': False, |
---|
| 1643 | 'homeless': True},) |
---|
[511] | 1644 | member = membership.getMemberById(sid) |
---|
| 1645 | self.portal_registration.afterAdd(member, sid, password, None) |
---|
| 1646 | self.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1647 | |
---|
| 1648 | ###) |
---|
| 1649 | |
---|
[764] | 1650 | security.declareProtected(View,'createSubObjects') ###( |
---|
| 1651 | def createSubObjects(self): |
---|
| 1652 | """make the student a member""" |
---|
| 1653 | dp = {'Title': 'Personal Data'} |
---|
| 1654 | app_doc = self.application.getContent() |
---|
| 1655 | names = app_doc.jamb_lastname.split() |
---|
| 1656 | if len(names) == 3: |
---|
| 1657 | dp['firstname'] = names[0].capitalize() |
---|
| 1658 | dp['middlename'] = names[1].capitalize() |
---|
| 1659 | dp['lastname'] = names[2].capitalize() |
---|
| 1660 | elif len(names) == 2: |
---|
| 1661 | dp['firstname'] = names[0].capitalize() |
---|
| 1662 | dp['lastname'] = names[1].capitalize() |
---|
| 1663 | else: |
---|
| 1664 | dp['lastname'] = app_doc.jamb_lastname |
---|
| 1665 | dp['sex'] = app_doc.jamb_sex == 'F' |
---|
| 1666 | dp['lga'] = "%s/%s" % (app_doc.jamb_state,app_doc.jamb_lga ) |
---|
| 1667 | proxy = self.aq_parent |
---|
| 1668 | proxy.invokeFactory('StudentPersonal','personal') |
---|
| 1669 | per = proxy.personal |
---|
| 1670 | per_doc = per.getContent() |
---|
| 1671 | per_doc.edit(mapping = dp) |
---|
[927] | 1672 | per.manage_setLocalRoles(proxy.getId(), ['Owner',]) |
---|
[764] | 1673 | #self.portal_workflow.doActionFor(per,'open',dest_container=per) |
---|
[603] | 1674 | |
---|
[511] | 1675 | ###) |
---|
| 1676 | |
---|
[57] | 1677 | InitializeClass(Student) |
---|
| 1678 | |
---|
| 1679 | def addStudent(container, id, REQUEST=None, **kw): |
---|
| 1680 | """Add a Student.""" |
---|
| 1681 | ob = Student(id, **kw) |
---|
| 1682 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1683 | |
---|
| 1684 | ###) |
---|
[91] | 1685 | |
---|
[639] | 1686 | class StudentAccommodation(CPSDocument): ###( |
---|
| 1687 | """ |
---|
| 1688 | WAeUP Student container for the various student data |
---|
| 1689 | """ |
---|
| 1690 | meta_type = 'StudentAccommodation' |
---|
| 1691 | portal_type = meta_type |
---|
| 1692 | security = ClassSecurityInfo() |
---|
| 1693 | |
---|
| 1694 | security.declareProtected(View,"Title") |
---|
| 1695 | def Title(self): |
---|
| 1696 | """compose title""" |
---|
| 1697 | content = self.getContent() |
---|
| 1698 | #return "Accommodation Data for %s %s" % (content.firstname,content.lastname) |
---|
| 1699 | return "Accommodation Data for Session %s" % content.session |
---|
| 1700 | |
---|
| 1701 | |
---|
| 1702 | InitializeClass(StudentAccommodation) |
---|
| 1703 | |
---|
| 1704 | def addStudentAccommodation(container, id, REQUEST=None, **kw): |
---|
| 1705 | """Add a Students personal data.""" |
---|
| 1706 | ob = StudentAccommodation(id, **kw) |
---|
| 1707 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1708 | |
---|
| 1709 | ###) |
---|
| 1710 | |
---|
[89] | 1711 | class StudentPersonal(CPSDocument): ###( |
---|
| 1712 | """ |
---|
[154] | 1713 | WAeUP Student container for the various student data |
---|
[89] | 1714 | """ |
---|
| 1715 | meta_type = 'StudentPersonal' |
---|
| 1716 | portal_type = meta_type |
---|
| 1717 | security = ClassSecurityInfo() |
---|
[152] | 1718 | |
---|
| 1719 | security.declareProtected(View,"Title") |
---|
| 1720 | def Title(self): |
---|
| 1721 | """compose title""" |
---|
| 1722 | content = self.getContent() |
---|
[364] | 1723 | #return "Personal Data for %s %s" % (content.firstname,content.lastname) |
---|
| 1724 | return "Personal Data" |
---|
[152] | 1725 | |
---|
[154] | 1726 | |
---|
[89] | 1727 | InitializeClass(StudentPersonal) |
---|
| 1728 | |
---|
| 1729 | def addStudentPersonal(container, id, REQUEST=None, **kw): |
---|
| 1730 | """Add a Students personal data.""" |
---|
| 1731 | ob = StudentPersonal(id, **kw) |
---|
| 1732 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1733 | |
---|
| 1734 | ###) |
---|
| 1735 | |
---|
[423] | 1736 | class StudentClearance(CPSDocument): ###( |
---|
| 1737 | """ |
---|
| 1738 | WAeUP Student container for the various student data |
---|
| 1739 | """ |
---|
| 1740 | meta_type = 'StudentClearance' |
---|
| 1741 | portal_type = meta_type |
---|
| 1742 | security = ClassSecurityInfo() |
---|
| 1743 | |
---|
| 1744 | security.declareProtected(View,"Title") |
---|
| 1745 | def Title(self): |
---|
| 1746 | """compose title""" |
---|
| 1747 | content = self.getContent() |
---|
[840] | 1748 | #return "Clearance/Eligibility Record for %s %s" % (content.firstname,content.lastname) |
---|
| 1749 | return "Clearance/Eligibility Record" |
---|
[423] | 1750 | |
---|
| 1751 | |
---|
| 1752 | InitializeClass(StudentClearance) |
---|
| 1753 | |
---|
| 1754 | def addStudentClearance(container, id, REQUEST=None, **kw): |
---|
| 1755 | """Add a Students personal data.""" |
---|
| 1756 | ob = StudentClearance(id, **kw) |
---|
| 1757 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1758 | |
---|
| 1759 | ###) |
---|
| 1760 | |
---|
[454] | 1761 | class StudentStudyLevel(CPSDocument): ###( |
---|
| 1762 | """ |
---|
| 1763 | WAeUP Student container for the various student data |
---|
| 1764 | """ |
---|
| 1765 | meta_type = 'StudentStudyLevel' |
---|
| 1766 | portal_type = meta_type |
---|
| 1767 | security = ClassSecurityInfo() |
---|
| 1768 | |
---|
| 1769 | security.declareProtected(View,"Title") |
---|
| 1770 | def Title(self): |
---|
| 1771 | """compose title""" |
---|
| 1772 | return "Level %s" % self.aq_parent.getId() |
---|
| 1773 | |
---|
[1700] | 1774 | def create_course_results(self,cert_id,current_level): ###( |
---|
[1649] | 1775 | "create all courses in a level" |
---|
| 1776 | aq_portal = self.portal_catalog.evalAdvancedQuery |
---|
| 1777 | res = self.portal_catalog(portal_type="Certificate", id = cert_id) |
---|
| 1778 | l = [] |
---|
| 1779 | import transaction |
---|
| 1780 | if res: |
---|
| 1781 | cert = res[0] |
---|
| 1782 | path = cert.getPath() |
---|
| 1783 | query = Eq("path","%s/%s" % (path,current_level)) &\ |
---|
| 1784 | Eq('portal_type','CertificateCourse') |
---|
| 1785 | courses = aq_portal(query) |
---|
| 1786 | #from pdb import set_trace;set_trace() |
---|
| 1787 | self_proxy = self.aq_parent |
---|
| 1788 | for c in courses: |
---|
| 1789 | d = self.getCourseInfo(c.getId) |
---|
| 1790 | cr_id = self_proxy.invokeFactory('StudentCourseResult',c.getId) |
---|
| 1791 | course_result = getattr(self_proxy,cr_id) |
---|
| 1792 | self.portal_workflow.doActionFor(course_result,'open') |
---|
| 1793 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
| 1794 | course_result.getContent().edit(mapping=d) |
---|
| 1795 | transaction.commit() |
---|
[1700] | 1796 | ###) |
---|
[472] | 1797 | |
---|
[454] | 1798 | InitializeClass(StudentStudyLevel) |
---|
| 1799 | |
---|
| 1800 | def addStudentStudyLevel(container, id, REQUEST=None, **kw): |
---|
| 1801 | """Add a Students personal data.""" |
---|
| 1802 | ob = StudentStudyLevel(id, **kw) |
---|
| 1803 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1804 | |
---|
| 1805 | ###) |
---|
| 1806 | |
---|
[362] | 1807 | class StudentStudyCourse(CPSDocument): ###( |
---|
| 1808 | """ |
---|
| 1809 | WAeUP Student container for the various student data |
---|
| 1810 | """ |
---|
| 1811 | meta_type = 'StudentStudyCourse' |
---|
| 1812 | portal_type = meta_type |
---|
| 1813 | security = ClassSecurityInfo() |
---|
| 1814 | |
---|
[364] | 1815 | security.declareProtected(View,"Title") |
---|
| 1816 | def Title(self): |
---|
| 1817 | """compose title""" |
---|
| 1818 | content = self.getContent() |
---|
[453] | 1819 | return "Study Course" |
---|
[362] | 1820 | |
---|
| 1821 | |
---|
| 1822 | InitializeClass(StudentStudyCourse) |
---|
| 1823 | |
---|
| 1824 | def addStudentStudyCourse(container, id, REQUEST=None, **kw): |
---|
| 1825 | """Add a Students personal data.""" |
---|
| 1826 | ob = StudentStudyCourse(id, **kw) |
---|
| 1827 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1828 | |
---|
| 1829 | ###) |
---|
| 1830 | |
---|
[472] | 1831 | class StudentApplication(CPSDocument): ###( |
---|
[179] | 1832 | """ |
---|
| 1833 | WAeUP Student container for the various student data |
---|
| 1834 | """ |
---|
[472] | 1835 | meta_type = 'StudentApplication' |
---|
[179] | 1836 | portal_type = meta_type |
---|
| 1837 | security = ClassSecurityInfo() |
---|
| 1838 | |
---|
[181] | 1839 | security.declareProtected(View,"Title") |
---|
| 1840 | def Title(self): |
---|
| 1841 | """compose title""" |
---|
[472] | 1842 | return "Application Data" |
---|
[179] | 1843 | |
---|
[181] | 1844 | |
---|
[472] | 1845 | InitializeClass(StudentApplication) |
---|
[179] | 1846 | |
---|
[472] | 1847 | def addStudentApplication(container, id, REQUEST=None, **kw): |
---|
[179] | 1848 | """Add a Students eligibility data.""" |
---|
[472] | 1849 | ob = StudentApplication(id, **kw) |
---|
[179] | 1850 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[763] | 1851 | ###) |
---|
[179] | 1852 | |
---|
[758] | 1853 | class StudentPume(CPSDocument): ###( |
---|
| 1854 | """ |
---|
| 1855 | WAeUP Student container for the various student data |
---|
| 1856 | """ |
---|
| 1857 | meta_type = 'StudentPume' |
---|
| 1858 | portal_type = meta_type |
---|
| 1859 | security = ClassSecurityInfo() |
---|
| 1860 | |
---|
| 1861 | security.declareProtected(View,"Title") |
---|
| 1862 | def Title(self): |
---|
| 1863 | """compose title""" |
---|
| 1864 | return "PUME Results" |
---|
| 1865 | |
---|
| 1866 | |
---|
| 1867 | InitializeClass(StudentPume) |
---|
| 1868 | |
---|
| 1869 | def addStudentPume(container, id, REQUEST=None, **kw): |
---|
| 1870 | """Add a Students PUME data.""" |
---|
| 1871 | ob = StudentPume(id, **kw) |
---|
| 1872 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[179] | 1873 | ###) |
---|
[181] | 1874 | |
---|
[565] | 1875 | ##class StudentSemester(CPSDocument): ###( |
---|
| 1876 | ## """ |
---|
| 1877 | ## WAeUP StudentSemester containing the courses and students |
---|
| 1878 | ## """ |
---|
| 1879 | ## meta_type = 'StudentSemester' |
---|
| 1880 | ## portal_type = meta_type |
---|
| 1881 | ## security = ClassSecurityInfo() |
---|
| 1882 | ## |
---|
| 1883 | ##InitializeClass(StudentSemester) |
---|
| 1884 | ## |
---|
| 1885 | ##def addStudentSemester(container, id, REQUEST=None, **kw): |
---|
| 1886 | ## """Add a StudentSemester.""" |
---|
| 1887 | ## ob = StudentSemester(id, **kw) |
---|
| 1888 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1889 | ## |
---|
| 1890 | #####) |
---|
[464] | 1891 | |
---|
[758] | 1892 | ##class Semester(CPSDocument): ###( |
---|
| 1893 | ## """ |
---|
| 1894 | ## WAeUP Semester containing the courses and students |
---|
| 1895 | ## """ |
---|
| 1896 | ## meta_type = 'Semester' |
---|
| 1897 | ## portal_type = meta_type |
---|
| 1898 | ## security = ClassSecurityInfo() |
---|
| 1899 | ## |
---|
| 1900 | ##InitializeClass(Semester) |
---|
| 1901 | ## |
---|
| 1902 | ##def addSemester(container, id, REQUEST=None, **kw): |
---|
| 1903 | ## """Add a Semester.""" |
---|
| 1904 | ## ob = Semester(id, **kw) |
---|
| 1905 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1906 | ## |
---|
| 1907 | #####) |
---|
[464] | 1908 | |
---|
| 1909 | class StudentCourseResult(CPSDocument): ###( |
---|
[89] | 1910 | """ |
---|
[464] | 1911 | WAeUP StudentCourseResult |
---|
[89] | 1912 | """ |
---|
[464] | 1913 | meta_type = 'StudentCourseResult' |
---|
[89] | 1914 | portal_type = meta_type |
---|
| 1915 | security = ClassSecurityInfo() |
---|
[472] | 1916 | |
---|
[454] | 1917 | def getCourseEntry(self,cid): |
---|
[723] | 1918 | res = self.portal_catalog({'meta_type': "Course", |
---|
[454] | 1919 | 'id': cid}) |
---|
| 1920 | if res: |
---|
| 1921 | return res[-1] |
---|
| 1922 | else: |
---|
| 1923 | return None |
---|
[154] | 1924 | |
---|
[454] | 1925 | security.declareProtected(View,"Title") |
---|
| 1926 | def Title(self): |
---|
| 1927 | """compose title""" |
---|
[723] | 1928 | cid = self.aq_parent.getId() |
---|
[454] | 1929 | ce = self.getCourseEntry(cid) |
---|
| 1930 | if ce: |
---|
| 1931 | return "%s" % ce.Title |
---|
| 1932 | return "No course with id %s" % cid |
---|
[152] | 1933 | |
---|
[464] | 1934 | InitializeClass(StudentCourseResult) |
---|
[454] | 1935 | |
---|
[464] | 1936 | def addStudentCourseResult(container, id, REQUEST=None, **kw): |
---|
| 1937 | """Add a StudentCourseResult.""" |
---|
| 1938 | ob = StudentCourseResult(id, **kw) |
---|
[89] | 1939 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[139] | 1940 | ###) |
---|
| 1941 | |
---|
[579] | 1942 | # Backward Compatibility StudyLevel |
---|
| 1943 | |
---|
| 1944 | from Products.WAeUP_SRP.Academics import StudyLevel |
---|
| 1945 | |
---|
| 1946 | from Products.WAeUP_SRP.Academics import addStudyLevel |
---|
| 1947 | |
---|