source: WAeUP_SRP/trunk/skins/waeup_utilities/ti_507_resolve.py @ 3778

Last change on this file since 3778 was 3778, checked in by Henrik Bettermann, 16 years ago

resolve FCEOkene ticket #131

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1## Script (Python) "ti_507_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_507_resolve.py 3778 2008-11-20 06:37:12Z henrik $
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
24import logging
25import DateTime
26logger = logging.getLogger('Skins.ti_507_resolve')
27from Products.AdvancedQuery import Eq, Between, Le,In
28aq_students = context.students_catalog.evalAdvancedQuery
29aq_portal = context.portal_catalog_real.evalAdvancedQuery
30students_folder = context.portal_url.getPortalObject().campus.students
31
32request = context.REQUEST
33session = request.SESSION
34response = request.RESPONSE
35setheader = request.RESPONSE.setHeader
36logger.info('start')
37count = 0
38found = 0
39commit_after = 1000
40certificates = context.getCertificatesDict()
41students = context.students_catalog()
42wrong = {}
43missing_courses = []
44wrong_modes = {}
45students_with_missing_courses = []
46for student in students:
47    count += 1
48    if student.mode and student.course:
49        certificate = certificates.get(student.course,None)
50        if certificate is None:
51            students_with_missing_courses += student.id,
52            if student.course not in missing_courses:
53                missing_courses += student.course,
54                #logger.info('missing course %s' % student.course)
55            continue
56        current_mode = student.mode
57        study_mode = certificate.get('study_mode','xxx')
58        if current_mode != study_mode:
59            w_count =  wrong_modes.get((current_mode,study_mode),0)
60            #if w_count == 0:
61            #    logger.info('%s != %s' % (student.mode,
62            #                              study_mode))
63            w_count += 1
64            wrong_modes[(current_mode,study_mode)] = w_count
65            d = {}
66            d['student_id'] = student.id
67            d['current_mode'] = study_mode
68            d['current_mode_old'] = current_mode
69            d['study_course'] = student.course
70            d['matric_no'] = student.matric_no
71            wrong[student.id] = d
72            if (student.mode,study_mode) not in (('ume_ft', 'ug_ft'),('de_pt', 'ug_pt'),('de_ft', 'ug_ft')):
73                logger.info("; %(student_id)s;  %(matric_no)s ; %(study_course)s ; %(current_mode_old)s ; %(current_mode)s" % d)
74    # if wrong and not (len(wrong) % commit_after):
75    #     logger.info('found %d wrong of %d' % (len(wrong),count))
76for k,v in wrong_modes.items():
77    logger.info('wrong mode %s counted %d' % (k,v))
78logger.info('missing courses %s (%d counted)' % (', '.join(missing_courses),len(students_with_missing_courses)))
79logger.info('found %d wrong of %d' % (len(wrong),count))
80count = 0
81
82return
83
84for student_id,d in wrong.items():
85    #set_trace()
86    try:
87        getattr(getattr(students_folder,student_id),'study_course').getContent().edit(mapping=d)
88        failed = False
89    except:
90        failed = True
91    if failed:
92        logger.info("%(student_id)s change failed")
93    else:
94        logger.info("%(student_id)s changed current_mode from %(current_mode_old)s to %(current_mode)s" % d)
95    if count and not count % commit_after:
96        context.waeup_tool.doCommit()
97        logger.info("committing %d of total %d" % (commit_after,count))
98    count += 1
Note: See TracBrowser for help on using the repository browser.