1 | ## Script (Python) "ti_71fc_resolve_fix" |
---|
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_71fc_resolve_fix.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 |
---|
27 | logger = logging.getLogger('Skins.ti_71fc_resolve_fix') |
---|
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 | levels_to_look_for = ("110","210") |
---|
43 | course_results_to_change = [] |
---|
44 | for result in course_results(): |
---|
45 | student_id,level_id,code = result.key.split('|') |
---|
46 | if code != result.code: |
---|
47 | d = {} |
---|
48 | for field in course_results.schema(): |
---|
49 | d[field] = getattr(result,field) |
---|
50 | d['old_key'] = d['key'] |
---|
51 | d['key'] = "%s|%s|%s" % (student_id,result.level_id,result.code) |
---|
52 | course_results_to_change += d, |
---|
53 | for result in course_results_to_change: |
---|
54 | try: |
---|
55 | course_results.addRecord(**result) |
---|
56 | logger.info('%(student_id)s adding %(key)s' % result) |
---|
57 | except ValueError: |
---|
58 | set_trace() |
---|
59 | logger.info('%(student_id)s %(key)s already there' % result) |
---|
60 | logger.info('%(student_id)s deleting %(old_key)s' % result) |
---|
61 | course_results.deleteRecord(result['old_key']) |
---|
62 | |
---|
63 | logger.info('finished') |
---|