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