Changeset 971
- Timestamp:
- 30 Nov 2006, 19:31:01 (18 years ago)
- Location:
- WAeUP_SRP/trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r966 r971 17 17 from Products.WAeUP_SRP.Academics import makeCertificateCode 18 18 import logging 19 import csv,re 19 import csv,re,os 20 20 import Globals 21 21 p_home = Globals.package_home(globals()) … … 23 23 MAX_TRANS = 100 24 24 import DateTime 25 import PIL.Image 26 from StringIO import StringIO 25 27 26 28 def makeCertificateCode(code): ###( … … 263 265 tr_count = 0 264 266 total = 0 265 #name = 'pume_results' 266 name = 'pup' 267 #name = 'pup_new' 268 name = 'pup_update' 269 update = name.endswith('update') 267 270 no_import = [] 268 271 s = ','.join(['"(%s)"' % fn for fn in csv_fields]) … … 287 290 for f,fn in csv_d.items(): 288 291 dict[f] = jamb.get(csv_d[f]) 292 res = pume(jamb_reg_no=jamb.get(csv_d['jamb_reg_no'])) 293 if len(res) > 0: 294 if update: 295 pume.modifyRecord(**dict) 296 else: 297 data = res[0] 298 if data.name != jamb.get(csv_d['name']): 299 #set_trace() 300 logger.info(eduplicate % jamb) 301 #em = 'Student with REG-NO %(jamb_reg_no)s already exists\n' % dict 302 #logger.info(em) 303 dd = {} 304 for f,fn in csv_d.items(): 305 dd[fn] = getattr(data,f) 306 no_import.append(eduplicate % dd) 307 no_import.append(eduplicate % jamb) 308 continue 289 309 try: 290 310 pume.addRecord(**dict) … … 299 319 '\n'.join(no_import)) 300 320 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 321 ###) 301 322 302 323 security.declareProtected(ModifyPortalContent,"createNewStudents")###( … … 305 326 import transaction 306 327 import random 307 from pdb import set_trace328 #from pdb import set_trace 308 329 wftool = self.portal_workflow 309 330 students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() 310 csv_d = {'jamb_reg_no': " JAMBRegno",331 csv_d = {'jamb_reg_no': "RegNumber", 311 332 'jamb_lastname': "Name", 312 #'pume_options': "Options", 313 #'session': "Session", 314 #'days': "Days", 315 #'response': "Responce", 316 #'wrong': "Wrong", 317 #'pume_eng_score': "EngScore", 318 #'pume_gen_score': "GenScore", 319 'pume_tot_score': "Score", 320 #'batch': "Batch", 321 #'serial': "SerialNo", 322 'jamb_score': "Score", 323 #'omitted':"Omitted", 324 #'search_key': "SearchKey", 333 'session': "Session", 334 'pume_tot_score': "PUME SCORE", 335 'jamb_score': "JambScore", 325 336 'jamb_sex': "Sex", 326 'fac1': "Faculty", 327 'dep': "Dept", 328 #'fac2': "Fac2", 329 'jamb_first_cos': "Course Code", 330 'stud_status':"Admission Status", 331 #'registered': "Registered", 332 #'jamb_state': "State", 333 #'eng_fail': "EngFail", 334 #'gen_fail': "GenFail", 335 #'un_ans_eng': "UnAnsEng", 336 #'un_ans_eng': "UnAnsGen", 337 #'total_ans': "TotalUnAns", 338 #'dept': "Dept", 339 #'jamb_second_cos': "Course2", 340 #'jamb_third_cos': "course3", 337 'jamb_state': "State", 338 'jamb_first_cos': "AdminCourse", 339 'faculty': "AdminFaculty", 340 'course_code': "AdmitCoscode", 341 'stud_status':"AdmitStatus", 342 'department': "AdmitDept", 343 'jamb_lga': "LGA", 344 'app_email': "email", 341 345 } 342 346 csv_fields = [f[1] for f in csv_d.items()] … … 344 348 total = 0 345 349 #name = 'pume_results' 346 name = ' pup'350 name = 'Admitted' 347 351 no_import = [] 348 352 s = ','.join(['"(%s)"' % fn for fn in csv_fields]) 349 no_import.append('%s' % s) 353 no_import.append('"Error",%s' % s) 354 format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) 355 no_certificate = "no certificate %s" % format 350 356 open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( 351 357 '\n'.join(no_import)) 352 no_import = []353 358 logger = logging.getLogger('%s_import' % name) 354 359 logger.info('Start loading from %s.csv' % name) 355 #set_trace() 360 l = self.portal_catalog({'meta_type': "Certificate"}) 361 certs = {} 362 cert_docs = {} 363 for f in l: 364 certs[f.getId] = f.getObject().getContent() 356 365 try: 357 366 result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) … … 360 369 return 361 370 for jamb in result: 362 format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) 363 processing = "processing %s" % format 364 logger.info(processing % jamb) 371 jamb['Error'] = "Processing " 372 logger.info(format % jamb) 365 373 jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) 366 #import pdb;pdb.set_trace()367 374 res = self.portal_catalog({'portal_type': "StudentApplication", 368 375 'SearchableText': jamb_reg_no }) … … 370 377 em = 'Student with REG-NO %s already exists\n' % jamb_reg_no 371 378 logger.info(em) 372 no_import.append(em)379 jamb['Error'] = "Student exists" 373 380 no_import.append(format % jamb) 374 381 continue 375 cert_id = makeCertificateCode(jamb.get(csv_d['jamb_first_cos'])) 376 res = self.portal_catalog({'portal_type': "Certificate", 377 'id': cert_id }) 378 if len(res) < 1: 382 cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) 383 if cert_id not in certs.keys(): 379 384 em = 'No Certificate with ID %s \n' % cert_id 380 385 logger.info(em) 381 no_import.append(em)382 no_import.append( format % jamb)386 jamb['Error'] = "No Certificate %s" % cert_id 387 no_import.append( format % jamb) 383 388 continue 384 cert = res[0].getObject()385 c ert_path = res[0].getPath()386 c ert_doc = cert.getContent()389 cert_doc = certs[cert_id] 390 catalog_entry = {} 391 catalog_entry['jamb_reg_no'] = jamb_reg_no 387 392 jamb_name = jamb.get(csv_d['jamb_lastname']) 388 393 jamb_name.replace('>','') … … 398 403 except BadRequest: 399 404 sid = self.generateStudentId(letter) 405 catalog_entry['id'] = sid 400 406 tr_count += 1 401 407 logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) … … 413 419 'jamb_first_cos', 414 420 'jamb_sex', 415 #'jamb_state',416 #'jamb_first_cos',417 #'jamb_second_cos',421 'jamb_state', 422 'jamb_lga', 423 'app_email', 418 424 ) 419 425 for f in da_fields: 420 426 da[f] = jamb.get(csv_d[f]) 427 catalog_entry['email'] = jamb.get(csv_d['app_email']) 421 428 app = student.application 429 app_doc = app.getContent() 430 picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no) 431 #import pdb;pdb.set_trace() 432 if os.path.exists(picture): 433 file = open(picture) 434 img = PIL.Image.open(file) 435 img.thumbnail((150,200), 436 resample=PIL.Image.ANTIALIAS) 437 # We now need a buffer to write to. It can't be the same 438 # as the inbuffer as the PNG writer will write over itself. 439 outfile = StringIO() 440 img.save(outfile, format=img.format) 441 app_doc.manage_addFile('passport', 442 file=outfile, 443 title="%s.jpg" % jamb_reg_no) 422 444 app.getContent().edit(mapping=da) 423 445 app.manage_setLocalRoles(sid, ['Owner',]) … … 434 456 pume.manage_setLocalRoles(sid, ['Owner',]) 435 457 #student.getContent().createSubObjects() 436 names = jamb_name.split()437 458 dp = {} 438 459 if len(names) == 3: … … 442 463 elif len(names) == 2: 443 464 dp['firstname'] = names[0].capitalize() 465 dp['middlename'] = '' 444 466 dp['lastname'] = names[1].capitalize() 445 467 else: 468 dp['firstname'] = '' 469 dp['middlename'] = '' 446 470 dp['lastname'] = jamb_name 447 471 dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F' 472 catalog_entry['sex'] = dp['sex'] 473 catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp 448 474 student.invokeFactory('StudentPersonal','personal') 449 475 per = student.personal … … 482 508 for f in from_certificate: 483 509 dsc[f] = getattr(cert_doc,f) 484 cpl = cert_path.split('/') 485 dsc['faculty'] = cpl[-4] 486 dsc['department'] = cpl[-3] 510 dsc['faculty'] = jamb.get(csv_d['faculty']) 511 dsc['department'] = jamb.get(csv_d['department']) 512 catalog_entry['faculty'] = jamb.get(csv_d['faculty']) 513 catalog_entry['department'] = jamb.get(csv_d['department']) 514 catalog_entry['course'] = cert_id 515 catalog_entry['level'] = getattr(cert_doc,'start_level') 487 516 dsc['study_course'] = cert_id 488 dsc['entry_session'] = "2006/2007" #jamb.get(csv_d['session'])517 dsc['entry_session'] = jamb.get(csv_d['session']) 489 518 study_course.getContent().edit(mapping=dsc) 490 if tr_count > MAX_TRANS: 519 self.students_catalog.addRecord(**catalog_entry) 520 if tr_count > 1000: 491 521 if len(no_import) > 1: 492 522 open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write( -
WAeUP_SRP/trunk/WAeUPTables.py
r966 r971 178 178 InitializeClass(PumeResultsTable) 179 179 180 class StudentsCatalog(WAeUPTable): 181 182 meta_type = 'WAeUP Students Catalog' 183 name = "students_catalog" 184 key = "id" 185 def __init__(self): 186 WAeUPTable.__init__(self, 'students_catalog') 187 188 189 InitializeClass(StudentsCatalog) 190 180 191 # BBB: 181 192 AccomodationTable = AccommodationTable -
WAeUP_SRP/trunk/exportimport.py
r966 r971 100 100 importWAeUPTable(site.portal_pins, '', context,'pins') 101 101 importWAeUPTable(site.portal_pumeresults, '', context,'pumeresults') 102 importWAeUPTable(site.students_catalog, '', context,'students_catalog') 102 103 103 104 from Products.CPSCore.exportimport.catalog import CatalogToolXMLAdapter -
WAeUP_SRP/trunk/profiles/default/toolset.xml
r966 r971 7 7 <required tool_id="portal_pumeresults" 8 8 class="Products.WAeUP_SRP.WAeUPTables.PumeResultsTable"/> 9 <required tool_id="students_catalog" 10 class="Products.WAeUP_SRP.WAeUPTables.StudentsCatalog"/> 9 11 <required tool_id="waeup_tool" 10 12 class="Products.WAeUP_SRP.WAeUPTool.WAeUPTool"/> -
WAeUP_SRP/trunk/skins/waeup_student/getStudentInfo.py
r966 r971 34 34 student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id) 35 35 student = context.restrictedTraverse(student_path,default=None) 36 #from Products.zdb import set_trace 37 #set_trace() 38 36 39 if student is None or student.portal_type != 'Student': 37 40 return None -
WAeUP_SRP/trunk/skins/waeup_student/search_students.py
r966 r971 62 62 ob=default, 63 63 layout_mode='edit', 64 formaction="search_students" 64 formaction="search_students", 65 commit = False, 65 66 ) 66 67 if psm == '': … … 68 69 psm = psm, 69 70 #psm = "%s, %s" % (psm,ds), 70 students = items,71 students = [], 71 72 allowed = True, 72 73 ) … … 127 128 if res: 128 129 for r in res: 129 if r.portal_type in ("StudentStudyLevel",): 130 student = r.getObject().aq_parent.aq_parent 131 elif r.portal_type in student_subobjects: 132 student = r.getObject().aq_parent 133 else: 134 student = r.getObject() 135 search_set.append(student) 130 pl = r.getPath().split('/') 131 search_set.append(pl[pl.index('students') + 1]) 136 132 review_set = [] 137 133 if review_res: 138 134 for r in review_res: 139 if r.portal_type in ("StudentStudyLevel",): 140 student = r.getObject().aq_parent.aq_parent 141 elif r.portal_type in student_subobjects: 142 student = r.getObject().aq_parent 143 else: 144 student = r.getObject() 145 review_set.append(student) 135 pl = r.getPath().split('/') 136 review_set.append(pl[pl.index('students') + 1]) 146 137 all = [] 147 138 if only_review: … … 158 149 items.append(a) 159 150 students = [] 160 items.sort( cmp_id)151 items.sort() 161 152 co_view = False 162 153 if items: 163 154 for item in items: 164 155 #if context.isClearanceOfficer(info): 156 info = {} 165 157 if "ClearanceOfficers" in member.getGroups(): 166 158 co_view = True 167 droles = member.getRolesInContext(item)168 if "ClearanceOfficer" in droles:169 info = context.getStudentInfo(item)170 students.append(info)159 ## droles = member.getRolesInContext(item) 160 ## if "ClearanceOfficer" in droles: 161 ## info = context.getStudentInfo(item) 162 ## students.append(info) 171 163 else: 172 info = context.getStudentInfo(item) 173 students.append(info) 164 #info = context.getStudentInfo(item) 165 info = context.students_catalog(id = item) 166 if len(info) == 1: 167 students.append(info[0]) 174 168 175 169 return context.search_students_form(rendered = rend, -
WAeUP_SRP/trunk/skins/waeup_student/search_students_form.pt
r966 r971 55 55 <tr tal:condition="student" 56 56 tal:attributes="class python:test(repeat['student'].even(), 'even ajaxtd', 'odd ajaxtd')"> 57 <td><a href="id" tal:attributes="href string:${ student/student/absolute_url}"57 <td><a href="id" tal:attributes="href string:${context/portal_url}/campus/students/${student/id}" 58 58 tal:content="student/id"></a></td> 59 59 <td> 60 60 <span tal:replace="student/name" /> 61 61 </td> 62 <td><span tal:replace=" python: student['app_doc'].jamb_reg_no" /></td>62 <td><span tal:replace="student/jamb_reg_no" /></td> 63 63 <td tal:condition="options/co_view|nothing"> 64 64 <a href="id" … … 67 67 onclick="javascript:window.open('','edit','width=600, height=700, directories=no, toolbar=no, location=no, menubar=no, scrollbars=yes, status=no, resizable=no, dependent=no')" 68 68 >[change state]</a></td> 69 <td tal:condition=" not:options/co_view|nothing"><span tal:replace="student/review_state" /></td>69 <td tal:condition="options/co_view|nothing"><span tal:replace="student/review_state" /></td> 70 70 </tr> 71 71 </span>
Note: See TracChangeset for help on using the changeset viewer.