[3397] | 1 | ## Script (Python) "ti_115fc_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_115fc_resolve.py 3397 2008-03-31 10:07:17Z 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_115fc_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 | students = context.students_catalog() |
---|
| 45 | total = len(students) |
---|
| 46 | logger.info('started for %d students' % total) |
---|
| 47 | wrong_count = 0 |
---|
| 48 | count = 0 |
---|
| 49 | commit_after = 10000 |
---|
| 50 | #set_trace() |
---|
| 51 | for student in students: |
---|
| 52 | count += 1 |
---|
| 53 | if not count % commit_after: |
---|
| 54 | logger.info('found %d wrong of %d searched total %d' % (wrong_count,count,total)) |
---|
| 55 | levels = context.getLevelsFromCourseResults(student.id) |
---|
| 56 | for level in levels: |
---|
| 57 | if int(level) % 100: |
---|
| 58 | logger.info('%s invalid level in course_results %s' % (student.id,','.join(levels))) |
---|
| 59 | study_course = getattr(getattr(students_folder,student.id),'study_course',None) |
---|
| 60 | if study_course is None: |
---|
| 61 | wrong_count += 1 |
---|
| 62 | logger.info('%s no study_course object but %s levels' % (student.id,','.join(levels))) |
---|
| 63 | continue |
---|
| 64 | existing_levels = study_course.objectIds() |
---|
| 65 | different = [l for l in levels if l not in existing_levels] |
---|
| 66 | if different: |
---|
| 67 | wrong_count += 1 |
---|
| 68 | logger.info("%s levels %s in course_results and %s existing levels %d of %d checked %d wrong" % (student.id, |
---|
| 69 | ",".join(levels), |
---|
| 70 | ",".join(existing_levels), |
---|
| 71 | count, |
---|
| 72 | total, |
---|
| 73 | wrong_count, |
---|
| 74 | )) |
---|
| 75 | # if count > 10: |
---|
| 76 | # break |
---|
| 77 | # set_trace() |
---|
| 78 | logger.info('found %d' % wrong_count) |
---|
| 79 | logger.info('finished') |
---|