1 | ## Script (Python) "ti_112fc_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_112fc_resolve.py 3370 2008-03-25 13:20:19Z 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_112fc_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 | 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 | results = course_results() |
---|
43 | inconsistent = {} |
---|
44 | student_ids = [] |
---|
45 | count = 0 |
---|
46 | for result in results: |
---|
47 | d = {} |
---|
48 | d['student_id'],d['level_id'],d['code'] = result.key.split('|') |
---|
49 | not_equal = [] |
---|
50 | for attr in ('student_id','level_id','code'): |
---|
51 | if d[attr] != getattr(result,attr,''): |
---|
52 | not_equal += attr, |
---|
53 | if not_equal: |
---|
54 | if d['student_id'] not in student_ids: |
---|
55 | student_ids += d['student_id'], |
---|
56 | #logger.info('%s has inconsistent data for %s' % (result.key,",".join(not_equal))) |
---|
57 | inconsistent[result.key] = d |
---|
58 | count += 1 |
---|
59 | #set_trace() |
---|
60 | logger.info("found %d students with %d inconsistent results" % (len(student_ids),len(inconsistent))) |
---|
61 | student_id = '' |
---|
62 | for key,d in inconsistent.items(): |
---|
63 | if d['student_id'] != student_id: |
---|
64 | student_id = d['student_id'] |
---|
65 | logger.info('fixing course_results for student %s' % student_id) |
---|
66 | d['key'] = key |
---|
67 | course_results.modifyRecord(**d) |
---|
68 | logger.info("fixed %d students with %d inconsistent results" % (len(student_ids),len(inconsistent))) |
---|
69 | logger.info('finished') |
---|