[57] | 1 | #-*- mode: python; mode: fold -*- |
---|
[200] | 2 | # $Id: Students.py 1700 2007-04-23 21:16:34Z 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 |
---|
[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 |
---|
[1515] | 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 |
---|
[961] | 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() |
---|
[975] | 430 | picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no) |
---|
[971] | 431 | #import pdb;pdb.set_trace() |
---|
| 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 |
---|
[1396] | 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 | |
---|
[1700] | 540 | security.declareProtected(ModifyPortalContent,"createNewStudents")###( |
---|
| 541 | def createParttimeStudents(self): |
---|
| 542 | """load Parttime Studentdata from CSV values""" |
---|
| 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() |
---|
| 548 | csv_d = {'jamb_reg_no': "Reg_No", |
---|
| 549 | 'jamb_firstname': "Firstname", |
---|
| 550 | 'jamb_middlename': "Middlename", |
---|
| 551 | 'jamb_lastname': "Lastname", |
---|
| 552 | 'jamb_sex': "Sex", |
---|
| 553 | 'entry_mode': 'Entry_mode', |
---|
| 554 | 'jamb_age': "Age", |
---|
| 555 | 'jamb_state': "State", |
---|
| 556 | ## 'jamb_first_cos': "AdminCourse", |
---|
| 557 | 'faculty': "AdminFaculty", |
---|
| 558 | 'course_code': "AdmitCoscode", |
---|
| 559 | 'stud_status':"AdmitStatus", |
---|
| 560 | 'department': "AdmitDept", |
---|
| 561 | 'jamb_lga': "LGA", |
---|
| 562 | 'app_email': "email", |
---|
| 563 | 'app_mobile': "PhoneNumbers", |
---|
| 564 | } |
---|
| 565 | csv_fields = [f[1] for f in csv_d.items()] |
---|
| 566 | tr_count = 0 |
---|
| 567 | total = 0 |
---|
| 568 | #name = 'pume_results' |
---|
| 569 | name = 'Admitted' |
---|
| 570 | no_import = [] |
---|
| 571 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
---|
| 572 | no_import.append('"Error",%s' % s) |
---|
| 573 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
---|
| 574 | no_certificate = "no certificate %s" % format |
---|
| 575 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import)) |
---|
| 576 | logger = logging.getLogger('Students.StudentsFolder.createNewStudents') |
---|
| 577 | logger.info('Start loading from %s.csv' % name) |
---|
| 578 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 579 | certs = {} |
---|
| 580 | cert_docs = {} |
---|
| 581 | for f in l: |
---|
| 582 | certs[f.getId] = f.getObject().getContent() |
---|
| 583 | try: |
---|
| 584 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 585 | except: |
---|
| 586 | logger.error('Error reading %s.csv' % name) |
---|
| 587 | return |
---|
| 588 | for jamb in result: |
---|
| 589 | jamb['Error'] = "Processing " |
---|
| 590 | logger.info(format % jamb) |
---|
| 591 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) |
---|
| 592 | res = self.portal_catalog({'portal_type': "StudentApplication", |
---|
| 593 | 'SearchableText': jamb_reg_no }) |
---|
| 594 | if res: |
---|
| 595 | em = 'Student with RegNo %s already exists\n' % jamb_reg_no |
---|
| 596 | logger.info(em) |
---|
| 597 | jamb['Error'] = "Student exists" |
---|
| 598 | no_import.append(format % jamb) |
---|
| 599 | continue |
---|
| 600 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) |
---|
| 601 | if cert_id not in certs.keys(): |
---|
| 602 | em = 'No Certificate with ID %s \n' % cert_id |
---|
| 603 | logger.info(em) |
---|
| 604 | jamb['Error'] = "No Certificate %s" % cert_id |
---|
| 605 | no_import.append( format % jamb) |
---|
| 606 | continue |
---|
| 607 | res = self.portal_pumeresults(jamb_reg_no = jamb_reg_no) |
---|
| 608 | if len(res) == 1: |
---|
| 609 | self.portal_pumeresults.modifyRecord(jamb_reg_no = jamb_reg_no, |
---|
| 610 | status = jamb.get(csv_d['stud_status']), |
---|
| 611 | ) |
---|
| 612 | jamb_reg_no =jamb.get(csv_d['jamb_reg_no']) |
---|
| 613 | cert_doc = certs[cert_id] |
---|
| 614 | catalog_entry = {} |
---|
| 615 | catalog_entry['jamb_reg_no'] = jamb_reg_no |
---|
| 616 | jamb_name = jamb.get(csv_d['jamb_lastname']) |
---|
| 617 | jamb_name.replace('>','') |
---|
| 618 | jamb_name.replace('<','') |
---|
| 619 | names = jamb_name.split() |
---|
| 620 | letter = names[-1][0].upper() |
---|
| 621 | sid = self.generateStudentId(letter) |
---|
| 622 | not_created = True |
---|
| 623 | while not_created: |
---|
| 624 | try: |
---|
| 625 | students_folder.invokeFactory('Student', sid) |
---|
| 626 | not_created = False |
---|
| 627 | except BadRequest: |
---|
| 628 | sid = self.generateStudentId(letter) |
---|
| 629 | catalog_entry['id'] = sid |
---|
| 630 | tr_count += 1 |
---|
| 631 | logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) |
---|
| 632 | student = getattr(self,sid) |
---|
| 633 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 634 | student.invokeFactory('StudentPume','pume') |
---|
| 635 | dp = {'Title': 'Pume Data'} |
---|
| 636 | student.invokeFactory('StudentApplication','application') |
---|
| 637 | da = {'Title': 'Application Data'} |
---|
| 638 | da["jamb_lastname"] = jamb_name |
---|
| 639 | da_fields = ('jamb_reg_no', |
---|
| 640 | 'jamb_sex', |
---|
| 641 | #'jamb_state', |
---|
| 642 | 'jamb_score', |
---|
| 643 | ## 'jamb_first_cos', |
---|
| 644 | 'jamb_sex', |
---|
| 645 | 'jamb_state', |
---|
| 646 | 'jamb_lga', |
---|
| 647 | 'app_email', |
---|
| 648 | 'app_mobile', |
---|
| 649 | ) |
---|
| 650 | for f in da_fields: |
---|
| 651 | da[f] = jamb.get(csv_d[f]) |
---|
| 652 | catalog_entry['email'] = jamb.get(csv_d['app_email']) |
---|
| 653 | app = student.application |
---|
| 654 | app_doc = app.getContent() |
---|
| 655 | picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no) |
---|
| 656 | #import pdb;pdb.set_trace() |
---|
| 657 | if os.path.exists(picture): |
---|
| 658 | file = open(picture) |
---|
| 659 | if False: |
---|
| 660 | img = PIL.Image.open(file) |
---|
| 661 | img.thumbnail((150,200), |
---|
| 662 | resample=PIL.Image.ANTIALIAS) |
---|
| 663 | # We now need a buffer to write to. It can't be the same |
---|
| 664 | # as the inbuffer as the PNG writer will write over itself. |
---|
| 665 | outfile = StringIO() |
---|
| 666 | img.save(outfile, format=img.format) |
---|
| 667 | else: |
---|
| 668 | outfile = file.read() |
---|
| 669 | app_doc.manage_addFile('passport', |
---|
| 670 | file=outfile, |
---|
| 671 | title="%s.jpg" % jamb_reg_no) |
---|
| 672 | app.getContent().edit(mapping=da) |
---|
| 673 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 674 | #wftool.doActionFor(app,'close') |
---|
| 675 | dp_fields = ( |
---|
| 676 | #'pume_eng_score', |
---|
| 677 | #'pume_gen_score', |
---|
| 678 | 'pume_tot_score', |
---|
| 679 | ) |
---|
| 680 | dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded" |
---|
| 681 | pume = student.pume |
---|
| 682 | pume.getContent().edit(mapping=dp) |
---|
| 683 | #wftool.doActionFor(pume,'close') |
---|
| 684 | pume.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 685 | #student.getContent().createSubObjects() |
---|
| 686 | dp = {} |
---|
| 687 | if len(names) == 3: |
---|
| 688 | dp['firstname'] = names[0].capitalize() |
---|
| 689 | dp['middlename'] = names[1].capitalize() |
---|
| 690 | dp['lastname'] = names[2].capitalize() |
---|
| 691 | elif len(names) == 2: |
---|
| 692 | dp['firstname'] = names[0].capitalize() |
---|
| 693 | dp['middlename'] = '' |
---|
| 694 | dp['lastname'] = names[1].capitalize() |
---|
| 695 | else: |
---|
| 696 | dp['firstname'] = '' |
---|
| 697 | dp['middlename'] = '' |
---|
| 698 | dp['lastname'] = jamb_name |
---|
| 699 | dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F' |
---|
| 700 | catalog_entry['sex'] = dp['sex'] |
---|
| 701 | catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp |
---|
| 702 | student.invokeFactory('StudentPersonal','personal') |
---|
| 703 | per = student.personal |
---|
| 704 | per_doc = per.getContent() |
---|
| 705 | per_doc.edit(mapping = dp) |
---|
| 706 | per.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 707 | if jamb.get(csv_d['stud_status']) == "Admitted": |
---|
| 708 | wftool.doActionFor(student,'pume_pass') |
---|
| 709 | wftool.doActionFor(student,'admit') |
---|
| 710 | else: |
---|
| 711 | wftool.doActionFor(student,'pume_fail') |
---|
| 712 | wftool.doActionFor(student,'reject_admission') |
---|
| 713 | continue |
---|
| 714 | # |
---|
| 715 | # Clearance |
---|
| 716 | # |
---|
| 717 | student.invokeFactory('StudentClearance','clearance') |
---|
| 718 | #wftool.doActionFor(student.clearance,'open') |
---|
| 719 | dp = {'Title': 'Clearance/Eligibility Record'} |
---|
| 720 | student.clearance.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 721 | # |
---|
| 722 | # Study Course |
---|
| 723 | # |
---|
| 724 | student.invokeFactory('StudentStudyCourse','study_course') |
---|
| 725 | study_course = student.study_course |
---|
| 726 | dsc = {} |
---|
| 727 | #from_certificate = ['title', |
---|
| 728 | # 'max_elect', |
---|
| 729 | # 'max_pass', |
---|
| 730 | # 'n_core', |
---|
| 731 | # 'nr_years', |
---|
| 732 | # 'probation_credits', |
---|
| 733 | # 'promotion_credits', |
---|
| 734 | # 'start_level', |
---|
| 735 | # ] |
---|
| 736 | #for f in from_certificate: |
---|
| 737 | # dsc[f] = getattr(cert_doc,f) |
---|
| 738 | #dsc['faculty'] = jamb.get(csv_d['faculty']) |
---|
| 739 | #dsc['department'] = jamb.get(csv_d['department']) |
---|
| 740 | catalog_entry['faculty'] = jamb.get(csv_d['faculty']) |
---|
| 741 | catalog_entry['department'] = jamb.get(csv_d['department']) |
---|
| 742 | catalog_entry['course'] = cert_id |
---|
| 743 | #catalog_entry['level'] = getattr(cert_doc,'start_level') |
---|
| 744 | catalog_entry['level'] = '100' |
---|
| 745 | dsc['study_course'] = cert_id |
---|
| 746 | dsc['entry_level'] = '100' |
---|
| 747 | #dsc['entry_session'] = jamb.get(csv_d['session']) |
---|
| 748 | study_course.getContent().edit(mapping=dsc) |
---|
| 749 | self.students_catalog.addRecord(**catalog_entry) |
---|
| 750 | if tr_count > 10: |
---|
| 751 | if len(no_import) > 0: |
---|
| 752 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
| 753 | '\n'.join(no_import) + "\n") |
---|
| 754 | no_import = [] |
---|
| 755 | em = '%d transactions commited\n' % tr_count |
---|
| 756 | transaction.commit() |
---|
| 757 | logger.info(em) |
---|
| 758 | total += tr_count |
---|
| 759 | tr_count = 0 |
---|
| 760 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
---|
| 761 | '\n'.join(no_import)) |
---|
| 762 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 763 | ###) |
---|
| 764 | |
---|
[1151] | 765 | security.declareProtected(ModifyPortalContent,"importReturningStudents")###( |
---|
| 766 | def importReturningStudents(self): |
---|
| 767 | """load Returning Studentdata from CSV values""" |
---|
[1146] | 768 | import transaction |
---|
| 769 | import random |
---|
| 770 | #from pdb import set_trace |
---|
| 771 | wftool = self.portal_workflow |
---|
| 772 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
[1616] | 773 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 774 | #students_folder = self.portal_url().getPortalObject().campus.students |
---|
[1146] | 775 | tr_count = 1 |
---|
| 776 | total = 0 |
---|
| 777 | #name = 'pume_results' |
---|
[1151] | 778 | name = 'Returning' |
---|
| 779 | table = self.returning_import |
---|
[1146] | 780 | no_import = [] |
---|
| 781 | imported = [] |
---|
[1571] | 782 | logger = logging.getLogger('Students.StudentsFolder.importReturningStudents') |
---|
[1146] | 783 | try: |
---|
[1151] | 784 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
[1146] | 785 | except: |
---|
| 786 | logger.error('Error reading %s.csv' % name) |
---|
| 787 | return |
---|
| 788 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 789 | certs = {} |
---|
| 790 | cert_docs = {} |
---|
| 791 | for f in l: |
---|
| 792 | certs[f.getId] = f.getObject().getContent() |
---|
| 793 | start = True |
---|
| 794 | res = table() |
---|
| 795 | regs = [] |
---|
| 796 | if len(res) > 0: |
---|
| 797 | regs = [s.matric_no for s in res] |
---|
[1319] | 798 | #import pdb;pdb.set_trace() |
---|
[1151] | 799 | for student in returning: |
---|
[1146] | 800 | if start: |
---|
| 801 | start = False |
---|
[1571] | 802 | logger.info('Start loading from %s.csv' % name) |
---|
[1319] | 803 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
---|
[1146] | 804 | imported.append(s) |
---|
| 805 | no_import.append('%s,"Error"' % s) |
---|
| 806 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
---|
| 807 | format_error = format + ',"%(Error)s"' |
---|
| 808 | no_certificate = "no certificate %s" % format |
---|
[1319] | 809 | student['matric_no'] = matric_no = student.get('matric_no').upper() |
---|
| 810 | student['Mode_of_Entry'] = entry_mode = student.get('Mode of Entry').upper() |
---|
| 811 | student['Permanent_Address'] = perm_address = student.get('Permanent Address') |
---|
[1168] | 812 | if matric_no == '': |
---|
[1252] | 813 | student['Error'] = "Empty matric_no" |
---|
[1146] | 814 | no_import.append( format_error % student) |
---|
| 815 | continue |
---|
[1168] | 816 | if matric_no in regs or self.returning_import(matric_no = matric_no): |
---|
[1252] | 817 | student['Error'] = "Duplicate" |
---|
[1146] | 818 | no_import.append( format_error % student) |
---|
| 819 | continue |
---|
| 820 | cert_id = makeCertificateCode(student.get('Coursemajorcode')) |
---|
| 821 | if cert_id not in certs.keys(): |
---|
| 822 | student['Error'] = "No Certificate %s" % cert_id |
---|
| 823 | no_import.append( format_error % student) |
---|
| 824 | continue |
---|
| 825 | try: |
---|
| 826 | table.addRecord(**student) |
---|
| 827 | except ValueError: |
---|
[1252] | 828 | student['Error'] = "Duplicate" |
---|
[1146] | 829 | no_import.append( format_error % student) |
---|
| 830 | continue |
---|
| 831 | regs.append(student.get('matric_no')) |
---|
| 832 | imported.append(format % student) |
---|
| 833 | tr_count += 1 |
---|
| 834 | if tr_count > 1000: |
---|
| 835 | if len(no_import) > 0: |
---|
| 836 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
[1151] | 837 | '\n'.join(no_import) + '\n') |
---|
[1146] | 838 | no_import = [] |
---|
| 839 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
[1151] | 840 | '\n'.join(no_import) + "\n") |
---|
| 841 | imported = [] |
---|
[1146] | 842 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
| 843 | transaction.commit() |
---|
[1168] | 844 | regs = [] |
---|
[1146] | 845 | logger.info(em) |
---|
| 846 | total += tr_count |
---|
| 847 | tr_count = 0 |
---|
| 848 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
[1252] | 849 | '\n'.join(imported)) |
---|
[1146] | 850 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 851 | '\n'.join(no_import)) |
---|
| 852 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 853 | ###) |
---|
| 854 | |
---|
[1529] | 855 | security.declareProtected(ModifyPortalContent,"fixVerdicts")###( |
---|
| 856 | def fixVerdicts(self,csv_file=None): |
---|
| 857 | """fix wrong uploaded verdicts""" |
---|
| 858 | import transaction |
---|
| 859 | import random |
---|
| 860 | wftool = self.portal_workflow |
---|
| 861 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 862 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 863 | tr_count = 1 |
---|
| 864 | total = 0 |
---|
| 865 | if csv_file is None: |
---|
| 866 | name = 'Verdicts' |
---|
| 867 | else: |
---|
| 868 | name = csv_file |
---|
| 869 | st_cat = self.students_catalog |
---|
| 870 | no_import = [] |
---|
| 871 | verdicts_voc = self.portal_vocabularies.verdicts |
---|
| 872 | rverdicts = {} |
---|
| 873 | for k,v in verdicts_voc.items(): |
---|
| 874 | rverdicts[v.upper()] = k |
---|
[1571] | 875 | rverdicts['STUDENT ON PROBATION'] = 'C' |
---|
| 876 | logger = logging.getLogger('Students.StudentsFolder.fixVerdicts') |
---|
[1529] | 877 | try: |
---|
| 878 | verdicts = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 879 | except: |
---|
| 880 | logger.error('Error reading %s.csv' % name) |
---|
| 881 | return |
---|
| 882 | start = True |
---|
| 883 | #import pdb;pdb.set_trace() |
---|
| 884 | for verdict in verdicts: |
---|
| 885 | if start: |
---|
| 886 | start = False |
---|
[1571] | 887 | logger.info('Start loading from %s.csv' % name) |
---|
[1529] | 888 | s = ','.join(['"%s"' % fn for fn in verdict.keys()]) |
---|
| 889 | no_import.append('%s,"Error"' % s) |
---|
| 890 | format = ','.join(['"%%(%s)s"' % fn for fn in verdict.keys()]) |
---|
| 891 | format_error = format + ',"%(Error)s"' |
---|
| 892 | matric_no = verdict.get('MAT NO') |
---|
| 893 | if not matric_no: |
---|
| 894 | continue |
---|
| 895 | matric_no = matric_no.upper() |
---|
| 896 | if matric_no == '': |
---|
| 897 | continue |
---|
| 898 | verdict_code = rverdicts.get(verdict.get('CATEGORY'),None) |
---|
| 899 | if verdict_code is None: |
---|
| 900 | continue |
---|
| 901 | sres = st_cat(matric_no = matric_no) |
---|
| 902 | if sres: |
---|
| 903 | student_id = sres[0].id |
---|
| 904 | student_obj = getattr(students_folder,student_id,None) |
---|
| 905 | if student_obj: |
---|
| 906 | study_course = getattr(student_obj,'study_course',None) |
---|
| 907 | if study_course is None: |
---|
| 908 | verdict['Error'] = "Student did not yet log in" |
---|
| 909 | no_import.append( format_error % verdict) |
---|
| 910 | continue |
---|
[1571] | 911 | st_cat.modifyRecord(id = student_id, |
---|
[1529] | 912 | verdict=verdict_code) |
---|
[1571] | 913 | |
---|
[1529] | 914 | dsc = {} |
---|
| 915 | dsc['current_verdict'] = verdict_code |
---|
| 916 | study_course.getContent().edit(mapping=dsc) |
---|
[1571] | 917 | else: |
---|
[1577] | 918 | verdict['Error'] = "Not found in students_catalog" |
---|
| 919 | no_import.append( format_error % verdict) |
---|
[1571] | 920 | continue |
---|
[1529] | 921 | tr_count += 1 |
---|
| 922 | if tr_count > 1000: |
---|
| 923 | if len(no_import) > 0: |
---|
| 924 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 925 | '\n'.join(no_import) + '\n') |
---|
| 926 | no_import = [] |
---|
| 927 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
| 928 | transaction.commit() |
---|
| 929 | regs = [] |
---|
| 930 | logger.info(em) |
---|
| 931 | total += tr_count |
---|
| 932 | tr_count = 0 |
---|
| 933 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 934 | '\n'.join(no_import)) |
---|
| 935 | total += tr_count |
---|
| 936 | em = '%d total transactions commited' % (total) |
---|
| 937 | logger.info(em) |
---|
| 938 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 939 | ###) |
---|
| 940 | |
---|
[1599] | 941 | security.declareProtected(ModifyPortalContent,"fixAllNames")###( |
---|
[1601] | 942 | def fixAllNames(self): |
---|
[1599] | 943 | "fix all students names" |
---|
| 944 | import transaction |
---|
| 945 | response = self.REQUEST.RESPONSE |
---|
| 946 | logger = logging.getLogger('fixAllNames') |
---|
| 947 | logger.info('Start') |
---|
| 948 | students = self.portal_catalog(portal_type='Student') |
---|
| 949 | count = 0 |
---|
| 950 | total = 0 |
---|
| 951 | for student in students: |
---|
| 952 | scat_res = self.students_catalog(id = student.getId) |
---|
| 953 | if not scat_res: |
---|
| 954 | self.students_catalog.addRecord(id = student.getId) |
---|
| 955 | scat_res = self.students_catalog(id = student.getId) |
---|
| 956 | student_entry = scat_res[0] |
---|
| 957 | old_new = self.fixName(student,student_entry) |
---|
| 958 | count += 1 |
---|
[1602] | 959 | response_write(response,'"%d","%s",%s' % (count + total,student_entry.id,old_new)) |
---|
[1599] | 960 | if count > 2000: |
---|
| 961 | transaction.commit() |
---|
| 962 | logger.info("%d transactions commited" % count) |
---|
| 963 | total += count |
---|
| 964 | count = 0 |
---|
| 965 | ###) |
---|
| 966 | |
---|
| 967 | security.declareProtected(ModifyPortalContent,"fixName")###( |
---|
[1601] | 968 | def fixName(self,student_brain, student_entry): |
---|
[1599] | 969 | "fix the name of a student" |
---|
| 970 | fix = "first" |
---|
| 971 | if student_entry.get('name_fixed',None) == fix: |
---|
| 972 | return "Name already fixed" |
---|
| 973 | student_id = student_entry.id |
---|
[1601] | 974 | new_student = student_entry.jamb_reg_no.startswith('6') |
---|
[1599] | 975 | student_obj = student_brain.getObject() |
---|
| 976 | personal = getattr(student_obj,'personal',None) |
---|
| 977 | invalid = '' |
---|
| 978 | if personal is None: |
---|
[1601] | 979 | return '"%s","Returning","%s","%s"' % (invalid,student_entry.name,"not logged in") |
---|
[1599] | 980 | per_doc = personal.getContent() |
---|
| 981 | old_first = per_doc.firstname |
---|
| 982 | old_middle = per_doc.middlename |
---|
| 983 | old_last = per_doc.lastname |
---|
| 984 | new_first = '' |
---|
| 985 | new_middle = '' |
---|
| 986 | new_last = '' |
---|
| 987 | if new_student: |
---|
| 988 | if not old_first and not old_middle and old_last: |
---|
| 989 | new_names = [n.capitalize() for n in old_last.split()] |
---|
[1611] | 990 | if len(new_names) > 1: |
---|
[1599] | 991 | old_first = new_names[0] |
---|
[1611] | 992 | old_last = new_names[-1] |
---|
| 993 | old_middle = ' '.join(new_names[1:-1]) |
---|
| 994 | else: |
---|
[1599] | 995 | old_last = new_names[0] |
---|
| 996 | old_first = '' |
---|
| 997 | old_middle = '' |
---|
[1611] | 998 | if old_first: |
---|
| 999 | new_first = old_first |
---|
[1599] | 1000 | if old_middle: |
---|
| 1001 | new_middle = old_middle |
---|
[1611] | 1002 | if old_last: |
---|
| 1003 | new_last = old_last |
---|
[1599] | 1004 | if old_first.find('<') != -1 or\ |
---|
| 1005 | old_first.find('>') != -1 or\ |
---|
| 1006 | old_middle.find('<') != -1 or\ |
---|
| 1007 | old_middle.find('>') != -1 or\ |
---|
| 1008 | old_last.find('<') != -1 or\ |
---|
| 1009 | old_last.find('>') != -1: |
---|
| 1010 | invalid = "invalid characters" |
---|
| 1011 | else: |
---|
[1611] | 1012 | new_first = old_first |
---|
| 1013 | if new_first.strip() == '-': |
---|
[1599] | 1014 | new_first = '' |
---|
[1611] | 1015 | new_middle = old_middle |
---|
| 1016 | if new_middle.strip() == '-': |
---|
[1599] | 1017 | new_middle = '' |
---|
[1611] | 1018 | new_last = old_last |
---|
| 1019 | if new_last.strip() == '-': |
---|
[1599] | 1020 | new_last = '' |
---|
[1611] | 1021 | name = "%(new_first)s %(new_middle)s %(new_last)s" % vars() |
---|
[1599] | 1022 | if new_student: |
---|
| 1023 | text = "New" |
---|
| 1024 | else: |
---|
| 1025 | text = "Returning" |
---|
[1601] | 1026 | old_new = '"%s","%s","%s","%s"' % (invalid,text, |
---|
[1599] | 1027 | student_entry.name, |
---|
| 1028 | name) |
---|
| 1029 | if not invalid: |
---|
| 1030 | self.students_catalog.modifyRecord(id = student_id, |
---|
| 1031 | name_fixed = fix, |
---|
| 1032 | name = name) |
---|
| 1033 | per_doc.edit(mapping = {'firstname' : new_first, |
---|
| 1034 | 'middlename' : new_middle, |
---|
| 1035 | 'lastname' : new_last, |
---|
| 1036 | }) |
---|
| 1037 | return old_new |
---|
| 1038 | ###) |
---|
| 1039 | |
---|
[1319] | 1040 | security.declareProtected(ModifyPortalContent,"fixAllEntryModeForReturning")###( |
---|
| 1041 | def fixAllEntryModeForReturning(self): |
---|
| 1042 | "read all Returning*.csv" |
---|
| 1043 | ipath = "%s/import/" % i_home |
---|
| 1044 | names = os.listdir(ipath) |
---|
| 1045 | for name in names: |
---|
| 1046 | head,tail = os.path.splitext(name) |
---|
| 1047 | if head.startswith('Returning')\ |
---|
| 1048 | and tail == '.csv'\ |
---|
| 1049 | and name.find('imported') < 0: |
---|
| 1050 | self.fixEntryModeForReturning(csv_file=head) |
---|
[1322] | 1051 | ###) |
---|
[1386] | 1052 | |
---|
[1319] | 1053 | security.declareProtected(ModifyPortalContent,"fixEntryModeForReturning")###( |
---|
| 1054 | def fixEntryModeForReturning(self,csv_file=None): |
---|
| 1055 | """load Returning Studentdata from CSV values""" |
---|
| 1056 | import transaction |
---|
| 1057 | import random |
---|
| 1058 | wftool = self.portal_workflow |
---|
| 1059 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 1060 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1061 | tr_count = 1 |
---|
| 1062 | total = 0 |
---|
| 1063 | if csv_file is None: |
---|
| 1064 | name = 'Returning' |
---|
| 1065 | else: |
---|
| 1066 | name = csv_file |
---|
| 1067 | table = self.returning_import |
---|
| 1068 | st_cat = self.students_catalog |
---|
| 1069 | no_import = [] |
---|
[1571] | 1070 | logger = logging.getLogger('Students.StudentsFolder.fixEntryModeForReturning') |
---|
[1319] | 1071 | try: |
---|
| 1072 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 1073 | except: |
---|
| 1074 | logger.error('Error reading %s.csv' % name) |
---|
| 1075 | return |
---|
| 1076 | start = True |
---|
| 1077 | for student in returning: |
---|
| 1078 | if start: |
---|
| 1079 | start = False |
---|
[1571] | 1080 | logger.info('Start loading from %s.csv' % name) |
---|
[1321] | 1081 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
---|
[1319] | 1082 | no_import.append('%s,"Error"' % s) |
---|
| 1083 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
---|
| 1084 | format_error = format + ',"%(Error)s"' |
---|
| 1085 | matric_no = student.get('matric_no') |
---|
| 1086 | if not matric_no: |
---|
| 1087 | continue |
---|
| 1088 | matric_no = matric_no.upper() |
---|
| 1089 | student['matric_no'] = matric_no |
---|
| 1090 | if matric_no == '': |
---|
| 1091 | continue |
---|
| 1092 | if not table(matric_no = matric_no): |
---|
| 1093 | student['Error'] = "Not imported yet" |
---|
| 1094 | no_import.append( format_error % student) |
---|
| 1095 | continue |
---|
| 1096 | student_id = None |
---|
| 1097 | app = None |
---|
| 1098 | per = None |
---|
| 1099 | if st_cat(matric_no = matric_no): |
---|
| 1100 | student_id = st_cat(matric_no = matric_no)[0].id |
---|
[1322] | 1101 | student_obj = getattr(students_folder,student_id,None) |
---|
| 1102 | if student_obj: |
---|
| 1103 | app = getattr(student_obj,'application',None) |
---|
| 1104 | if app is not None: |
---|
| 1105 | app_doc = app.getContent() |
---|
| 1106 | per = getattr(student_obj,'personal',None) |
---|
| 1107 | if per is not None: |
---|
| 1108 | per_doc = per.getContent() |
---|
[1319] | 1109 | student['Mode_of_Entry'] = entry_mode = student.get('Mode of Entry').upper() |
---|
| 1110 | student['Permanent_Address'] = perm_address = student.get('Permanent Address') |
---|
[1322] | 1111 | #import pdb;pdb.set_trace() |
---|
[1319] | 1112 | if not entry_mode: |
---|
| 1113 | student['Error'] = "'Mode of Entry' empty" |
---|
| 1114 | no_import.append( format_error % student) |
---|
| 1115 | continue |
---|
| 1116 | try: |
---|
| 1117 | table.modifyRecord(matric_no = matric_no, |
---|
| 1118 | Mode_of_Entry = entry_mode, |
---|
| 1119 | Permanent_Address = perm_address) |
---|
| 1120 | except KeyError: |
---|
| 1121 | student['Error'] = "Not found in returning_import" |
---|
| 1122 | no_import.append( format_error % student) |
---|
| 1123 | continue |
---|
| 1124 | if student_id is not None: |
---|
| 1125 | try: |
---|
| 1126 | st_cat.modifyRecord(id = student_id, |
---|
| 1127 | entry_mode=entry_mode) |
---|
| 1128 | except KeyError: |
---|
| 1129 | student['Error'] = "Not found in students_catalog" |
---|
| 1130 | no_import.append( format_error % student) |
---|
| 1131 | continue |
---|
| 1132 | if app is not None: |
---|
| 1133 | da = {} |
---|
| 1134 | da['entry_mode'] = entry_mode |
---|
| 1135 | app_doc.edit(mapping=da) |
---|
| 1136 | if per is not None: |
---|
| 1137 | dp = {} |
---|
[1350] | 1138 | dp['perm_address'] = perm_address |
---|
[1319] | 1139 | per_doc.edit(mapping=dp) |
---|
| 1140 | tr_count += 1 |
---|
| 1141 | if tr_count > 1000: |
---|
| 1142 | if len(no_import) > 0: |
---|
| 1143 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1144 | '\n'.join(no_import) + '\n') |
---|
| 1145 | no_import = [] |
---|
| 1146 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
| 1147 | transaction.commit() |
---|
| 1148 | regs = [] |
---|
| 1149 | logger.info(em) |
---|
| 1150 | total += tr_count |
---|
| 1151 | tr_count = 0 |
---|
| 1152 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1153 | '\n'.join(no_import)) |
---|
| 1154 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 1155 | ###) |
---|
[1289] | 1156 | |
---|
| 1157 | security.declareProtected(ModifyPortalContent,"updateReturningStudents")###( |
---|
| 1158 | def updateReturningStudents(self): |
---|
| 1159 | """load and overwrite Returning Student Data from CSV values""" |
---|
| 1160 | import transaction |
---|
| 1161 | import random |
---|
| 1162 | #from pdb import set_trace |
---|
| 1163 | wftool = self.portal_workflow |
---|
| 1164 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 1165 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 1166 | tr_count = 1 |
---|
| 1167 | total = 0 |
---|
| 1168 | #name = 'pume_results' |
---|
| 1169 | name = 'Returning_update' |
---|
| 1170 | table = self.returning_import |
---|
| 1171 | no_import = [] |
---|
| 1172 | imported = [] |
---|
[1571] | 1173 | logger = logging.getLogger('Students.StudentsFolder.updateReturningStudents') |
---|
[1289] | 1174 | try: |
---|
| 1175 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 1176 | except: |
---|
| 1177 | logger.error('Error reading %s.csv' % name) |
---|
| 1178 | return |
---|
| 1179 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 1180 | certs = {} |
---|
| 1181 | cert_docs = {} |
---|
| 1182 | for f in l: |
---|
| 1183 | certs[f.getId] = f.getObject().getContent() |
---|
| 1184 | start = True |
---|
| 1185 | res = table() |
---|
| 1186 | regs = [] |
---|
| 1187 | if len(res) > 0: |
---|
| 1188 | regs = [s.matric_no for s in res] |
---|
| 1189 | for student in returning: |
---|
| 1190 | if start: |
---|
| 1191 | start = False |
---|
[1571] | 1192 | logger.info('Start loading from %s.csv' % name) |
---|
[1321] | 1193 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
---|
[1289] | 1194 | imported.append(s) |
---|
| 1195 | no_import.append('%s,"Error"' % s) |
---|
| 1196 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
---|
| 1197 | format_error = format + ',"%(Error)s"' |
---|
| 1198 | no_certificate = "no certificate %s" % format |
---|
| 1199 | matric_no = student.get('matric_no').upper() |
---|
| 1200 | student['matric_no'] = matric_no |
---|
| 1201 | if matric_no == '': |
---|
| 1202 | student['Error'] = "Empty matric_no" |
---|
| 1203 | no_import.append( format_error % student) |
---|
| 1204 | continue |
---|
| 1205 | # if matric_no in regs or self.returning_import(matric_no = matric_no): |
---|
| 1206 | # student['Error'] = "Duplicate" |
---|
| 1207 | # no_import.append( format_error % student) |
---|
| 1208 | # continue |
---|
| 1209 | # cert_id = makeCertificateCode(student.get('Coursemajorcode')) |
---|
| 1210 | # if cert_id not in certs.keys(): |
---|
| 1211 | # student['Error'] = "No Certificate %s" % cert_id |
---|
| 1212 | # no_import.append( format_error % student) |
---|
| 1213 | # continue |
---|
| 1214 | try: |
---|
| 1215 | table.modifyRecord(**student) |
---|
| 1216 | except KeyError: |
---|
| 1217 | #import pdb;pdb.set_trace() |
---|
| 1218 | student['Error'] = "no Student found to update" |
---|
| 1219 | no_import.append( format_error % student) |
---|
| 1220 | continue |
---|
[1386] | 1221 | #s = self.students_catalog(matric_no=matric_no) |
---|
| 1222 | #if s: |
---|
| 1223 | # level = "%s" % (int(student.get('Level')) + 100) |
---|
| 1224 | # self.students_catalog.modifyRecord(id = s[0].id, |
---|
| 1225 | # level=level) |
---|
[1289] | 1226 | |
---|
| 1227 | regs.append(student.get('matric_no')) |
---|
| 1228 | imported.append(format % student) |
---|
| 1229 | tr_count += 1 |
---|
| 1230 | if tr_count > 1000: |
---|
| 1231 | if len(no_import) > 0: |
---|
| 1232 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1233 | '\n'.join(no_import) + '\n') |
---|
| 1234 | no_import = [] |
---|
| 1235 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1236 | '\n'.join(no_import) + "\n") |
---|
| 1237 | imported = [] |
---|
| 1238 | em = '%d transactions commited total %s\n' % (tr_count,total) |
---|
| 1239 | transaction.commit() |
---|
| 1240 | regs = [] |
---|
| 1241 | logger.info(em) |
---|
| 1242 | total += tr_count |
---|
| 1243 | tr_count = 0 |
---|
| 1244 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1245 | '\n'.join(imported)) |
---|
| 1246 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1247 | '\n'.join(no_import)) |
---|
| 1248 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 1249 | ###) |
---|
| 1250 | |
---|
[1146] | 1251 | security.declareProtected(ModifyPortalContent,"importResults")###( |
---|
| 1252 | def importResults(self): |
---|
[1151] | 1253 | """load Returning Students Results from CSV""" |
---|
[1146] | 1254 | import transaction |
---|
| 1255 | import random |
---|
| 1256 | #from pdb import set_trace |
---|
| 1257 | wftool = self.portal_workflow |
---|
| 1258 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 1259 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 1260 | tr_count = 1 |
---|
| 1261 | total = 0 |
---|
| 1262 | #name = 'pume_results' |
---|
| 1263 | name = 'Results' |
---|
| 1264 | table = self.results_import |
---|
| 1265 | no_import = [] |
---|
| 1266 | imported = [] |
---|
[1571] | 1267 | logger = logging.getLogger('Students.StudentsFolder.importResults') |
---|
[1146] | 1268 | try: |
---|
| 1269 | results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 1270 | except: |
---|
| 1271 | logger.error('Error reading %s.csv' % name) |
---|
| 1272 | return |
---|
| 1273 | l = self.portal_catalog({'meta_type': "Course"}) |
---|
| 1274 | courses = [f.getId for f in l] |
---|
| 1275 | start = True |
---|
| 1276 | res = table() |
---|
| 1277 | regs = [] |
---|
| 1278 | if len(res) > 0: |
---|
| 1279 | regs = [s.key for s in res] |
---|
| 1280 | no_course = [] |
---|
| 1281 | no_course_list = [] |
---|
| 1282 | course_count = 0 |
---|
| 1283 | for result in results: |
---|
| 1284 | if start: |
---|
| 1285 | start = False |
---|
[1571] | 1286 | logger.info('Start loading from %s.csv' % name) |
---|
[1321] | 1287 | s = ','.join(['"%s"' % fn for fn in result.keys()]) |
---|
[1146] | 1288 | imported.append(s) |
---|
| 1289 | no_import.append('%s,"Error"' % s) |
---|
| 1290 | format = ','.join(['"%%(%s)s"' % fn for fn in result.keys()]) |
---|
| 1291 | format_error = format + ',"%(Error)s"' |
---|
| 1292 | no_certificate = "no certificate %s" % format |
---|
| 1293 | course_id = result.get('CosCode') |
---|
[1448] | 1294 | if not course_id: |
---|
| 1295 | course_id = 'N/A' |
---|
| 1296 | result['CosCode'] = course_id |
---|
[1168] | 1297 | matric_no = result.get('matric_no').upper() |
---|
| 1298 | result['matric_no'] = matric_no |
---|
| 1299 | key = matric_no+course_id |
---|
| 1300 | if matric_no == '': |
---|
[1252] | 1301 | result['Error'] = "Empty matric_no" |
---|
[1146] | 1302 | no_import.append( format_error % result) |
---|
| 1303 | continue |
---|
[1168] | 1304 | if key in regs or self.results_import(key = key): |
---|
[1252] | 1305 | result['Error'] = "Duplicate" |
---|
[1146] | 1306 | no_import.append( format_error % result) |
---|
| 1307 | continue |
---|
| 1308 | if course_id not in courses: |
---|
| 1309 | if course_id not in no_course: |
---|
| 1310 | course_count +=1 |
---|
| 1311 | no_course.append(course_id) |
---|
| 1312 | no_course_list.append('"%s"' % course_id) |
---|
| 1313 | #result['Error'] = "No Course" |
---|
| 1314 | #logger.info(format_error % result) |
---|
| 1315 | regs.append(key) |
---|
| 1316 | imported.append(format % result) |
---|
| 1317 | tr_count += 1 |
---|
| 1318 | if tr_count > 1000: |
---|
| 1319 | if len(no_import) > 0: |
---|
| 1320 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
[1151] | 1321 | '\n'.join(no_import)+'\n') |
---|
[1146] | 1322 | no_import = [] |
---|
| 1323 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
[1151] | 1324 | '\n'.join(imported) + '\n') |
---|
[1146] | 1325 | imported = [] |
---|
| 1326 | if no_course_list: |
---|
| 1327 | open("%s/import/%sno_courses%s.csv" % (i_home,name,current),"a").write( |
---|
[1151] | 1328 | '\n'.join(no_course_list) + '\n') |
---|
[1146] | 1329 | no_course_list = [] |
---|
| 1330 | em = '%d transactions commited total %s\n courses not found %s' % (tr_count,total,course_count) |
---|
| 1331 | transaction.commit() |
---|
| 1332 | logger.info(em) |
---|
[1168] | 1333 | regs = [] |
---|
[1146] | 1334 | total += tr_count |
---|
| 1335 | tr_count = 0 |
---|
| 1336 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1337 | '\n'.join(imported)) |
---|
| 1338 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1339 | '\n'.join(no_import)) |
---|
| 1340 | if no_course_list: |
---|
| 1341 | open("%s/import/%sno_courses%s.csv" % (i_home,name,current),"a").write( |
---|
| 1342 | '\n'.join(no_course_list)) |
---|
[1393] | 1343 | em = '%d transactions commited total %s\n courses not found %s' % (tr_count,total,course_count) |
---|
| 1344 | logger.info(em) |
---|
[1146] | 1345 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 1346 | ###) |
---|
| 1347 | |
---|
[1700] | 1348 | security.declareProtected(ModifyPortalContent,"importPreviousSessionStudents")###( |
---|
| 1349 | def importPreviousSessionStudents(self): |
---|
| 1350 | """load and create previous session students from CSV""" |
---|
| 1351 | import transaction |
---|
| 1352 | import random |
---|
| 1353 | wftool = self.portal_workflow |
---|
| 1354 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 1355 | students_folder = self.portal_url.getPortalObject().campus.students |
---|
| 1356 | tr_count = 1 |
---|
| 1357 | total = 0 |
---|
| 1358 | #name = 'pume_results' |
---|
| 1359 | name = 'Previous' |
---|
| 1360 | keys = self.portal_schemas.import_student.keys() |
---|
| 1361 | keys += self.portal_schemas.import_student_level_data.keys() |
---|
| 1362 | not_imported = [] |
---|
| 1363 | imported = [] |
---|
| 1364 | certificates = {} |
---|
| 1365 | logger = logging.getLogger('Students.StudentsFolder.importPreviousSessionStudents') |
---|
| 1366 | try: |
---|
| 1367 | records = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 1368 | except: |
---|
| 1369 | logger.error('Error reading %s.csv' % name) |
---|
| 1370 | return |
---|
| 1371 | start = True |
---|
| 1372 | for record in records: |
---|
| 1373 | if start: |
---|
| 1374 | start = False |
---|
| 1375 | logger.info('Start loading from %s.csv' % name) |
---|
| 1376 | false_keys = [k for k in record.keys() if k not in keys] |
---|
| 1377 | right_keys = [k for k in record.keys() if k in keys] |
---|
| 1378 | if false_keys: |
---|
| 1379 | logger.info('Fields %s not in schema' % false_keys) |
---|
| 1380 | s = ','.join(['"%s"' % k for k in right_keys]) |
---|
| 1381 | imported.append(s) |
---|
| 1382 | not_imported.append('%s,"error"' % s) |
---|
| 1383 | format = ','.join(['"%%(%s)s"' % k for k in right_keys]) |
---|
| 1384 | format_error = format + ',"%(error)s"' |
---|
| 1385 | study_course = record.get('study_course') |
---|
| 1386 | matric_no = record.get('matric_no') |
---|
| 1387 | student_res = self.students_catalog(matric_no = matric_no) |
---|
| 1388 | if student_res: |
---|
| 1389 | record['error'] = "Student exists" |
---|
| 1390 | not_imported.append(format_error % record) |
---|
| 1391 | continue |
---|
| 1392 | if study_course not in certificates.keys(): |
---|
| 1393 | cert_res = self.portal_catalog(portal_type='Certificate', |
---|
| 1394 | id = study_course) |
---|
| 1395 | if not cert_res: |
---|
| 1396 | record['error'] = "No such studycourse" |
---|
| 1397 | not_imported.append(format_error % record) |
---|
| 1398 | continue |
---|
| 1399 | certificates[cert_res[0].id] = cert_res[0] |
---|
| 1400 | sid = self.generateStudentId('x',students_folder) |
---|
| 1401 | students_folder.invokeFactory('Student', sid) |
---|
| 1402 | #from pdb import set_trace;set_trace() |
---|
| 1403 | record['student_id'] = sid |
---|
| 1404 | student = getattr(self,sid) |
---|
| 1405 | student.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1406 | student.invokeFactory('StudentApplication','application') |
---|
| 1407 | app = student.application |
---|
| 1408 | app_doc = app.getContent() |
---|
| 1409 | dict = {'Title': 'Application Data'} |
---|
| 1410 | dict["jamb_lastname"] = "%(firstname)s %(lastname)s %(middlename)s" % record |
---|
| 1411 | r2d = [ |
---|
| 1412 | ('entry_mode','entry_mode'), |
---|
| 1413 | ('sex','jamb_sex'), |
---|
| 1414 | ('jamb_score','jamb_score'), |
---|
| 1415 | ('jamb_reg_no','jamb_reg_no'), |
---|
| 1416 | ] |
---|
| 1417 | for r,d in r2d: |
---|
| 1418 | dict[d] = record[r] |
---|
| 1419 | app_doc.edit(mapping=dict) |
---|
| 1420 | app.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1421 | wftool.doActionFor(app,'close') |
---|
| 1422 | record['sex'] = record['sex'] == 'F' |
---|
| 1423 | student.invokeFactory('StudentPersonal','personal') |
---|
| 1424 | dict = {} |
---|
| 1425 | r2d = [('firstname','firstname'), |
---|
| 1426 | ('middlename','middlename'), |
---|
| 1427 | ('lastname','lastname'), |
---|
| 1428 | ('sex','sex'), |
---|
| 1429 | ('email','email'), |
---|
| 1430 | ('phone','phone'), |
---|
| 1431 | ('address','perm_address'), |
---|
| 1432 | ] |
---|
| 1433 | for r,d in r2d: |
---|
| 1434 | dict[d] = record[r] |
---|
| 1435 | per = student.personal |
---|
| 1436 | per_doc = per.getContent() |
---|
| 1437 | per_doc.edit(mapping = dict) |
---|
| 1438 | per.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1439 | # |
---|
| 1440 | # Clearance |
---|
| 1441 | # |
---|
| 1442 | student.invokeFactory('StudentClearance','clearance') |
---|
| 1443 | #wftool.doActionFor(student.clearance,'open') |
---|
| 1444 | clearance = getattr(student,'clearance') |
---|
| 1445 | dict = {'Title': 'Clearance/Eligibility Record'} |
---|
| 1446 | clearance.getContent().edit(mapping = dict) |
---|
| 1447 | student.clearance.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1448 | # |
---|
| 1449 | # Study Course |
---|
| 1450 | # |
---|
| 1451 | student.invokeFactory('StudentStudyCourse','study_course') |
---|
| 1452 | study_course = student.study_course |
---|
| 1453 | dict = {} |
---|
| 1454 | r2d = [('session','current_session'), |
---|
| 1455 | ('level','current_level'), |
---|
| 1456 | ('verdict','current_verdict'), |
---|
| 1457 | ('study_course','study_course'), |
---|
| 1458 | ] |
---|
| 1459 | for r,d in r2d: |
---|
| 1460 | dict[d] = record[r] |
---|
| 1461 | study_course.getContent().edit(mapping=dict) |
---|
| 1462 | # |
---|
| 1463 | # Study Level |
---|
| 1464 | # |
---|
| 1465 | level = record['level'] |
---|
| 1466 | study_course.invokeFactory('StudentStudyLevel',level) |
---|
| 1467 | study_level = getattr(study_course,level) |
---|
| 1468 | dict = {} |
---|
| 1469 | r2d = [('session','session'), |
---|
| 1470 | ('level','code'), |
---|
| 1471 | ('verdict','verdict'), |
---|
| 1472 | ] |
---|
| 1473 | for r,d in r2d: |
---|
| 1474 | dict[d] = record[r] |
---|
| 1475 | study_level.getContent().edit(mapping=dict) |
---|
| 1476 | wftool.doActionFor(student,'return') |
---|
| 1477 | imported.append(format % record) |
---|
| 1478 | tr_count += 1 |
---|
| 1479 | record['tr_count'] = tr_count |
---|
| 1480 | record['total'] = total |
---|
| 1481 | logger.info('%(total)s+%(tr_count)s: Creating Student %(student_id)s %(matric_no)s %(jamb_reg_no)s' % record) |
---|
| 1482 | if tr_count > 1000: |
---|
| 1483 | if len(not_imported) > 0: |
---|
| 1484 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1485 | '\n'.join(not_imported)+'\n') |
---|
| 1486 | not_imported = [] |
---|
| 1487 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1488 | '\n'.join(imported) + '\n') |
---|
| 1489 | imported = [] |
---|
| 1490 | em = '%d transactions commited total %s' % (tr_count,total) |
---|
| 1491 | transaction.commit() |
---|
| 1492 | logger.info(em) |
---|
| 1493 | regs = [] |
---|
| 1494 | total += tr_count |
---|
| 1495 | tr_count = 0 |
---|
| 1496 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1497 | '\n'.join(imported)) |
---|
| 1498 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
---|
| 1499 | '\n'.join(not_imported)) |
---|
| 1500 | em = '%d transactions commited total %d' % (tr_count,total) |
---|
| 1501 | logger.info(em) |
---|
| 1502 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 1503 | ###) |
---|
| 1504 | |
---|
[1065] | 1505 | security.declareProtected(ModifyPortalContent,"updateStudyCourse")###( |
---|
| 1506 | def updateStudyCourse(self): |
---|
| 1507 | """update StudyCourse from CSV values""" |
---|
| 1508 | import transaction |
---|
| 1509 | import random |
---|
| 1510 | from pdb import set_trace |
---|
| 1511 | wftool = self.portal_workflow |
---|
| 1512 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
---|
| 1513 | csv_d = {'jamb_reg_no': "RegNumber", |
---|
| 1514 | 'jamb_lastname': "Name", |
---|
| 1515 | 'session': "Session", |
---|
| 1516 | 'pume_tot_score': "PUME SCORE", |
---|
| 1517 | 'jamb_score': "JambScore", |
---|
| 1518 | 'jamb_sex': "Sex", |
---|
| 1519 | 'jamb_state': "State", |
---|
| 1520 | ## 'jamb_first_cos': "AdminCourse", |
---|
| 1521 | 'faculty': "AdminFaculty", |
---|
| 1522 | 'course_code': "AdmitCoscode", |
---|
| 1523 | 'stud_status':"AdmitStatus", |
---|
| 1524 | 'department': "AdmitDept", |
---|
| 1525 | 'jamb_lga': "LGA", |
---|
| 1526 | 'app_email': "email", |
---|
| 1527 | 'app_mobile': "PhoneNumbers", |
---|
| 1528 | } |
---|
| 1529 | csv_fields = [f[1] for f in csv_d.items()] |
---|
| 1530 | tr_count = 0 |
---|
| 1531 | total = 0 |
---|
| 1532 | #name = 'pume_results' |
---|
| 1533 | name = 'StudyCourseChange' |
---|
| 1534 | no_import = [] |
---|
[1321] | 1535 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
---|
[1065] | 1536 | no_import.append('"Error",%s' % s) |
---|
| 1537 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
---|
| 1538 | no_certificate = "no certificate %s" % format |
---|
| 1539 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( |
---|
| 1540 | '\n'.join(no_import)) |
---|
[1571] | 1541 | logger = logging.getLogger('Students.StudentsFolder.updateStudyCourse') |
---|
[1065] | 1542 | logger.info('Start loading from %s.csv' % name) |
---|
| 1543 | l = self.portal_catalog({'meta_type': "Certificate"}) |
---|
| 1544 | try: |
---|
| 1545 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
---|
| 1546 | except: |
---|
| 1547 | logger.error('Error reading %s.csv' % name) |
---|
| 1548 | return |
---|
| 1549 | for jamb in result: |
---|
| 1550 | jamb['Error'] = "Processing " |
---|
| 1551 | logger.info(format % jamb) |
---|
| 1552 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) |
---|
| 1553 | res = self.portal_catalog({'portal_type': "StudentApplication", |
---|
| 1554 | 'SearchableText': jamb_reg_no }) |
---|
| 1555 | if not res: |
---|
[1571] | 1556 | em = 'Student with jamb_reg_no %s does not exists\n' % jamb_reg_no |
---|
[1065] | 1557 | logger.info(em) |
---|
[1571] | 1558 | jamb['Error'] = "Student does not exist" |
---|
[1065] | 1559 | no_import.append(format % jamb) |
---|
| 1560 | continue |
---|
| 1561 | sid = res[0].getPath().split('/')[-2] |
---|
| 1562 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) |
---|
| 1563 | res = self.portal_catalog(portal_type = "Certificate", id = cert_id) |
---|
| 1564 | if not res: |
---|
| 1565 | em = 'No Certificate with ID %s \n' % cert_id |
---|
| 1566 | logger.info(em) |
---|
| 1567 | jamb['Error'] = "No Certificate %s" % cert_id |
---|
| 1568 | no_import.append( format % jamb) |
---|
| 1569 | continue |
---|
| 1570 | cert_brain = res[0] |
---|
| 1571 | catalog_entry = {} |
---|
| 1572 | student = getattr(self,sid) |
---|
| 1573 | # |
---|
| 1574 | # Study Course |
---|
| 1575 | # |
---|
| 1576 | study_course = student.study_course |
---|
| 1577 | dsc = {} |
---|
| 1578 | cert_pl = cert_brain.getPath().split('/') |
---|
| 1579 | catalog_entry['id'] = sid |
---|
| 1580 | catalog_entry['faculty'] = cert_pl[-4] |
---|
| 1581 | catalog_entry['department'] = cert_pl[-3] |
---|
| 1582 | catalog_entry['course'] = cert_id |
---|
| 1583 | dsc['study_course'] = cert_id |
---|
| 1584 | study_course.getContent().edit(mapping=dsc) |
---|
| 1585 | self.students_catalog.modifyRecord(**catalog_entry) |
---|
| 1586 | if tr_count > 10: |
---|
| 1587 | if len(no_import) > 1: |
---|
| 1588 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write( |
---|
| 1589 | '\n'.join(no_import)) |
---|
| 1590 | no_import = [] |
---|
| 1591 | em = '%d transactions commited\n' % tr_count |
---|
| 1592 | transaction.commit() |
---|
| 1593 | logger.info(em) |
---|
| 1594 | total += tr_count |
---|
| 1595 | tr_count = 0 |
---|
| 1596 | tr_count += 1 |
---|
| 1597 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
---|
| 1598 | ###) |
---|
| 1599 | |
---|
[1594] | 1600 | security.declareProtected(View,"fixOwnership") ###( |
---|
[511] | 1601 | def fixOwnership(self): |
---|
| 1602 | """fix Ownership""" |
---|
| 1603 | for s in self.portal_catalog(meta_type = 'Student'): |
---|
| 1604 | student = s.getObject() |
---|
| 1605 | sid = s.getId |
---|
| 1606 | import pdb;pdb.set_trace() |
---|
| 1607 | student.application.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1608 | student.personal.manage_setLocalRoles(sid, ['Owner',]) |
---|
[1594] | 1609 | ###) |
---|
[603] | 1610 | |
---|
[1594] | 1611 | security.declareProtected(View,"Title") ###( |
---|
[364] | 1612 | def Title(self): |
---|
| 1613 | """compose title""" |
---|
[382] | 1614 | return "Student Section" |
---|
[1594] | 1615 | ###) |
---|
[361] | 1616 | |
---|
[1700] | 1617 | def generateStudentId(self,letter,students = None): ###( |
---|
[714] | 1618 | import random |
---|
| 1619 | r = random |
---|
[1700] | 1620 | if students is None: |
---|
| 1621 | students = self.portal_url.getPortalObject().campus.students |
---|
[714] | 1622 | if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'): |
---|
| 1623 | letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY') |
---|
| 1624 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
| 1625 | while hasattr(students, sid): |
---|
| 1626 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
---|
[758] | 1627 | return sid |
---|
[714] | 1628 | #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000)) |
---|
| 1629 | ###) |
---|
| 1630 | |
---|
[361] | 1631 | InitializeClass(StudentsFolder) |
---|
| 1632 | |
---|
[1594] | 1633 | def addStudentsFolder(container, id, REQUEST=None, **kw): ###( |
---|
[361] | 1634 | """Add a Student.""" |
---|
| 1635 | ob = StudentsFolder(id, **kw) |
---|
| 1636 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[1594] | 1637 | ###) |
---|
| 1638 | |
---|
[361] | 1639 | ###) |
---|
| 1640 | |
---|
[57] | 1641 | class Student(CPSDocument): ###( |
---|
| 1642 | """ |
---|
[154] | 1643 | WAeUP Student container for the various student data |
---|
[57] | 1644 | """ |
---|
| 1645 | meta_type = 'Student' |
---|
| 1646 | portal_type = meta_type |
---|
| 1647 | security = ClassSecurityInfo() |
---|
[154] | 1648 | |
---|
[152] | 1649 | security.declareProtected(View,"Title") |
---|
| 1650 | def Title(self): |
---|
| 1651 | """compose title""" |
---|
[153] | 1652 | reg_nr = self.getId()[1:] |
---|
[362] | 1653 | data = getattr(self,'personal',None) |
---|
[152] | 1654 | if data: |
---|
| 1655 | content = data.getContent() |
---|
[1143] | 1656 | return "%s %s %s" % (content.firstname,content.middlename,content.lastname) |
---|
[472] | 1657 | data = getattr(self,'application',None) |
---|
[464] | 1658 | if data: |
---|
| 1659 | content = data.getContent() |
---|
| 1660 | return "%s" % (content.jamb_lastname) |
---|
[152] | 1661 | return self.title |
---|
[154] | 1662 | |
---|
[511] | 1663 | security.declarePrivate('makeStudentMember') ###( |
---|
| 1664 | def makeStudentMember(self,sid,password='uNsEt'): |
---|
| 1665 | """make the student a member""" |
---|
| 1666 | membership = self.portal_membership |
---|
[603] | 1667 | membership.addMember(sid, |
---|
[511] | 1668 | password , |
---|
| 1669 | roles=('Member', |
---|
| 1670 | 'Student', |
---|
[522] | 1671 | ), |
---|
[511] | 1672 | domains='', |
---|
[904] | 1673 | properties = {'memberareaCreationFlag': False, |
---|
| 1674 | 'homeless': True},) |
---|
[511] | 1675 | member = membership.getMemberById(sid) |
---|
| 1676 | self.portal_registration.afterAdd(member, sid, password, None) |
---|
| 1677 | self.manage_setLocalRoles(sid, ['Owner',]) |
---|
| 1678 | |
---|
| 1679 | ###) |
---|
| 1680 | |
---|
[764] | 1681 | security.declareProtected(View,'createSubObjects') ###( |
---|
| 1682 | def createSubObjects(self): |
---|
| 1683 | """make the student a member""" |
---|
| 1684 | dp = {'Title': 'Personal Data'} |
---|
| 1685 | app_doc = self.application.getContent() |
---|
| 1686 | names = app_doc.jamb_lastname.split() |
---|
| 1687 | if len(names) == 3: |
---|
| 1688 | dp['firstname'] = names[0].capitalize() |
---|
| 1689 | dp['middlename'] = names[1].capitalize() |
---|
| 1690 | dp['lastname'] = names[2].capitalize() |
---|
| 1691 | elif len(names) == 2: |
---|
| 1692 | dp['firstname'] = names[0].capitalize() |
---|
| 1693 | dp['lastname'] = names[1].capitalize() |
---|
| 1694 | else: |
---|
| 1695 | dp['lastname'] = app_doc.jamb_lastname |
---|
| 1696 | dp['sex'] = app_doc.jamb_sex == 'F' |
---|
| 1697 | dp['lga'] = "%s/%s" % (app_doc.jamb_state,app_doc.jamb_lga ) |
---|
| 1698 | proxy = self.aq_parent |
---|
| 1699 | proxy.invokeFactory('StudentPersonal','personal') |
---|
| 1700 | per = proxy.personal |
---|
| 1701 | per_doc = per.getContent() |
---|
| 1702 | per_doc.edit(mapping = dp) |
---|
[927] | 1703 | per.manage_setLocalRoles(proxy.getId(), ['Owner',]) |
---|
[764] | 1704 | #self.portal_workflow.doActionFor(per,'open',dest_container=per) |
---|
[603] | 1705 | |
---|
[511] | 1706 | ###) |
---|
| 1707 | |
---|
[57] | 1708 | InitializeClass(Student) |
---|
| 1709 | |
---|
| 1710 | def addStudent(container, id, REQUEST=None, **kw): |
---|
| 1711 | """Add a Student.""" |
---|
| 1712 | ob = Student(id, **kw) |
---|
| 1713 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1714 | |
---|
| 1715 | ###) |
---|
[91] | 1716 | |
---|
[639] | 1717 | class StudentAccommodation(CPSDocument): ###( |
---|
| 1718 | """ |
---|
| 1719 | WAeUP Student container for the various student data |
---|
| 1720 | """ |
---|
| 1721 | meta_type = 'StudentAccommodation' |
---|
| 1722 | portal_type = meta_type |
---|
| 1723 | security = ClassSecurityInfo() |
---|
| 1724 | |
---|
| 1725 | security.declareProtected(View,"Title") |
---|
| 1726 | def Title(self): |
---|
| 1727 | """compose title""" |
---|
| 1728 | content = self.getContent() |
---|
| 1729 | #return "Accommodation Data for %s %s" % (content.firstname,content.lastname) |
---|
| 1730 | return "Accommodation Data for Session %s" % content.session |
---|
| 1731 | |
---|
| 1732 | |
---|
| 1733 | InitializeClass(StudentAccommodation) |
---|
| 1734 | |
---|
| 1735 | def addStudentAccommodation(container, id, REQUEST=None, **kw): |
---|
| 1736 | """Add a Students personal data.""" |
---|
| 1737 | ob = StudentAccommodation(id, **kw) |
---|
| 1738 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1739 | |
---|
| 1740 | ###) |
---|
| 1741 | |
---|
[89] | 1742 | class StudentPersonal(CPSDocument): ###( |
---|
| 1743 | """ |
---|
[154] | 1744 | WAeUP Student container for the various student data |
---|
[89] | 1745 | """ |
---|
| 1746 | meta_type = 'StudentPersonal' |
---|
| 1747 | portal_type = meta_type |
---|
| 1748 | security = ClassSecurityInfo() |
---|
[152] | 1749 | |
---|
| 1750 | security.declareProtected(View,"Title") |
---|
| 1751 | def Title(self): |
---|
| 1752 | """compose title""" |
---|
| 1753 | content = self.getContent() |
---|
[364] | 1754 | #return "Personal Data for %s %s" % (content.firstname,content.lastname) |
---|
| 1755 | return "Personal Data" |
---|
[152] | 1756 | |
---|
[154] | 1757 | |
---|
[89] | 1758 | InitializeClass(StudentPersonal) |
---|
| 1759 | |
---|
| 1760 | def addStudentPersonal(container, id, REQUEST=None, **kw): |
---|
| 1761 | """Add a Students personal data.""" |
---|
| 1762 | ob = StudentPersonal(id, **kw) |
---|
| 1763 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1764 | |
---|
| 1765 | ###) |
---|
| 1766 | |
---|
[423] | 1767 | class StudentClearance(CPSDocument): ###( |
---|
| 1768 | """ |
---|
| 1769 | WAeUP Student container for the various student data |
---|
| 1770 | """ |
---|
| 1771 | meta_type = 'StudentClearance' |
---|
| 1772 | portal_type = meta_type |
---|
| 1773 | security = ClassSecurityInfo() |
---|
| 1774 | |
---|
| 1775 | security.declareProtected(View,"Title") |
---|
| 1776 | def Title(self): |
---|
| 1777 | """compose title""" |
---|
| 1778 | content = self.getContent() |
---|
[840] | 1779 | #return "Clearance/Eligibility Record for %s %s" % (content.firstname,content.lastname) |
---|
| 1780 | return "Clearance/Eligibility Record" |
---|
[423] | 1781 | |
---|
| 1782 | |
---|
| 1783 | InitializeClass(StudentClearance) |
---|
| 1784 | |
---|
| 1785 | def addStudentClearance(container, id, REQUEST=None, **kw): |
---|
| 1786 | """Add a Students personal data.""" |
---|
| 1787 | ob = StudentClearance(id, **kw) |
---|
| 1788 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1789 | |
---|
| 1790 | ###) |
---|
| 1791 | |
---|
[454] | 1792 | class StudentStudyLevel(CPSDocument): ###( |
---|
| 1793 | """ |
---|
| 1794 | WAeUP Student container for the various student data |
---|
| 1795 | """ |
---|
| 1796 | meta_type = 'StudentStudyLevel' |
---|
| 1797 | portal_type = meta_type |
---|
| 1798 | security = ClassSecurityInfo() |
---|
| 1799 | |
---|
| 1800 | security.declareProtected(View,"Title") |
---|
| 1801 | def Title(self): |
---|
| 1802 | """compose title""" |
---|
| 1803 | return "Level %s" % self.aq_parent.getId() |
---|
| 1804 | |
---|
[1700] | 1805 | def create_course_results(self,cert_id,current_level): ###( |
---|
[1649] | 1806 | "create all courses in a level" |
---|
| 1807 | aq_portal = self.portal_catalog.evalAdvancedQuery |
---|
| 1808 | res = self.portal_catalog(portal_type="Certificate", id = cert_id) |
---|
| 1809 | l = [] |
---|
| 1810 | import transaction |
---|
| 1811 | if res: |
---|
| 1812 | cert = res[0] |
---|
| 1813 | path = cert.getPath() |
---|
| 1814 | query = Eq("path","%s/%s" % (path,current_level)) &\ |
---|
| 1815 | Eq('portal_type','CertificateCourse') |
---|
| 1816 | courses = aq_portal(query) |
---|
| 1817 | #from pdb import set_trace;set_trace() |
---|
| 1818 | self_proxy = self.aq_parent |
---|
| 1819 | for c in courses: |
---|
| 1820 | d = self.getCourseInfo(c.getId) |
---|
| 1821 | cr_id = self_proxy.invokeFactory('StudentCourseResult',c.getId) |
---|
| 1822 | course_result = getattr(self_proxy,cr_id) |
---|
| 1823 | self.portal_workflow.doActionFor(course_result,'open') |
---|
| 1824 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
---|
| 1825 | course_result.getContent().edit(mapping=d) |
---|
| 1826 | transaction.commit() |
---|
[1700] | 1827 | ###) |
---|
[472] | 1828 | |
---|
[454] | 1829 | InitializeClass(StudentStudyLevel) |
---|
| 1830 | |
---|
| 1831 | def addStudentStudyLevel(container, id, REQUEST=None, **kw): |
---|
| 1832 | """Add a Students personal data.""" |
---|
| 1833 | ob = StudentStudyLevel(id, **kw) |
---|
| 1834 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1835 | |
---|
| 1836 | ###) |
---|
| 1837 | |
---|
[362] | 1838 | class StudentStudyCourse(CPSDocument): ###( |
---|
| 1839 | """ |
---|
| 1840 | WAeUP Student container for the various student data |
---|
| 1841 | """ |
---|
| 1842 | meta_type = 'StudentStudyCourse' |
---|
| 1843 | portal_type = meta_type |
---|
| 1844 | security = ClassSecurityInfo() |
---|
| 1845 | |
---|
[364] | 1846 | security.declareProtected(View,"Title") |
---|
| 1847 | def Title(self): |
---|
| 1848 | """compose title""" |
---|
| 1849 | content = self.getContent() |
---|
[453] | 1850 | return "Study Course" |
---|
[362] | 1851 | |
---|
| 1852 | |
---|
| 1853 | InitializeClass(StudentStudyCourse) |
---|
| 1854 | |
---|
| 1855 | def addStudentStudyCourse(container, id, REQUEST=None, **kw): |
---|
| 1856 | """Add a Students personal data.""" |
---|
| 1857 | ob = StudentStudyCourse(id, **kw) |
---|
| 1858 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1859 | |
---|
| 1860 | ###) |
---|
| 1861 | |
---|
[472] | 1862 | class StudentApplication(CPSDocument): ###( |
---|
[179] | 1863 | """ |
---|
| 1864 | WAeUP Student container for the various student data |
---|
| 1865 | """ |
---|
[472] | 1866 | meta_type = 'StudentApplication' |
---|
[179] | 1867 | portal_type = meta_type |
---|
| 1868 | security = ClassSecurityInfo() |
---|
| 1869 | |
---|
[181] | 1870 | security.declareProtected(View,"Title") |
---|
| 1871 | def Title(self): |
---|
| 1872 | """compose title""" |
---|
[472] | 1873 | return "Application Data" |
---|
[179] | 1874 | |
---|
[181] | 1875 | |
---|
[472] | 1876 | InitializeClass(StudentApplication) |
---|
[179] | 1877 | |
---|
[472] | 1878 | def addStudentApplication(container, id, REQUEST=None, **kw): |
---|
[179] | 1879 | """Add a Students eligibility data.""" |
---|
[472] | 1880 | ob = StudentApplication(id, **kw) |
---|
[179] | 1881 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[763] | 1882 | ###) |
---|
[179] | 1883 | |
---|
[758] | 1884 | class StudentPume(CPSDocument): ###( |
---|
| 1885 | """ |
---|
| 1886 | WAeUP Student container for the various student data |
---|
| 1887 | """ |
---|
| 1888 | meta_type = 'StudentPume' |
---|
| 1889 | portal_type = meta_type |
---|
| 1890 | security = ClassSecurityInfo() |
---|
| 1891 | |
---|
| 1892 | security.declareProtected(View,"Title") |
---|
| 1893 | def Title(self): |
---|
| 1894 | """compose title""" |
---|
| 1895 | return "PUME Results" |
---|
| 1896 | |
---|
| 1897 | |
---|
| 1898 | InitializeClass(StudentPume) |
---|
| 1899 | |
---|
| 1900 | def addStudentPume(container, id, REQUEST=None, **kw): |
---|
| 1901 | """Add a Students PUME data.""" |
---|
| 1902 | ob = StudentPume(id, **kw) |
---|
| 1903 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[179] | 1904 | ###) |
---|
[181] | 1905 | |
---|
[565] | 1906 | ##class StudentSemester(CPSDocument): ###( |
---|
| 1907 | ## """ |
---|
| 1908 | ## WAeUP StudentSemester containing the courses and students |
---|
| 1909 | ## """ |
---|
| 1910 | ## meta_type = 'StudentSemester' |
---|
| 1911 | ## portal_type = meta_type |
---|
| 1912 | ## security = ClassSecurityInfo() |
---|
| 1913 | ## |
---|
| 1914 | ##InitializeClass(StudentSemester) |
---|
| 1915 | ## |
---|
| 1916 | ##def addStudentSemester(container, id, REQUEST=None, **kw): |
---|
| 1917 | ## """Add a StudentSemester.""" |
---|
| 1918 | ## ob = StudentSemester(id, **kw) |
---|
| 1919 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1920 | ## |
---|
| 1921 | #####) |
---|
[464] | 1922 | |
---|
[758] | 1923 | ##class Semester(CPSDocument): ###( |
---|
| 1924 | ## """ |
---|
| 1925 | ## WAeUP Semester containing the courses and students |
---|
| 1926 | ## """ |
---|
| 1927 | ## meta_type = 'Semester' |
---|
| 1928 | ## portal_type = meta_type |
---|
| 1929 | ## security = ClassSecurityInfo() |
---|
| 1930 | ## |
---|
| 1931 | ##InitializeClass(Semester) |
---|
| 1932 | ## |
---|
| 1933 | ##def addSemester(container, id, REQUEST=None, **kw): |
---|
| 1934 | ## """Add a Semester.""" |
---|
| 1935 | ## ob = Semester(id, **kw) |
---|
| 1936 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 1937 | ## |
---|
| 1938 | #####) |
---|
[464] | 1939 | |
---|
| 1940 | class StudentCourseResult(CPSDocument): ###( |
---|
[89] | 1941 | """ |
---|
[464] | 1942 | WAeUP StudentCourseResult |
---|
[89] | 1943 | """ |
---|
[464] | 1944 | meta_type = 'StudentCourseResult' |
---|
[89] | 1945 | portal_type = meta_type |
---|
| 1946 | security = ClassSecurityInfo() |
---|
[472] | 1947 | |
---|
[454] | 1948 | def getCourseEntry(self,cid): |
---|
[723] | 1949 | res = self.portal_catalog({'meta_type': "Course", |
---|
[454] | 1950 | 'id': cid}) |
---|
| 1951 | if res: |
---|
| 1952 | return res[-1] |
---|
| 1953 | else: |
---|
| 1954 | return None |
---|
[154] | 1955 | |
---|
[454] | 1956 | security.declareProtected(View,"Title") |
---|
| 1957 | def Title(self): |
---|
| 1958 | """compose title""" |
---|
[723] | 1959 | cid = self.aq_parent.getId() |
---|
[454] | 1960 | ce = self.getCourseEntry(cid) |
---|
| 1961 | if ce: |
---|
| 1962 | return "%s" % ce.Title |
---|
| 1963 | return "No course with id %s" % cid |
---|
[152] | 1964 | |
---|
[464] | 1965 | InitializeClass(StudentCourseResult) |
---|
[454] | 1966 | |
---|
[464] | 1967 | def addStudentCourseResult(container, id, REQUEST=None, **kw): |
---|
| 1968 | """Add a StudentCourseResult.""" |
---|
| 1969 | ob = StudentCourseResult(id, **kw) |
---|
[89] | 1970 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
[139] | 1971 | ###) |
---|
| 1972 | |
---|
[579] | 1973 | # Backward Compatibility StudyLevel |
---|
| 1974 | |
---|
| 1975 | from Products.WAeUP_SRP.Academics import StudyLevel |
---|
| 1976 | |
---|
| 1977 | from Products.WAeUP_SRP.Academics import addStudyLevel |
---|
| 1978 | |
---|