| 1 | ## Script (Python) "ti_513_resolve" |
|---|
| 2 | ##bind container=container |
|---|
| 3 | ##bind context=context |
|---|
| 4 | ##bind namespace= |
|---|
| 5 | ##bind script=script |
|---|
| 6 | ##bind subpath=traverse_subpath |
|---|
| 7 | ##parameters= |
|---|
| 8 | ##title= |
|---|
| 9 | ## |
|---|
| 10 | # $Id: ti_513_resolve.py 3371 2008-03-25 17:50:05Z joachim $ |
|---|
| 11 | """ |
|---|
| 12 | """ |
|---|
| 13 | try: |
|---|
| 14 | from Products.zdb import set_trace |
|---|
| 15 | except: |
|---|
| 16 | def set_trace(): |
|---|
| 17 | pass |
|---|
| 18 | |
|---|
| 19 | mtool = context.portal_membership |
|---|
| 20 | member = mtool.getAuthenticatedMember() |
|---|
| 21 | if str(member) not in ('admin','joachim'): |
|---|
| 22 | return |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | import logging |
|---|
| 26 | import DateTime |
|---|
| 27 | logger = logging.getLogger('Skins.ti_513_resolve') |
|---|
| 28 | from Products.AdvancedQuery import Eq, Between, Le,In |
|---|
| 29 | aq_students = context.students_catalog.evalAdvancedQuery |
|---|
| 30 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
|---|
| 31 | students_folder = context.portal_url.getPortalObject().campus.students |
|---|
| 32 | |
|---|
| 33 | request = context.REQUEST |
|---|
| 34 | session = request.SESSION |
|---|
| 35 | response = request.RESPONSE |
|---|
| 36 | setheader = request.RESPONSE.setHeader |
|---|
| 37 | count = 0 |
|---|
| 38 | found = 0 |
|---|
| 39 | commit_after = 100 |
|---|
| 40 | logger.info('start') |
|---|
| 41 | students = context.students_catalog() |
|---|
| 42 | wrong = {} |
|---|
| 43 | missing_courses = [] |
|---|
| 44 | wrong_starts = [] |
|---|
| 45 | for student in students: |
|---|
| 46 | count += 1 |
|---|
| 47 | if student.jamb_reg_no.endswith('/07'): |
|---|
| 48 | pos = 0 |
|---|
| 49 | if student.jamb_reg_no[:5].isalpha(): |
|---|
| 50 | pos = 5 |
|---|
| 51 | elif student.jamb_reg_no[:4].isalpha(): |
|---|
| 52 | if student.jamb_reg_no[:4] != 'UBNO': |
|---|
| 53 | pos = 4 |
|---|
| 54 | if pos: |
|---|
| 55 | d = {} |
|---|
| 56 | d['student_id'] = student.id |
|---|
| 57 | d['jamb_reg_no_old'] = student.jamb_reg_no |
|---|
| 58 | d['jamb_reg_no'] = student.jamb_reg_no[:3]+student.jamb_reg_no[pos:] |
|---|
| 59 | #set_trace() |
|---|
| 60 | if student.jamb_reg_no[:pos] not in wrong_starts: |
|---|
| 61 | wrong_starts += student.jamb_reg_no[:pos], |
|---|
| 62 | wrong[student.id] = d |
|---|
| 63 | logger.info('found %d wrong of %d' % (len(wrong),count)) |
|---|
| 64 | count = 0 |
|---|
| 65 | for student_id,d in wrong.items(): |
|---|
| 66 | try: |
|---|
| 67 | getattr(getattr(students_folder,student_id),'application').getContent().edit(mapping=d) |
|---|
| 68 | logger.info("%(student_id)s changed jamb_reg_no from %(jamb_reg_no_old)s to %(jamb_reg_no)s" % d) |
|---|
| 69 | except: |
|---|
| 70 | logger.info("%(student_id)s change failed") |
|---|
| 71 | if count and not count % commit_after: |
|---|
| 72 | context.waeup_tool.doCommit() |
|---|
| 73 | logger.info("committing %d of total %d" % (commit_after,count)) |
|---|
| 74 | count += 1 |
|---|
| 75 | logger.info('finished') |
|---|