| 1 | #-*- mode: python; mode: fold -*- |
|---|
| 2 | # $Id: Students.py 1775 2007-05-12 06:38:37Z henrik $ |
|---|
| 3 | from string import Template |
|---|
| 4 | from Globals import InitializeClass |
|---|
| 5 | from AccessControl import ClassSecurityInfo |
|---|
| 6 | from AccessControl.SecurityManagement import newSecurityManager |
|---|
| 7 | from zExceptions import BadRequest |
|---|
| 8 | from Products.ZCatalog.ZCatalog import ZCatalog |
|---|
| 9 | from Products.CMFCore.utils import UniqueObject, getToolByName |
|---|
| 10 | from Products.CMFCore.permissions import View |
|---|
| 11 | from Products.CMFCore.permissions import ModifyPortalContent |
|---|
| 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 |
|---|
| 16 | from Products.CPSCore.CPSMembershipTool import CPSUnrestrictedUser |
|---|
| 17 | from Products.WAeUP_SRP.Academics import makeCertificateCode |
|---|
| 18 | from Products.AdvancedQuery import Eq, Between, Le,In |
|---|
| 19 | import logging |
|---|
| 20 | import csv,re,os |
|---|
| 21 | import Globals |
|---|
| 22 | p_home = Globals.package_home(globals()) |
|---|
| 23 | i_home = Globals.INSTANCE_HOME |
|---|
| 24 | MAX_TRANS = 1000 |
|---|
| 25 | from urllib import urlencode |
|---|
| 26 | |
|---|
| 27 | import DateTime |
|---|
| 28 | import PIL.Image |
|---|
| 29 | from StringIO import StringIO |
|---|
| 30 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 51 | def getInt(s): ###( |
|---|
| 52 | try: |
|---|
| 53 | return int(s) |
|---|
| 54 | except: |
|---|
| 55 | return 0 |
|---|
| 56 | |
|---|
| 57 | def getFloat(s): |
|---|
| 58 | try: |
|---|
| 59 | return float(s) |
|---|
| 60 | except: |
|---|
| 61 | return 0.0 |
|---|
| 62 | |
|---|
| 63 | ###) |
|---|
| 64 | |
|---|
| 65 | def getStudentByRegNo(self,reg_no): ###( |
|---|
| 66 | """search student by JAMB Reg No and return StudentFolder""" |
|---|
| 67 | search = ZCatalog.searchResults(self.portal_catalog,{'meta_type': 'StudentApplication', |
|---|
| 68 | 'SearchableText': reg_no, |
|---|
| 69 | }) |
|---|
| 70 | if len(search) < 1: |
|---|
| 71 | return None |
|---|
| 72 | return search[0].getObject().aq_parent |
|---|
| 73 | |
|---|
| 74 | ###) |
|---|
| 75 | |
|---|
| 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 |
|---|
| 87 | |
|---|
| 88 | class StudentsFolder(CPSDocument): ###( |
|---|
| 89 | """ |
|---|
| 90 | WAeUP container for the various WAeUP containers data |
|---|
| 91 | """ |
|---|
| 92 | meta_type = 'StudentsFolder' |
|---|
| 93 | portal_type = meta_type |
|---|
| 94 | security = ClassSecurityInfo() |
|---|
| 95 | |
|---|
| 96 | security.declareProtected(ModifyPortalContent,"createStudents")###( |
|---|
| 97 | def createStudents(self): |
|---|
| 98 | """load 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 | #entry_levels = {'ume_ft':'100', |
|---|
| 105 | # 'de_ft': '200', |
|---|
| 106 | # 'ug_pt': '100', |
|---|
| 107 | # 'de_pt': '200', |
|---|
| 108 | # 'pg_ft': '700', |
|---|
| 109 | # 'pg_pt': '700', |
|---|
| 110 | # 'dp_pt': '100', |
|---|
| 111 | # 'dp_ft': '100', |
|---|
| 112 | # } |
|---|
| 113 | csv_d = {'jamb_reg_no': "reg_no", |
|---|
| 114 | 'entry_mode': 'entry_mode', |
|---|
| 115 | 'jamb_firstname': "firstname", |
|---|
| 116 | 'jamb_middlename': "middlename", |
|---|
| 117 | 'jamb_lastname': "lastname", |
|---|
| 118 | 'jamb_sex': "sex", |
|---|
| 119 | 'jamb_state': "state", |
|---|
| 120 | 'birthday': "date_of_birth", |
|---|
| 121 | 'app_email': "email", |
|---|
| 122 | 'study_course': "study_course", |
|---|
| 123 | 'perm_address': "address", |
|---|
| 124 | } |
|---|
| 125 | csv_fields = [f[1] for f in csv_d.items()] |
|---|
| 126 | tr_count = 0 |
|---|
| 127 | total = 0 |
|---|
| 128 | #name = 'pume_results' |
|---|
| 129 | name = 'Admitted' |
|---|
| 130 | no_import = [] |
|---|
| 131 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
|---|
| 132 | no_import.append('"Error",%s' % s) |
|---|
| 133 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
|---|
| 134 | no_certificate = "no certificate %s" % format |
|---|
| 135 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import)) |
|---|
| 136 | logger = logging.getLogger('Students.StudentsFolder.createStudents') |
|---|
| 137 | logger.info('Start loading from %s.csv' % name) |
|---|
| 138 | certs = {} |
|---|
| 139 | try: |
|---|
| 140 | results = 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 result in results: |
|---|
| 145 | #result['Error'] = "Processing " |
|---|
| 146 | #logger.info(format % result) |
|---|
| 147 | jamb_reg_no = result.get(csv_d['jamb_reg_no']) |
|---|
| 148 | res = self.students_catalog(jamb_reg_no = jamb_reg_no) |
|---|
| 149 | if res: |
|---|
| 150 | em = 'Student with RegNo %s already exists\n' % jamb_reg_no |
|---|
| 151 | logger.info(em) |
|---|
| 152 | result['Error'] = "Student exists" |
|---|
| 153 | no_import.append(format % result) |
|---|
| 154 | continue |
|---|
| 155 | cert_id = makeCertificateCode(result.get(csv_d['study_course'])) |
|---|
| 156 | if cert_id not in certs.keys(): |
|---|
| 157 | res = self.portal_catalog(meta_type = "Certificate",id = cert_id) |
|---|
| 158 | if not res: |
|---|
| 159 | em = 'No Certificate with ID %s \n' % cert_id |
|---|
| 160 | logger.info(em) |
|---|
| 161 | result['Error'] = "No Certificate %s" % cert_id |
|---|
| 162 | no_import.append( format % result) |
|---|
| 163 | continue |
|---|
| 164 | cert = res[0] |
|---|
| 165 | cert_path = cert.getPath().split('/') |
|---|
| 166 | certificate = certs[cert_id] = {'faculty': cert_path[-4], |
|---|
| 167 | 'department': cert_path[-3]} |
|---|
| 168 | cert_doc = certs[cert_id] |
|---|
| 169 | catalog_entry = {} |
|---|
| 170 | catalog_entry['jamb_reg_no'] = jamb_reg_no |
|---|
| 171 | firstname = result.get(csv_d['jamb_firstname']) |
|---|
| 172 | middlename = result.get(csv_d['jamb_middlename']) |
|---|
| 173 | lastname = result.get(csv_d['jamb_lastname']) |
|---|
| 174 | sid = self.generateStudentId('x') |
|---|
| 175 | students_folder.invokeFactory('Student', sid) |
|---|
| 176 | catalog_entry['id'] = sid |
|---|
| 177 | tr_count += 1 |
|---|
| 178 | logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s reg_no %(jamb_reg_no)s ' % vars()) |
|---|
| 179 | student = getattr(self,sid) |
|---|
| 180 | student.manage_setLocalRoles(sid, ['Owner',]) |
|---|
| 181 | student.invokeFactory('StudentApplication','application') |
|---|
| 182 | da = {'Title': 'Application Data'} |
|---|
| 183 | da["jamb_firstname"] = firstname |
|---|
| 184 | da["jamb_middlename"] = middlename |
|---|
| 185 | da["jamb_lastname"] = lastname |
|---|
| 186 | catalog_entry['entry_session'] = da["entry_session"] = self.getSessionId()[-2:] |
|---|
| 187 | catalog_entry['sex'] = sex = result.get(csv_d['jamb_sex']).startswith('F') |
|---|
| 188 | da_fields = ('jamb_reg_no', |
|---|
| 189 | 'jamb_sex', |
|---|
| 190 | 'jamb_state', |
|---|
| 191 | 'entry_mode', |
|---|
| 192 | 'app_email', |
|---|
| 193 | ) |
|---|
| 194 | for f in da_fields: |
|---|
| 195 | da[f] = result.get(csv_d[f]) |
|---|
| 196 | catalog_entry['email'] = da['app_email'] |
|---|
| 197 | catalog_entry['entry_mode'] = da['entry_mode'] |
|---|
| 198 | #catalog_entry['entry_level'] = da["entry_level"] = entry_levels.get(da['entry_mode'],'100') |
|---|
| 199 | app = student.application |
|---|
| 200 | app_doc = app.getContent() |
|---|
| 201 | app.getContent().edit(mapping=da) |
|---|
| 202 | picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no) |
|---|
| 203 | app.manage_setLocalRoles(sid, ['Owner',]) |
|---|
| 204 | |
|---|
| 205 | picture_id = da['jamb_reg_no'].replace('/','_') |
|---|
| 206 | file = None |
|---|
| 207 | for ext in ('jpg','JPG'): |
|---|
| 208 | picture ="%s/import/pictures_admitted_latest/%s.%s" % (i_home,picture_id,ext) |
|---|
| 209 | if os.path.exists(picture): |
|---|
| 210 | file = open(picture) |
|---|
| 211 | break |
|---|
| 212 | if file is not None: |
|---|
| 213 | |
|---|
| 214 | ## file conversion does not work |
|---|
| 215 | #img = PIL.Image.open(file) |
|---|
| 216 | #img.thumbnail((150,200), |
|---|
| 217 | # resample=PIL.Image.ANTIALIAS) |
|---|
| 218 | #outfile = StringIO() |
|---|
| 219 | #img.save(outfile, format=img.format) |
|---|
| 220 | |
|---|
| 221 | outfile = file.read() |
|---|
| 222 | app_doc.manage_addFile('passport', |
|---|
| 223 | file=outfile, |
|---|
| 224 | title="%s.jpg" % jamb_reg_no) |
|---|
| 225 | #wftool.doActionFor(app,'close') |
|---|
| 226 | dp = {} |
|---|
| 227 | dp['firstname'] = firstname |
|---|
| 228 | dp['middlename'] = middlename |
|---|
| 229 | dp['lastname'] = lastname |
|---|
| 230 | dp['email'] = da['app_email'] |
|---|
| 231 | dp['sex'] = sex |
|---|
| 232 | catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp |
|---|
| 233 | student.invokeFactory('StudentPersonal','personal') |
|---|
| 234 | per = student.personal |
|---|
| 235 | per_doc = per.getContent() |
|---|
| 236 | per_doc.edit(mapping = dp) |
|---|
| 237 | per.manage_setLocalRoles(sid, ['Owner',]) |
|---|
| 238 | wftool.doActionFor(student,'pume_pass') |
|---|
| 239 | wftool.doActionFor(student,'admit') |
|---|
| 240 | # |
|---|
| 241 | # Clearance |
|---|
| 242 | # |
|---|
| 243 | student.invokeFactory('StudentClearance','clearance') |
|---|
| 244 | #wftool.doActionFor(student.clearance,'open') |
|---|
| 245 | clearance = student.clearance |
|---|
| 246 | dc = {'Title': 'Clearance/Eligibility Record'} |
|---|
| 247 | clearance = student.clearance |
|---|
| 248 | date_str = result.get(csv_d['birthday']) |
|---|
| 249 | try: |
|---|
| 250 | date = DateTime.DateTime(date_str) |
|---|
| 251 | except: |
|---|
| 252 | #import pdb;pdb.set_trace() |
|---|
| 253 | date = None |
|---|
| 254 | dc['birthday'] = date |
|---|
| 255 | clearance.getContent().edit(mapping=dc) |
|---|
| 256 | clearance.manage_setLocalRoles(sid, ['Owner',]) |
|---|
| 257 | # |
|---|
| 258 | # Study Course |
|---|
| 259 | # |
|---|
| 260 | student.invokeFactory('StudentStudyCourse','study_course') |
|---|
| 261 | study_course = student.study_course |
|---|
| 262 | dsc = {} |
|---|
| 263 | #catalog_entry['level'] = getattr(cert_doc,'start_level') |
|---|
| 264 | catalog_entry['session'] = dsc['current_session'] = da['entry_session'] |
|---|
| 265 | #catalog_entry['level'] = dsc['current_level'] = entry_levels.get(da['entry_mode'],'100') |
|---|
| 266 | catalog_entry['mode'] = dsc['current_mode'] = da['entry_mode'] |
|---|
| 267 | catalog_entry['course'] = dsc['study_course'] = cert_id |
|---|
| 268 | catalog_entry['faculty'] = certificate['faculty'] |
|---|
| 269 | catalog_entry['department'] = certificate['department'] |
|---|
| 270 | catalog_entry['verdict'] = dsc['current_verdict'] = 'N/A' |
|---|
| 271 | catalog_entry['review_state'] = self.portal_workflow.getInfoFor(student,'review_state',None) |
|---|
| 272 | study_course.getContent().edit(mapping=dsc) |
|---|
| 273 | #import pdb;pdb.set_trace() |
|---|
| 274 | self.students_catalog.addRecord(**catalog_entry) |
|---|
| 275 | if tr_count > 10: |
|---|
| 276 | if len(no_import) > 0: |
|---|
| 277 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
|---|
| 278 | '\n'.join(no_import) + "\n") |
|---|
| 279 | no_import = [] |
|---|
| 280 | em = '%d transactions commited\n' % tr_count |
|---|
| 281 | transaction.commit() |
|---|
| 282 | logger.info(em) |
|---|
| 283 | total += tr_count |
|---|
| 284 | tr_count = 0 |
|---|
| 285 | open("%s/import/%s_not_imported.csv" % (i_home,name),"a").write( |
|---|
| 286 | '\n'.join(no_import)) |
|---|
| 287 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
|---|
| 288 | ###) |
|---|
| 289 | |
|---|
| 290 | security.declareProtected(ModifyPortalContent,"importReturningStudents")###( |
|---|
| 291 | def importReturningStudents(self): |
|---|
| 292 | """load Returning Studentdata from CSV values""" |
|---|
| 293 | import transaction |
|---|
| 294 | import random |
|---|
| 295 | #from pdb import set_trace |
|---|
| 296 | wftool = self.portal_workflow |
|---|
| 297 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
|---|
| 298 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
|---|
| 299 | #students_folder = self.portal_url().getPortalObject().campus.students |
|---|
| 300 | tr_count = 1 |
|---|
| 301 | total = 0 |
|---|
| 302 | #name = 'pume_results' |
|---|
| 303 | name = 'Returning' |
|---|
| 304 | table = self.returning_import |
|---|
| 305 | no_import = [] |
|---|
| 306 | imported = [] |
|---|
| 307 | logger = logging.getLogger('Students.StudentsFolder.importReturningStudents') |
|---|
| 308 | try: |
|---|
| 309 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
|---|
| 310 | except: |
|---|
| 311 | logger.error('Error reading %s.csv' % name) |
|---|
| 312 | return |
|---|
| 313 | l = self.portal_catalog({'meta_type': "Certificate"}) |
|---|
| 314 | certs = {} |
|---|
| 315 | cert_docs = {} |
|---|
| 316 | for f in l: |
|---|
| 317 | certs[f.getId] = f.getObject().getContent() |
|---|
| 318 | start = True |
|---|
| 319 | res = table() |
|---|
| 320 | regs = [] |
|---|
| 321 | if len(res) > 0: |
|---|
| 322 | regs = [s.matric_no for s in res] |
|---|
| 323 | #import pdb;pdb.set_trace() |
|---|
| 324 | for student in returning: |
|---|
| 325 | if start: |
|---|
| 326 | start = False |
|---|
| 327 | logger.info('Start loading from %s.csv' % name) |
|---|
| 328 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
|---|
| 329 | imported.append(s) |
|---|
| 330 | no_import.append('%s,"Error"' % s) |
|---|
| 331 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
|---|
| 332 | format_error = format + ',"%(Error)s"' |
|---|
| 333 | no_certificate = "no certificate %s" % format |
|---|
| 334 | student['matric_no'] = matric_no = student.get('matric_no').upper() |
|---|
| 335 | student['Mode_of_Entry'] = entry_mode = student.get('Mode of Entry').upper() |
|---|
| 336 | student['Permanent_Address'] = perm_address = student.get('Permanent Address') |
|---|
| 337 | if matric_no == '': |
|---|
| 338 | student['Error'] = "Empty matric_no" |
|---|
| 339 | no_import.append( format_error % student) |
|---|
| 340 | continue |
|---|
| 341 | if matric_no in regs or self.returning_import(matric_no = matric_no): |
|---|
| 342 | student['Error'] = "Duplicate" |
|---|
| 343 | no_import.append( format_error % student) |
|---|
| 344 | continue |
|---|
| 345 | cert_id = makeCertificateCode(student.get('Coursemajorcode')) |
|---|
| 346 | if cert_id not in certs.keys(): |
|---|
| 347 | student['Error'] = "No Certificate %s" % cert_id |
|---|
| 348 | no_import.append( format_error % student) |
|---|
| 349 | continue |
|---|
| 350 | try: |
|---|
| 351 | table.addRecord(**student) |
|---|
| 352 | except ValueError: |
|---|
| 353 | student['Error'] = "Duplicate" |
|---|
| 354 | no_import.append( format_error % student) |
|---|
| 355 | continue |
|---|
| 356 | regs.append(student.get('matric_no')) |
|---|
| 357 | imported.append(format % student) |
|---|
| 358 | tr_count += 1 |
|---|
| 359 | if tr_count > 1000: |
|---|
| 360 | if len(no_import) > 0: |
|---|
| 361 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 362 | '\n'.join(no_import) + '\n') |
|---|
| 363 | no_import = [] |
|---|
| 364 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 365 | '\n'.join(no_import) + "\n") |
|---|
| 366 | imported = [] |
|---|
| 367 | em = '%d transactions commited total %s\n' % (tr_count,total) |
|---|
| 368 | transaction.commit() |
|---|
| 369 | regs = [] |
|---|
| 370 | logger.info(em) |
|---|
| 371 | total += tr_count |
|---|
| 372 | tr_count = 0 |
|---|
| 373 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 374 | '\n'.join(imported)) |
|---|
| 375 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 376 | '\n'.join(no_import)) |
|---|
| 377 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
|---|
| 378 | ###) |
|---|
| 379 | |
|---|
| 380 | security.declareProtected(ModifyPortalContent,"fixVerdicts")###( |
|---|
| 381 | def fixVerdicts(self,csv_file=None): |
|---|
| 382 | """fix wrong uploaded verdicts""" |
|---|
| 383 | import transaction |
|---|
| 384 | import random |
|---|
| 385 | wftool = self.portal_workflow |
|---|
| 386 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
|---|
| 387 | students_folder = self.portal_url.getPortalObject().campus.students |
|---|
| 388 | tr_count = 1 |
|---|
| 389 | total = 0 |
|---|
| 390 | if csv_file is None: |
|---|
| 391 | name = 'Verdicts' |
|---|
| 392 | else: |
|---|
| 393 | name = csv_file |
|---|
| 394 | st_cat = self.students_catalog |
|---|
| 395 | no_import = [] |
|---|
| 396 | verdicts_voc = self.portal_vocabularies.verdicts |
|---|
| 397 | rverdicts = {} |
|---|
| 398 | for k,v in verdicts_voc.items(): |
|---|
| 399 | rverdicts[v.upper()] = k |
|---|
| 400 | rverdicts['STUDENT ON PROBATION'] = 'C' |
|---|
| 401 | logger = logging.getLogger('Students.StudentsFolder.fixVerdicts') |
|---|
| 402 | try: |
|---|
| 403 | verdicts = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
|---|
| 404 | except: |
|---|
| 405 | logger.error('Error reading %s.csv' % name) |
|---|
| 406 | return |
|---|
| 407 | start = True |
|---|
| 408 | #import pdb;pdb.set_trace() |
|---|
| 409 | for verdict in verdicts: |
|---|
| 410 | if start: |
|---|
| 411 | start = False |
|---|
| 412 | logger.info('Start loading from %s.csv' % name) |
|---|
| 413 | s = ','.join(['"%s"' % fn for fn in verdict.keys()]) |
|---|
| 414 | no_import.append('%s,"Error"' % s) |
|---|
| 415 | format = ','.join(['"%%(%s)s"' % fn for fn in verdict.keys()]) |
|---|
| 416 | format_error = format + ',"%(Error)s"' |
|---|
| 417 | matric_no = verdict.get('MAT NO') |
|---|
| 418 | if not matric_no: |
|---|
| 419 | continue |
|---|
| 420 | matric_no = matric_no.upper() |
|---|
| 421 | if matric_no == '': |
|---|
| 422 | continue |
|---|
| 423 | verdict_code = rverdicts.get(verdict.get('CATEGORY'),None) |
|---|
| 424 | if verdict_code is None: |
|---|
| 425 | continue |
|---|
| 426 | sres = st_cat(matric_no = matric_no) |
|---|
| 427 | if sres: |
|---|
| 428 | student_id = sres[0].id |
|---|
| 429 | student_obj = getattr(students_folder,student_id,None) |
|---|
| 430 | if student_obj: |
|---|
| 431 | study_course = getattr(student_obj,'study_course',None) |
|---|
| 432 | if study_course is None: |
|---|
| 433 | verdict['Error'] = "Student did not yet log in" |
|---|
| 434 | no_import.append( format_error % verdict) |
|---|
| 435 | continue |
|---|
| 436 | st_cat.modifyRecord(id = student_id, |
|---|
| 437 | verdict=verdict_code) |
|---|
| 438 | |
|---|
| 439 | dsc = {} |
|---|
| 440 | dsc['current_verdict'] = verdict_code |
|---|
| 441 | study_course.getContent().edit(mapping=dsc) |
|---|
| 442 | else: |
|---|
| 443 | verdict['Error'] = "Not found in students_catalog" |
|---|
| 444 | no_import.append( format_error % verdict) |
|---|
| 445 | continue |
|---|
| 446 | tr_count += 1 |
|---|
| 447 | if tr_count > 1000: |
|---|
| 448 | if len(no_import) > 0: |
|---|
| 449 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 450 | '\n'.join(no_import) + '\n') |
|---|
| 451 | no_import = [] |
|---|
| 452 | em = '%d transactions commited total %s\n' % (tr_count,total) |
|---|
| 453 | transaction.commit() |
|---|
| 454 | regs = [] |
|---|
| 455 | logger.info(em) |
|---|
| 456 | total += tr_count |
|---|
| 457 | tr_count = 0 |
|---|
| 458 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 459 | '\n'.join(no_import)) |
|---|
| 460 | total += tr_count |
|---|
| 461 | em = '%d total transactions commited' % (total) |
|---|
| 462 | logger.info(em) |
|---|
| 463 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
|---|
| 464 | ###) |
|---|
| 465 | |
|---|
| 466 | security.declareProtected(ModifyPortalContent,"fixAllNames")###( |
|---|
| 467 | def fixAllNames(self): |
|---|
| 468 | "fix all students names" |
|---|
| 469 | import transaction |
|---|
| 470 | response = self.REQUEST.RESPONSE |
|---|
| 471 | logger = logging.getLogger('fixAllNames') |
|---|
| 472 | logger.info('Start') |
|---|
| 473 | students = self.portal_catalog(portal_type='Student') |
|---|
| 474 | count = 0 |
|---|
| 475 | total = 0 |
|---|
| 476 | for student in students: |
|---|
| 477 | scat_res = self.students_catalog(id = student.getId) |
|---|
| 478 | if not scat_res: |
|---|
| 479 | self.students_catalog.addRecord(id = student.getId) |
|---|
| 480 | scat_res = self.students_catalog(id = student.getId) |
|---|
| 481 | student_entry = scat_res[0] |
|---|
| 482 | old_new = self.fixName(student,student_entry) |
|---|
| 483 | count += 1 |
|---|
| 484 | response_write(response,'"%d","%s",%s' % (count + total,student_entry.id,old_new)) |
|---|
| 485 | if count > 2000: |
|---|
| 486 | transaction.commit() |
|---|
| 487 | logger.info("%d transactions commited" % count) |
|---|
| 488 | total += count |
|---|
| 489 | count = 0 |
|---|
| 490 | ###) |
|---|
| 491 | |
|---|
| 492 | security.declareProtected(ModifyPortalContent,"fixName")###( |
|---|
| 493 | def fixName(self,student_brain, student_entry): |
|---|
| 494 | "fix the name of a student" |
|---|
| 495 | fix = "first" |
|---|
| 496 | if student_entry.get('name_fixed',None) == fix: |
|---|
| 497 | return "Name already fixed" |
|---|
| 498 | student_id = student_entry.id |
|---|
| 499 | new_student = student_entry.jamb_reg_no.startswith('6') |
|---|
| 500 | student_obj = student_brain.getObject() |
|---|
| 501 | personal = getattr(student_obj,'personal',None) |
|---|
| 502 | invalid = '' |
|---|
| 503 | if personal is None: |
|---|
| 504 | return '"%s","Returning","%s","%s"' % (invalid,student_entry.name,"not logged in") |
|---|
| 505 | per_doc = personal.getContent() |
|---|
| 506 | old_first = per_doc.firstname |
|---|
| 507 | old_middle = per_doc.middlename |
|---|
| 508 | old_last = per_doc.lastname |
|---|
| 509 | new_first = '' |
|---|
| 510 | new_middle = '' |
|---|
| 511 | new_last = '' |
|---|
| 512 | if new_student: |
|---|
| 513 | if not old_first and not old_middle and old_last: |
|---|
| 514 | new_names = [n.capitalize() for n in old_last.split()] |
|---|
| 515 | if len(new_names) > 1: |
|---|
| 516 | old_first = new_names[0] |
|---|
| 517 | old_last = new_names[-1] |
|---|
| 518 | old_middle = ' '.join(new_names[1:-1]) |
|---|
| 519 | else: |
|---|
| 520 | old_last = new_names[0] |
|---|
| 521 | old_first = '' |
|---|
| 522 | old_middle = '' |
|---|
| 523 | if old_first: |
|---|
| 524 | new_first = old_first |
|---|
| 525 | if old_middle: |
|---|
| 526 | new_middle = old_middle |
|---|
| 527 | if old_last: |
|---|
| 528 | new_last = old_last |
|---|
| 529 | if old_first.find('<') != -1 or\ |
|---|
| 530 | old_first.find('>') != -1 or\ |
|---|
| 531 | old_middle.find('<') != -1 or\ |
|---|
| 532 | old_middle.find('>') != -1 or\ |
|---|
| 533 | old_last.find('<') != -1 or\ |
|---|
| 534 | old_last.find('>') != -1: |
|---|
| 535 | invalid = "invalid characters" |
|---|
| 536 | else: |
|---|
| 537 | new_first = old_first |
|---|
| 538 | if new_first.strip() == '-': |
|---|
| 539 | new_first = '' |
|---|
| 540 | new_middle = old_middle |
|---|
| 541 | if new_middle.strip() == '-': |
|---|
| 542 | new_middle = '' |
|---|
| 543 | new_last = old_last |
|---|
| 544 | if new_last.strip() == '-': |
|---|
| 545 | new_last = '' |
|---|
| 546 | name = "%(new_first)s %(new_middle)s %(new_last)s" % vars() |
|---|
| 547 | if new_student: |
|---|
| 548 | text = "New" |
|---|
| 549 | else: |
|---|
| 550 | text = "Returning" |
|---|
| 551 | old_new = '"%s","%s","%s","%s"' % (invalid,text, |
|---|
| 552 | student_entry.name, |
|---|
| 553 | name) |
|---|
| 554 | if not invalid: |
|---|
| 555 | self.students_catalog.modifyRecord(id = student_id, |
|---|
| 556 | name_fixed = fix, |
|---|
| 557 | name = name) |
|---|
| 558 | per_doc.edit(mapping = {'firstname' : new_first, |
|---|
| 559 | 'middlename' : new_middle, |
|---|
| 560 | 'lastname' : new_last, |
|---|
| 561 | }) |
|---|
| 562 | return old_new |
|---|
| 563 | ###) |
|---|
| 564 | |
|---|
| 565 | security.declareProtected(ModifyPortalContent,"fixAllEntryModeForReturning")###( |
|---|
| 566 | def fixAllEntryModeForReturning(self): |
|---|
| 567 | "read all Returning*.csv" |
|---|
| 568 | ipath = "%s/import/" % i_home |
|---|
| 569 | names = os.listdir(ipath) |
|---|
| 570 | for name in names: |
|---|
| 571 | head,tail = os.path.splitext(name) |
|---|
| 572 | if head.startswith('Returning')\ |
|---|
| 573 | and tail == '.csv'\ |
|---|
| 574 | and name.find('imported') < 0: |
|---|
| 575 | self.fixEntryModeForReturning(csv_file=head) |
|---|
| 576 | ###) |
|---|
| 577 | |
|---|
| 578 | security.declareProtected(ModifyPortalContent,"fixEntryModeForReturning")###( |
|---|
| 579 | def fixEntryModeForReturning(self,csv_file=None): |
|---|
| 580 | """load Returning Studentdata from CSV values""" |
|---|
| 581 | import transaction |
|---|
| 582 | import random |
|---|
| 583 | wftool = self.portal_workflow |
|---|
| 584 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
|---|
| 585 | students_folder = self.portal_url.getPortalObject().campus.students |
|---|
| 586 | tr_count = 1 |
|---|
| 587 | total = 0 |
|---|
| 588 | if csv_file is None: |
|---|
| 589 | name = 'Returning' |
|---|
| 590 | else: |
|---|
| 591 | name = csv_file |
|---|
| 592 | table = self.returning_import |
|---|
| 593 | st_cat = self.students_catalog |
|---|
| 594 | no_import = [] |
|---|
| 595 | logger = logging.getLogger('Students.StudentsFolder.fixEntryModeForReturning') |
|---|
| 596 | try: |
|---|
| 597 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
|---|
| 598 | except: |
|---|
| 599 | logger.error('Error reading %s.csv' % name) |
|---|
| 600 | return |
|---|
| 601 | start = True |
|---|
| 602 | for student in returning: |
|---|
| 603 | if start: |
|---|
| 604 | start = False |
|---|
| 605 | logger.info('Start loading from %s.csv' % name) |
|---|
| 606 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
|---|
| 607 | no_import.append('%s,"Error"' % s) |
|---|
| 608 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
|---|
| 609 | format_error = format + ',"%(Error)s"' |
|---|
| 610 | matric_no = student.get('matric_no') |
|---|
| 611 | if not matric_no: |
|---|
| 612 | continue |
|---|
| 613 | matric_no = matric_no.upper() |
|---|
| 614 | student['matric_no'] = matric_no |
|---|
| 615 | if matric_no == '': |
|---|
| 616 | continue |
|---|
| 617 | if not table(matric_no = matric_no): |
|---|
| 618 | student['Error'] = "Not imported yet" |
|---|
| 619 | no_import.append( format_error % student) |
|---|
| 620 | continue |
|---|
| 621 | student_id = None |
|---|
| 622 | app = None |
|---|
| 623 | per = None |
|---|
| 624 | if st_cat(matric_no = matric_no): |
|---|
| 625 | student_id = st_cat(matric_no = matric_no)[0].id |
|---|
| 626 | student_obj = getattr(students_folder,student_id,None) |
|---|
| 627 | if student_obj: |
|---|
| 628 | app = getattr(student_obj,'application',None) |
|---|
| 629 | if app is not None: |
|---|
| 630 | app_doc = app.getContent() |
|---|
| 631 | per = getattr(student_obj,'personal',None) |
|---|
| 632 | if per is not None: |
|---|
| 633 | per_doc = per.getContent() |
|---|
| 634 | student['Mode_of_Entry'] = entry_mode = student.get('Mode of Entry').upper() |
|---|
| 635 | student['Permanent_Address'] = perm_address = student.get('Permanent Address') |
|---|
| 636 | #import pdb;pdb.set_trace() |
|---|
| 637 | if not entry_mode: |
|---|
| 638 | student['Error'] = "'Mode of Entry' empty" |
|---|
| 639 | no_import.append( format_error % student) |
|---|
| 640 | continue |
|---|
| 641 | try: |
|---|
| 642 | table.modifyRecord(matric_no = matric_no, |
|---|
| 643 | Mode_of_Entry = entry_mode, |
|---|
| 644 | Permanent_Address = perm_address) |
|---|
| 645 | except KeyError: |
|---|
| 646 | student['Error'] = "Not found in returning_import" |
|---|
| 647 | no_import.append( format_error % student) |
|---|
| 648 | continue |
|---|
| 649 | if student_id is not None: |
|---|
| 650 | try: |
|---|
| 651 | st_cat.modifyRecord(id = student_id, |
|---|
| 652 | entry_mode=entry_mode) |
|---|
| 653 | except KeyError: |
|---|
| 654 | student['Error'] = "Not found in students_catalog" |
|---|
| 655 | no_import.append( format_error % student) |
|---|
| 656 | continue |
|---|
| 657 | if app is not None: |
|---|
| 658 | da = {} |
|---|
| 659 | da['entry_mode'] = entry_mode |
|---|
| 660 | app_doc.edit(mapping=da) |
|---|
| 661 | if per is not None: |
|---|
| 662 | dp = {} |
|---|
| 663 | dp['perm_address'] = perm_address |
|---|
| 664 | per_doc.edit(mapping=dp) |
|---|
| 665 | tr_count += 1 |
|---|
| 666 | if tr_count > 1000: |
|---|
| 667 | if len(no_import) > 0: |
|---|
| 668 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 669 | '\n'.join(no_import) + '\n') |
|---|
| 670 | no_import = [] |
|---|
| 671 | em = '%d transactions commited total %s\n' % (tr_count,total) |
|---|
| 672 | transaction.commit() |
|---|
| 673 | regs = [] |
|---|
| 674 | logger.info(em) |
|---|
| 675 | total += tr_count |
|---|
| 676 | tr_count = 0 |
|---|
| 677 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 678 | '\n'.join(no_import)) |
|---|
| 679 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
|---|
| 680 | ###) |
|---|
| 681 | |
|---|
| 682 | security.declareProtected(ModifyPortalContent,"updateReturningStudents")###( |
|---|
| 683 | def updateReturningStudents(self): |
|---|
| 684 | """load and overwrite Returning Student Data from CSV values""" |
|---|
| 685 | import transaction |
|---|
| 686 | import random |
|---|
| 687 | #from pdb import set_trace |
|---|
| 688 | wftool = self.portal_workflow |
|---|
| 689 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
|---|
| 690 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
|---|
| 691 | tr_count = 1 |
|---|
| 692 | total = 0 |
|---|
| 693 | #name = 'pume_results' |
|---|
| 694 | name = 'Returning_update' |
|---|
| 695 | table = self.returning_import |
|---|
| 696 | no_import = [] |
|---|
| 697 | imported = [] |
|---|
| 698 | logger = logging.getLogger('Students.StudentsFolder.updateReturningStudents') |
|---|
| 699 | try: |
|---|
| 700 | returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
|---|
| 701 | except: |
|---|
| 702 | logger.error('Error reading %s.csv' % name) |
|---|
| 703 | return |
|---|
| 704 | l = self.portal_catalog({'meta_type': "Certificate"}) |
|---|
| 705 | certs = {} |
|---|
| 706 | cert_docs = {} |
|---|
| 707 | for f in l: |
|---|
| 708 | certs[f.getId] = f.getObject().getContent() |
|---|
| 709 | start = True |
|---|
| 710 | res = table() |
|---|
| 711 | regs = [] |
|---|
| 712 | if len(res) > 0: |
|---|
| 713 | regs = [s.matric_no for s in res] |
|---|
| 714 | for student in returning: |
|---|
| 715 | if start: |
|---|
| 716 | start = False |
|---|
| 717 | logger.info('Start loading from %s.csv' % name) |
|---|
| 718 | s = ','.join(['"%s"' % fn for fn in student.keys()]) |
|---|
| 719 | imported.append(s) |
|---|
| 720 | no_import.append('%s,"Error"' % s) |
|---|
| 721 | format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) |
|---|
| 722 | format_error = format + ',"%(Error)s"' |
|---|
| 723 | no_certificate = "no certificate %s" % format |
|---|
| 724 | matric_no = student.get('matric_no').upper() |
|---|
| 725 | student['matric_no'] = matric_no |
|---|
| 726 | if matric_no == '': |
|---|
| 727 | student['Error'] = "Empty matric_no" |
|---|
| 728 | no_import.append( format_error % student) |
|---|
| 729 | continue |
|---|
| 730 | # if matric_no in regs or self.returning_import(matric_no = matric_no): |
|---|
| 731 | # student['Error'] = "Duplicate" |
|---|
| 732 | # no_import.append( format_error % student) |
|---|
| 733 | # continue |
|---|
| 734 | # cert_id = makeCertificateCode(student.get('Coursemajorcode')) |
|---|
| 735 | # if cert_id not in certs.keys(): |
|---|
| 736 | # student['Error'] = "No Certificate %s" % cert_id |
|---|
| 737 | # no_import.append( format_error % student) |
|---|
| 738 | # continue |
|---|
| 739 | try: |
|---|
| 740 | table.modifyRecord(**student) |
|---|
| 741 | except KeyError: |
|---|
| 742 | #import pdb;pdb.set_trace() |
|---|
| 743 | student['Error'] = "no Student found to update" |
|---|
| 744 | no_import.append( format_error % student) |
|---|
| 745 | continue |
|---|
| 746 | #s = self.students_catalog(matric_no=matric_no) |
|---|
| 747 | #if s: |
|---|
| 748 | # level = "%s" % (int(student.get('Level')) + 100) |
|---|
| 749 | # self.students_catalog.modifyRecord(id = s[0].id, |
|---|
| 750 | # level=level) |
|---|
| 751 | |
|---|
| 752 | regs.append(student.get('matric_no')) |
|---|
| 753 | imported.append(format % student) |
|---|
| 754 | tr_count += 1 |
|---|
| 755 | if tr_count > 1000: |
|---|
| 756 | if len(no_import) > 0: |
|---|
| 757 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 758 | '\n'.join(no_import) + '\n') |
|---|
| 759 | no_import = [] |
|---|
| 760 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 761 | '\n'.join(no_import) + "\n") |
|---|
| 762 | imported = [] |
|---|
| 763 | em = '%d transactions commited total %s\n' % (tr_count,total) |
|---|
| 764 | transaction.commit() |
|---|
| 765 | regs = [] |
|---|
| 766 | logger.info(em) |
|---|
| 767 | total += tr_count |
|---|
| 768 | tr_count = 0 |
|---|
| 769 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 770 | '\n'.join(imported)) |
|---|
| 771 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 772 | '\n'.join(no_import)) |
|---|
| 773 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
|---|
| 774 | ###) |
|---|
| 775 | |
|---|
| 776 | security.declareProtected(ModifyPortalContent,"importResults")###( |
|---|
| 777 | def importResults(self): |
|---|
| 778 | """load Returning Students Results from CSV""" |
|---|
| 779 | import transaction |
|---|
| 780 | import random |
|---|
| 781 | #from pdb import set_trace |
|---|
| 782 | wftool = self.portal_workflow |
|---|
| 783 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
|---|
| 784 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
|---|
| 785 | tr_count = 1 |
|---|
| 786 | total = 0 |
|---|
| 787 | #name = 'pume_results' |
|---|
| 788 | name = 'Results' |
|---|
| 789 | table = self.results_import |
|---|
| 790 | no_import = [] |
|---|
| 791 | imported = [] |
|---|
| 792 | logger = logging.getLogger('Students.StudentsFolder.importResults') |
|---|
| 793 | try: |
|---|
| 794 | results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
|---|
| 795 | except: |
|---|
| 796 | logger.error('Error reading %s.csv' % name) |
|---|
| 797 | return |
|---|
| 798 | l = self.portal_catalog({'meta_type': "Course"}) |
|---|
| 799 | courses = [f.getId for f in l] |
|---|
| 800 | start = True |
|---|
| 801 | res = table() |
|---|
| 802 | regs = [] |
|---|
| 803 | if len(res) > 0: |
|---|
| 804 | regs = [s.key for s in res] |
|---|
| 805 | no_course = [] |
|---|
| 806 | no_course_list = [] |
|---|
| 807 | course_count = 0 |
|---|
| 808 | for result in results: |
|---|
| 809 | if start: |
|---|
| 810 | start = False |
|---|
| 811 | logger.info('Start loading from %s.csv' % name) |
|---|
| 812 | s = ','.join(['"%s"' % fn for fn in result.keys()]) |
|---|
| 813 | imported.append(s) |
|---|
| 814 | no_import.append('%s,"Error"' % s) |
|---|
| 815 | format = ','.join(['"%%(%s)s"' % fn for fn in result.keys()]) |
|---|
| 816 | format_error = format + ',"%(Error)s"' |
|---|
| 817 | no_certificate = "no certificate %s" % format |
|---|
| 818 | course_id = result.get('CosCode') |
|---|
| 819 | if not course_id: |
|---|
| 820 | course_id = 'N/A' |
|---|
| 821 | result['CosCode'] = course_id |
|---|
| 822 | matric_no = result.get('matric_no').upper() |
|---|
| 823 | result['matric_no'] = matric_no |
|---|
| 824 | key = matric_no+course_id |
|---|
| 825 | if matric_no == '': |
|---|
| 826 | result['Error'] = "Empty matric_no" |
|---|
| 827 | no_import.append( format_error % result) |
|---|
| 828 | continue |
|---|
| 829 | if key in regs or self.results_import(key = key): |
|---|
| 830 | result['Error'] = "Duplicate" |
|---|
| 831 | no_import.append( format_error % result) |
|---|
| 832 | continue |
|---|
| 833 | if course_id not in courses: |
|---|
| 834 | if course_id not in no_course: |
|---|
| 835 | course_count +=1 |
|---|
| 836 | no_course.append(course_id) |
|---|
| 837 | no_course_list.append('"%s"' % course_id) |
|---|
| 838 | #result['Error'] = "No Course" |
|---|
| 839 | #logger.info(format_error % result) |
|---|
| 840 | regs.append(key) |
|---|
| 841 | imported.append(format % result) |
|---|
| 842 | tr_count += 1 |
|---|
| 843 | if tr_count > 1000: |
|---|
| 844 | if len(no_import) > 0: |
|---|
| 845 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 846 | '\n'.join(no_import)+'\n') |
|---|
| 847 | no_import = [] |
|---|
| 848 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 849 | '\n'.join(imported) + '\n') |
|---|
| 850 | imported = [] |
|---|
| 851 | if no_course_list: |
|---|
| 852 | open("%s/import/%sno_courses%s.csv" % (i_home,name,current),"a").write( |
|---|
| 853 | '\n'.join(no_course_list) + '\n') |
|---|
| 854 | no_course_list = [] |
|---|
| 855 | em = '%d transactions commited total %s\n courses not found %s' % (tr_count,total,course_count) |
|---|
| 856 | transaction.commit() |
|---|
| 857 | logger.info(em) |
|---|
| 858 | regs = [] |
|---|
| 859 | total += tr_count |
|---|
| 860 | tr_count = 0 |
|---|
| 861 | open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 862 | '\n'.join(imported)) |
|---|
| 863 | open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( |
|---|
| 864 | '\n'.join(no_import)) |
|---|
| 865 | if no_course_list: |
|---|
| 866 | open("%s/import/%sno_courses%s.csv" % (i_home,name,current),"a").write( |
|---|
| 867 | '\n'.join(no_course_list)) |
|---|
| 868 | em = '%d transactions commited total %s\n courses not found %s' % (tr_count,total,course_count) |
|---|
| 869 | logger.info(em) |
|---|
| 870 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
|---|
| 871 | ###) |
|---|
| 872 | |
|---|
| 873 | |
|---|
| 874 | security.declareProtected(ModifyPortalContent,"updateStudyCourse")###( |
|---|
| 875 | def updateStudyCourse(self): |
|---|
| 876 | """update StudyCourse from CSV values""" |
|---|
| 877 | import transaction |
|---|
| 878 | import random |
|---|
| 879 | from pdb import set_trace |
|---|
| 880 | wftool = self.portal_workflow |
|---|
| 881 | students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() |
|---|
| 882 | csv_d = {'jamb_reg_no': "RegNumber", |
|---|
| 883 | 'jamb_lastname': "Name", |
|---|
| 884 | 'session': "Session", |
|---|
| 885 | 'pume_tot_score': "PUME SCORE", |
|---|
| 886 | 'jamb_score': "JambScore", |
|---|
| 887 | 'jamb_sex': "Sex", |
|---|
| 888 | 'jamb_state': "State", |
|---|
| 889 | ## 'jamb_first_cos': "AdminCourse", |
|---|
| 890 | 'faculty': "AdminFaculty", |
|---|
| 891 | 'course_code': "AdmitCoscode", |
|---|
| 892 | 'stud_status':"AdmitStatus", |
|---|
| 893 | 'department': "AdmitDept", |
|---|
| 894 | 'jamb_lga': "LGA", |
|---|
| 895 | 'app_email': "email", |
|---|
| 896 | 'app_mobile': "PhoneNumbers", |
|---|
| 897 | } |
|---|
| 898 | csv_fields = [f[1] for f in csv_d.items()] |
|---|
| 899 | tr_count = 0 |
|---|
| 900 | total = 0 |
|---|
| 901 | #name = 'pume_results' |
|---|
| 902 | name = 'StudyCourseChange' |
|---|
| 903 | no_import = [] |
|---|
| 904 | s = ','.join(['"%s"' % fn for fn in csv_fields]) |
|---|
| 905 | no_import.append('"Error",%s' % s) |
|---|
| 906 | format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) |
|---|
| 907 | no_certificate = "no certificate %s" % format |
|---|
| 908 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( |
|---|
| 909 | '\n'.join(no_import)) |
|---|
| 910 | logger = logging.getLogger('Students.StudentsFolder.updateStudyCourse') |
|---|
| 911 | logger.info('Start loading from %s.csv' % name) |
|---|
| 912 | l = self.portal_catalog({'meta_type': "Certificate"}) |
|---|
| 913 | try: |
|---|
| 914 | result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) |
|---|
| 915 | except: |
|---|
| 916 | logger.error('Error reading %s.csv' % name) |
|---|
| 917 | return |
|---|
| 918 | for jamb in result: |
|---|
| 919 | jamb['Error'] = "Processing " |
|---|
| 920 | logger.info(format % jamb) |
|---|
| 921 | jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) |
|---|
| 922 | res = self.portal_catalog({'portal_type': "StudentApplication", |
|---|
| 923 | 'SearchableText': jamb_reg_no }) |
|---|
| 924 | if not res: |
|---|
| 925 | em = 'Student with jamb_reg_no %s does not exists\n' % jamb_reg_no |
|---|
| 926 | logger.info(em) |
|---|
| 927 | jamb['Error'] = "Student does not exist" |
|---|
| 928 | no_import.append(format % jamb) |
|---|
| 929 | continue |
|---|
| 930 | sid = res[0].getPath().split('/')[-2] |
|---|
| 931 | cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) |
|---|
| 932 | res = self.portal_catalog(portal_type = "Certificate", id = cert_id) |
|---|
| 933 | if not res: |
|---|
| 934 | em = 'No Certificate with ID %s \n' % cert_id |
|---|
| 935 | logger.info(em) |
|---|
| 936 | jamb['Error'] = "No Certificate %s" % cert_id |
|---|
| 937 | no_import.append( format % jamb) |
|---|
| 938 | continue |
|---|
| 939 | cert_brain = res[0] |
|---|
| 940 | catalog_entry = {} |
|---|
| 941 | student = getattr(self,sid) |
|---|
| 942 | # |
|---|
| 943 | # Study Course |
|---|
| 944 | # |
|---|
| 945 | study_course = student.study_course |
|---|
| 946 | dsc = {} |
|---|
| 947 | cert_pl = cert_brain.getPath().split('/') |
|---|
| 948 | catalog_entry['id'] = sid |
|---|
| 949 | catalog_entry['faculty'] = cert_pl[-4] |
|---|
| 950 | catalog_entry['department'] = cert_pl[-3] |
|---|
| 951 | catalog_entry['course'] = cert_id |
|---|
| 952 | dsc['study_course'] = cert_id |
|---|
| 953 | study_course.getContent().edit(mapping=dsc) |
|---|
| 954 | self.students_catalog.modifyRecord(**catalog_entry) |
|---|
| 955 | if tr_count > 10: |
|---|
| 956 | if len(no_import) > 1: |
|---|
| 957 | open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write( |
|---|
| 958 | '\n'.join(no_import)) |
|---|
| 959 | no_import = [] |
|---|
| 960 | em = '%d transactions commited\n' % tr_count |
|---|
| 961 | transaction.commit() |
|---|
| 962 | logger.info(em) |
|---|
| 963 | total += tr_count |
|---|
| 964 | tr_count = 0 |
|---|
| 965 | tr_count += 1 |
|---|
| 966 | return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) |
|---|
| 967 | ###) |
|---|
| 968 | |
|---|
| 969 | security.declareProtected(View,"fixOwnership") ###( |
|---|
| 970 | def fixOwnership(self): |
|---|
| 971 | """fix Ownership""" |
|---|
| 972 | for s in self.portal_catalog(meta_type = 'Student'): |
|---|
| 973 | student = s.getObject() |
|---|
| 974 | sid = s.getId |
|---|
| 975 | import pdb;pdb.set_trace() |
|---|
| 976 | student.application.manage_setLocalRoles(sid, ['Owner',]) |
|---|
| 977 | student.personal.manage_setLocalRoles(sid, ['Owner',]) |
|---|
| 978 | ###) |
|---|
| 979 | |
|---|
| 980 | security.declareProtected(View,"Title") ###( |
|---|
| 981 | def Title(self): |
|---|
| 982 | """compose title""" |
|---|
| 983 | return "Student Section" |
|---|
| 984 | ###) |
|---|
| 985 | |
|---|
| 986 | def generateStudentId(self,letter,students = None): ###( |
|---|
| 987 | import random |
|---|
| 988 | r = random |
|---|
| 989 | if students is None: |
|---|
| 990 | students = self.portal_url.getPortalObject().campus.students |
|---|
| 991 | if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'): |
|---|
| 992 | letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY') |
|---|
| 993 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
|---|
| 994 | while hasattr(students, sid): |
|---|
| 995 | sid = "%c%d" % (letter,r.randint(99999,1000000)) |
|---|
| 996 | return sid |
|---|
| 997 | #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000)) |
|---|
| 998 | ###) |
|---|
| 999 | |
|---|
| 1000 | InitializeClass(StudentsFolder) |
|---|
| 1001 | |
|---|
| 1002 | def addStudentsFolder(container, id, REQUEST=None, **kw): ###( |
|---|
| 1003 | """Add a Student.""" |
|---|
| 1004 | ob = StudentsFolder(id, **kw) |
|---|
| 1005 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1006 | ###) |
|---|
| 1007 | |
|---|
| 1008 | ###) |
|---|
| 1009 | |
|---|
| 1010 | class Student(CPSDocument): ###( |
|---|
| 1011 | """ |
|---|
| 1012 | WAeUP Student container for the various student data |
|---|
| 1013 | """ |
|---|
| 1014 | meta_type = 'Student' |
|---|
| 1015 | portal_type = meta_type |
|---|
| 1016 | security = ClassSecurityInfo() |
|---|
| 1017 | |
|---|
| 1018 | security.declareProtected(View,"Title") |
|---|
| 1019 | def Title(self): |
|---|
| 1020 | """compose title""" |
|---|
| 1021 | reg_nr = self.getId()[1:] |
|---|
| 1022 | data = getattr(self,'personal',None) |
|---|
| 1023 | if data: |
|---|
| 1024 | content = data.getContent() |
|---|
| 1025 | return "%s %s %s" % (content.firstname,content.middlename,content.lastname) |
|---|
| 1026 | data = getattr(self,'application',None) |
|---|
| 1027 | if data: |
|---|
| 1028 | content = data.getContent() |
|---|
| 1029 | return "%s" % (content.jamb_lastname) |
|---|
| 1030 | return self.title |
|---|
| 1031 | |
|---|
| 1032 | security.declarePrivate('makeStudentMember') ###( |
|---|
| 1033 | def makeStudentMember(self,sid,password='uNsEt'): |
|---|
| 1034 | """make the student a member""" |
|---|
| 1035 | membership = self.portal_membership |
|---|
| 1036 | membership.addMember(sid, |
|---|
| 1037 | password , |
|---|
| 1038 | roles=('Member', |
|---|
| 1039 | 'Student', |
|---|
| 1040 | ), |
|---|
| 1041 | domains='', |
|---|
| 1042 | properties = {'memberareaCreationFlag': False, |
|---|
| 1043 | 'homeless': True},) |
|---|
| 1044 | member = membership.getMemberById(sid) |
|---|
| 1045 | self.portal_registration.afterAdd(member, sid, password, None) |
|---|
| 1046 | self.manage_setLocalRoles(sid, ['Owner',]) |
|---|
| 1047 | |
|---|
| 1048 | ###) |
|---|
| 1049 | |
|---|
| 1050 | security.declareProtected(View,'createSubObjects') ###( |
|---|
| 1051 | def createSubObjects(self): |
|---|
| 1052 | """make the student a member""" |
|---|
| 1053 | dp = {'Title': 'Personal Data'} |
|---|
| 1054 | app_doc = self.application.getContent() |
|---|
| 1055 | names = app_doc.jamb_lastname.split() |
|---|
| 1056 | if len(names) == 3: |
|---|
| 1057 | dp['firstname'] = names[0].capitalize() |
|---|
| 1058 | dp['middlename'] = names[1].capitalize() |
|---|
| 1059 | dp['lastname'] = names[2].capitalize() |
|---|
| 1060 | elif len(names) == 2: |
|---|
| 1061 | dp['firstname'] = names[0].capitalize() |
|---|
| 1062 | dp['lastname'] = names[1].capitalize() |
|---|
| 1063 | else: |
|---|
| 1064 | dp['lastname'] = app_doc.jamb_lastname |
|---|
| 1065 | dp['sex'] = app_doc.jamb_sex == 'F' |
|---|
| 1066 | dp['lga'] = "%s/%s" % (app_doc.jamb_state,app_doc.jamb_lga ) |
|---|
| 1067 | proxy = self.aq_parent |
|---|
| 1068 | proxy.invokeFactory('StudentPersonal','personal') |
|---|
| 1069 | per = proxy.personal |
|---|
| 1070 | per_doc = per.getContent() |
|---|
| 1071 | per_doc.edit(mapping = dp) |
|---|
| 1072 | per.manage_setLocalRoles(proxy.getId(), ['Owner',]) |
|---|
| 1073 | #self.portal_workflow.doActionFor(per,'open',dest_container=per) |
|---|
| 1074 | |
|---|
| 1075 | ###) |
|---|
| 1076 | |
|---|
| 1077 | InitializeClass(Student) |
|---|
| 1078 | |
|---|
| 1079 | def addStudent(container, id, REQUEST=None, **kw): |
|---|
| 1080 | """Add a Student.""" |
|---|
| 1081 | ob = Student(id, **kw) |
|---|
| 1082 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1083 | |
|---|
| 1084 | ###) |
|---|
| 1085 | |
|---|
| 1086 | class StudentAccommodation(CPSDocument): ###( |
|---|
| 1087 | """ |
|---|
| 1088 | WAeUP Student container for the various student data |
|---|
| 1089 | """ |
|---|
| 1090 | meta_type = 'StudentAccommodation' |
|---|
| 1091 | portal_type = meta_type |
|---|
| 1092 | security = ClassSecurityInfo() |
|---|
| 1093 | |
|---|
| 1094 | security.declareProtected(View,"Title") |
|---|
| 1095 | def Title(self): |
|---|
| 1096 | """compose title""" |
|---|
| 1097 | content = self.getContent() |
|---|
| 1098 | #return "Accommodation Data for %s %s" % (content.firstname,content.lastname) |
|---|
| 1099 | return "Accommodation Data for Session %s" % content.session |
|---|
| 1100 | |
|---|
| 1101 | |
|---|
| 1102 | InitializeClass(StudentAccommodation) |
|---|
| 1103 | |
|---|
| 1104 | def addStudentAccommodation(container, id, REQUEST=None, **kw): |
|---|
| 1105 | """Add a Students personal data.""" |
|---|
| 1106 | ob = StudentAccommodation(id, **kw) |
|---|
| 1107 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1108 | |
|---|
| 1109 | ###) |
|---|
| 1110 | |
|---|
| 1111 | class StudentPersonal(CPSDocument): ###( |
|---|
| 1112 | """ |
|---|
| 1113 | WAeUP Student container for the various student data |
|---|
| 1114 | """ |
|---|
| 1115 | meta_type = 'StudentPersonal' |
|---|
| 1116 | portal_type = meta_type |
|---|
| 1117 | security = ClassSecurityInfo() |
|---|
| 1118 | |
|---|
| 1119 | security.declareProtected(View,"Title") |
|---|
| 1120 | def Title(self): |
|---|
| 1121 | """compose title""" |
|---|
| 1122 | content = self.getContent() |
|---|
| 1123 | #return "Personal Data for %s %s" % (content.firstname,content.lastname) |
|---|
| 1124 | return "Personal Data" |
|---|
| 1125 | |
|---|
| 1126 | |
|---|
| 1127 | InitializeClass(StudentPersonal) |
|---|
| 1128 | |
|---|
| 1129 | def addStudentPersonal(container, id, REQUEST=None, **kw): |
|---|
| 1130 | """Add a Students personal data.""" |
|---|
| 1131 | ob = StudentPersonal(id, **kw) |
|---|
| 1132 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1133 | |
|---|
| 1134 | ###) |
|---|
| 1135 | |
|---|
| 1136 | class StudentClearance(CPSDocument): ###( |
|---|
| 1137 | """ |
|---|
| 1138 | WAeUP Student container for the various student data |
|---|
| 1139 | """ |
|---|
| 1140 | meta_type = 'StudentClearance' |
|---|
| 1141 | portal_type = meta_type |
|---|
| 1142 | security = ClassSecurityInfo() |
|---|
| 1143 | |
|---|
| 1144 | security.declareProtected(View,"Title") |
|---|
| 1145 | def Title(self): |
|---|
| 1146 | """compose title""" |
|---|
| 1147 | content = self.getContent() |
|---|
| 1148 | #return "Clearance/Eligibility Record for %s %s" % (content.firstname,content.lastname) |
|---|
| 1149 | return "Clearance/Eligibility Record" |
|---|
| 1150 | |
|---|
| 1151 | |
|---|
| 1152 | InitializeClass(StudentClearance) |
|---|
| 1153 | |
|---|
| 1154 | def addStudentClearance(container, id, REQUEST=None, **kw): |
|---|
| 1155 | """Add a Students personal data.""" |
|---|
| 1156 | ob = StudentClearance(id, **kw) |
|---|
| 1157 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1158 | |
|---|
| 1159 | ###) |
|---|
| 1160 | |
|---|
| 1161 | class StudentStudyLevel(CPSDocument): ###( |
|---|
| 1162 | """ |
|---|
| 1163 | WAeUP Student container for the various student data |
|---|
| 1164 | """ |
|---|
| 1165 | meta_type = 'StudentStudyLevel' |
|---|
| 1166 | portal_type = meta_type |
|---|
| 1167 | security = ClassSecurityInfo() |
|---|
| 1168 | |
|---|
| 1169 | security.declareProtected(View,"Title") |
|---|
| 1170 | def Title(self): |
|---|
| 1171 | """compose title""" |
|---|
| 1172 | return "Level %s" % self.aq_parent.getId() |
|---|
| 1173 | |
|---|
| 1174 | def create_course_results(self,cert_id,current_level): ###( |
|---|
| 1175 | "create all courses in a level" |
|---|
| 1176 | aq_portal = self.portal_catalog.evalAdvancedQuery |
|---|
| 1177 | res = self.portal_catalog(portal_type="Certificate", id = cert_id) |
|---|
| 1178 | l = [] |
|---|
| 1179 | import transaction |
|---|
| 1180 | if res: |
|---|
| 1181 | cert = res[0] |
|---|
| 1182 | path = cert.getPath() |
|---|
| 1183 | query = Eq("path","%s/%s" % (path,current_level)) &\ |
|---|
| 1184 | Eq('portal_type','CertificateCourse') |
|---|
| 1185 | courses = aq_portal(query) |
|---|
| 1186 | #from pdb import set_trace;set_trace() |
|---|
| 1187 | self_proxy = self.aq_parent |
|---|
| 1188 | for c in courses: |
|---|
| 1189 | d = self.getCourseInfo(c.getId) |
|---|
| 1190 | cr_id = self_proxy.invokeFactory('StudentCourseResult',c.getId) |
|---|
| 1191 | course_result = getattr(self_proxy,cr_id) |
|---|
| 1192 | self.portal_workflow.doActionFor(course_result,'open') |
|---|
| 1193 | d['core_or_elective'] = getattr(c.getObject().getContent(),'core_or_elective') |
|---|
| 1194 | course_result.getContent().edit(mapping=d) |
|---|
| 1195 | transaction.commit() |
|---|
| 1196 | ###) |
|---|
| 1197 | |
|---|
| 1198 | InitializeClass(StudentStudyLevel) |
|---|
| 1199 | |
|---|
| 1200 | def addStudentStudyLevel(container, id, REQUEST=None, **kw): |
|---|
| 1201 | """Add a Students personal data.""" |
|---|
| 1202 | ob = StudentStudyLevel(id, **kw) |
|---|
| 1203 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1204 | |
|---|
| 1205 | ###) |
|---|
| 1206 | |
|---|
| 1207 | class StudentStudyCourse(CPSDocument): ###( |
|---|
| 1208 | """ |
|---|
| 1209 | WAeUP Student container for the various student data |
|---|
| 1210 | """ |
|---|
| 1211 | meta_type = 'StudentStudyCourse' |
|---|
| 1212 | portal_type = meta_type |
|---|
| 1213 | security = ClassSecurityInfo() |
|---|
| 1214 | |
|---|
| 1215 | security.declareProtected(View,"Title") |
|---|
| 1216 | def Title(self): |
|---|
| 1217 | """compose title""" |
|---|
| 1218 | content = self.getContent() |
|---|
| 1219 | return "Study Course" |
|---|
| 1220 | |
|---|
| 1221 | |
|---|
| 1222 | InitializeClass(StudentStudyCourse) |
|---|
| 1223 | |
|---|
| 1224 | def addStudentStudyCourse(container, id, REQUEST=None, **kw): |
|---|
| 1225 | """Add a Students personal data.""" |
|---|
| 1226 | ob = StudentStudyCourse(id, **kw) |
|---|
| 1227 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1228 | |
|---|
| 1229 | ###) |
|---|
| 1230 | |
|---|
| 1231 | class StudentApplication(CPSDocument): ###( |
|---|
| 1232 | """ |
|---|
| 1233 | WAeUP Student container for the various student data |
|---|
| 1234 | """ |
|---|
| 1235 | meta_type = 'StudentApplication' |
|---|
| 1236 | portal_type = meta_type |
|---|
| 1237 | security = ClassSecurityInfo() |
|---|
| 1238 | |
|---|
| 1239 | security.declareProtected(View,"Title") |
|---|
| 1240 | def Title(self): |
|---|
| 1241 | """compose title""" |
|---|
| 1242 | return "Application Data" |
|---|
| 1243 | |
|---|
| 1244 | |
|---|
| 1245 | InitializeClass(StudentApplication) |
|---|
| 1246 | |
|---|
| 1247 | def addStudentApplication(container, id, REQUEST=None, **kw): |
|---|
| 1248 | """Add a Students eligibility data.""" |
|---|
| 1249 | ob = StudentApplication(id, **kw) |
|---|
| 1250 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1251 | ###) |
|---|
| 1252 | |
|---|
| 1253 | class StudentPume(CPSDocument): ###( |
|---|
| 1254 | """ |
|---|
| 1255 | WAeUP Student container for the various student data |
|---|
| 1256 | """ |
|---|
| 1257 | meta_type = 'StudentPume' |
|---|
| 1258 | portal_type = meta_type |
|---|
| 1259 | security = ClassSecurityInfo() |
|---|
| 1260 | |
|---|
| 1261 | security.declareProtected(View,"Title") |
|---|
| 1262 | def Title(self): |
|---|
| 1263 | """compose title""" |
|---|
| 1264 | return "PUME Results" |
|---|
| 1265 | |
|---|
| 1266 | |
|---|
| 1267 | InitializeClass(StudentPume) |
|---|
| 1268 | |
|---|
| 1269 | def addStudentPume(container, id, REQUEST=None, **kw): |
|---|
| 1270 | """Add a Students PUME data.""" |
|---|
| 1271 | ob = StudentPume(id, **kw) |
|---|
| 1272 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1273 | ###) |
|---|
| 1274 | |
|---|
| 1275 | ##class StudentSemester(CPSDocument): ###( |
|---|
| 1276 | ## """ |
|---|
| 1277 | ## WAeUP StudentSemester containing the courses and students |
|---|
| 1278 | ## """ |
|---|
| 1279 | ## meta_type = 'StudentSemester' |
|---|
| 1280 | ## portal_type = meta_type |
|---|
| 1281 | ## security = ClassSecurityInfo() |
|---|
| 1282 | ## |
|---|
| 1283 | ##InitializeClass(StudentSemester) |
|---|
| 1284 | ## |
|---|
| 1285 | ##def addStudentSemester(container, id, REQUEST=None, **kw): |
|---|
| 1286 | ## """Add a StudentSemester.""" |
|---|
| 1287 | ## ob = StudentSemester(id, **kw) |
|---|
| 1288 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1289 | ## |
|---|
| 1290 | #####) |
|---|
| 1291 | |
|---|
| 1292 | ##class Semester(CPSDocument): ###( |
|---|
| 1293 | ## """ |
|---|
| 1294 | ## WAeUP Semester containing the courses and students |
|---|
| 1295 | ## """ |
|---|
| 1296 | ## meta_type = 'Semester' |
|---|
| 1297 | ## portal_type = meta_type |
|---|
| 1298 | ## security = ClassSecurityInfo() |
|---|
| 1299 | ## |
|---|
| 1300 | ##InitializeClass(Semester) |
|---|
| 1301 | ## |
|---|
| 1302 | ##def addSemester(container, id, REQUEST=None, **kw): |
|---|
| 1303 | ## """Add a Semester.""" |
|---|
| 1304 | ## ob = Semester(id, **kw) |
|---|
| 1305 | ## return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1306 | ## |
|---|
| 1307 | #####) |
|---|
| 1308 | |
|---|
| 1309 | class StudentCourseResult(CPSDocument): ###( |
|---|
| 1310 | """ |
|---|
| 1311 | WAeUP StudentCourseResult |
|---|
| 1312 | """ |
|---|
| 1313 | meta_type = 'StudentCourseResult' |
|---|
| 1314 | portal_type = meta_type |
|---|
| 1315 | security = ClassSecurityInfo() |
|---|
| 1316 | |
|---|
| 1317 | def getCourseEntry(self,cid): |
|---|
| 1318 | res = self.portal_catalog({'meta_type': "Course", |
|---|
| 1319 | 'id': cid}) |
|---|
| 1320 | if res: |
|---|
| 1321 | return res[-1] |
|---|
| 1322 | else: |
|---|
| 1323 | return None |
|---|
| 1324 | |
|---|
| 1325 | security.declareProtected(View,"Title") |
|---|
| 1326 | def Title(self): |
|---|
| 1327 | """compose title""" |
|---|
| 1328 | cid = self.aq_parent.getId() |
|---|
| 1329 | ce = self.getCourseEntry(cid) |
|---|
| 1330 | if ce: |
|---|
| 1331 | return "%s" % ce.Title |
|---|
| 1332 | return "No course with id %s" % cid |
|---|
| 1333 | |
|---|
| 1334 | InitializeClass(StudentCourseResult) |
|---|
| 1335 | |
|---|
| 1336 | def addStudentCourseResult(container, id, REQUEST=None, **kw): |
|---|
| 1337 | """Add a StudentCourseResult.""" |
|---|
| 1338 | ob = StudentCourseResult(id, **kw) |
|---|
| 1339 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
|---|
| 1340 | ###) |
|---|
| 1341 | |
|---|
| 1342 | # Backward Compatibility StudyLevel |
|---|
| 1343 | |
|---|
| 1344 | from Products.WAeUP_SRP.Academics import StudyLevel |
|---|
| 1345 | |
|---|
| 1346 | from Products.WAeUP_SRP.Academics import addStudyLevel |
|---|
| 1347 | |
|---|