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 3368 2008-03-21 17:50:50Z 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_507_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 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
32 | |
---|
33 | request = context.REQUEST |
---|
34 | session = request.SESSION |
---|
35 | response = request.RESPONSE |
---|
36 | setheader = request.RESPONSE.setHeader |
---|
37 | logger.info('start') |
---|
38 | count = 0 |
---|
39 | found = 0 |
---|
40 | commit_after = 100000 |
---|
41 | certificates = context.getCertificatesDict() |
---|
42 | students = context.students_catalog() |
---|
43 | wrong = [] |
---|
44 | missing_courses = [] |
---|
45 | wrong_modes = {} |
---|
46 | students_with_missing_courses = [] |
---|
47 | for student in students: |
---|
48 | count += 1 |
---|
49 | if student.mode and student.course: |
---|
50 | certificate = certificates.get(student.course,None) |
---|
51 | if certificate is None: |
---|
52 | students_with_missing_courses += student.id, |
---|
53 | if student.course not in missing_courses: |
---|
54 | missing_courses += student.course, |
---|
55 | #logger.info('missing course %s' % student.course) |
---|
56 | continue |
---|
57 | current_mode = student.mode |
---|
58 | study_mode = certificate.get('study_mode','xxx') |
---|
59 | if current_mode != study_mode: |
---|
60 | w_count = wrong_modes.get((current_mode,study_mode),0) |
---|
61 | if w_count == 0: |
---|
62 | logger.info('%s != %s' % (student.mode, |
---|
63 | study_mode)) |
---|
64 | w_count += 1 |
---|
65 | wrong_modes[(current_mode,study_mode)] = w_count |
---|
66 | wrong += student.id, |
---|
67 | if wrong and not (len(wrong) % commit_after): |
---|
68 | logger.info('found %d wrong of %d' % (len(wrong),count)) |
---|
69 | for k,v in wrong_modes.items(): |
---|
70 | logger.info('wrong mode %s counted %d' % (k,v)) |
---|
71 | logger.info('missing courses %s (%d counted)' % (', '.join(missing_courses),len(students_with_missing_courses))) |
---|
72 | logger.info('found %d wrong of %d' % (len(wrong),count)) |
---|