source: WAeUP_SRP/base/skins/waeup_utilities/ti_112fc_resolve.py @ 3411

Last change on this file since 3411 was 3370, checked in by joachim, 17 years ago

fix incosistent course-results for #112 okene

  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
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"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18
19mtool = context.portal_membership
20member = mtool.getAuthenticatedMember()
21if str(member) not in ('admin','joachim'):
22    return
23
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.ti_112fc_resolve')
28from Products.AdvancedQuery import Eq, Between, Le,In
29aq_students = context.students_catalog.evalAdvancedQuery
30aq_portal = context.portal_catalog_real.evalAdvancedQuery
31course_results = context.course_results
32aq_course_results = course_results.evalAdvancedQuery
33students_folder = context.portal_url.getPortalObject().campus.students
34
35request = context.REQUEST
36session = request.SESSION
37response = request.RESPONSE
38setheader = request.RESPONSE.setHeader
39def rwrite(s):
40    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
41    response.write("%s<br>\n\r" % s)
42results = course_results()
43inconsistent = {}
44student_ids = []   
45count = 0
46for 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()
60logger.info("found %d students with %d inconsistent results" % (len(student_ids),len(inconsistent)))
61student_id = ''
62for 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)
68logger.info("fixed %d students with %d inconsistent results" % (len(student_ids),len(inconsistent)))
69logger.info('finished')
Note: See TracBrowser for help on using the repository browser.