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