[3159] | 1 | ## Script (Python) "ti_474_resolve" |
---|
[3155] | 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_474_resolve.py 3159 2008-02-13 20:13:28Z henrik $ |
---|
| 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 |
---|
[3159] | 27 | logger = logging.getLogger('Skins.ti_474_resolve') |
---|
[3155] | 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 | course_results = context.course_results |
---|
| 32 | aq_course_results = course_results.evalAdvancedQuery |
---|
| 33 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
| 34 | |
---|
| 35 | request = context.REQUEST |
---|
| 36 | session = request.SESSION |
---|
| 37 | response = request.RESPONSE |
---|
| 38 | setheader = request.RESPONSE.setHeader |
---|
| 39 | def rwrite(s): |
---|
| 40 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 41 | response.write("%s<br>\n\r" % s) |
---|
| 42 | course_results_to_change = [] |
---|
| 43 | logger.info('start') |
---|
[3159] | 44 | #set_trace() |
---|
[3155] | 45 | for result in course_results(): |
---|
| 46 | student_id,level_id,code = result.key.split('|') |
---|
| 47 | if result.student_id != student_id: |
---|
| 48 | d = {} |
---|
| 49 | d['key'] = result.key |
---|
| 50 | d['student_id'] = student_id |
---|
| 51 | d['level_id'] = level_id |
---|
| 52 | course = context.courses_catalog.getRecordByKey(result.code) |
---|
| 53 | d['credits'] = course.credits |
---|
| 54 | d['semester'] = course.semester |
---|
| 55 | d['session_id'] = '06' |
---|
| 56 | course_results_to_change += d, |
---|
| 57 | logger.info('found %d correctable results' % len(course_results_to_change)) |
---|
[3159] | 58 | #set_trace() |
---|
[3155] | 59 | for result in course_results_to_change: |
---|
| 60 | try: |
---|
| 61 | course_results.modifyRecord(**result) |
---|
[3159] | 62 | logger.info('correcting %(key)s' % result) |
---|
[3155] | 63 | except KeyError: |
---|
[3159] | 64 | #set_trace() |
---|
| 65 | logger.info('%(key)s not found there' % result) |
---|
| 66 | |
---|
[3155] | 67 | logger.info('finished') |
---|