[2502] | 1 | ## Script (Python) "ti_385_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: moveCourseResults.py 2737 2007-11-22 09:53:21Z 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.moveCourseResults') |
---|
| 28 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
[2737] | 29 | aq_results = context.course_results.evalAdvancedQuery |
---|
[2502] | 30 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
| 31 | students = context.portal_url.getPortalObject().campus.students |
---|
| 32 | request = context.REQUEST |
---|
| 33 | session = request.SESSION |
---|
| 34 | response = request.RESPONSE |
---|
| 35 | setheader = request.RESPONSE.setHeader |
---|
[2508] | 36 | #def rwrite(s): |
---|
| 37 | # response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 38 | # response.write("%s<br>\n\r" % s) |
---|
[2502] | 39 | |
---|
| 40 | #logger.info('') |
---|
| 41 | |
---|
[2737] | 42 | brains = aq_students(In('review_state',('school_fee_paid','courses_registered','courses_validated'))) |
---|
[2502] | 43 | total = len(brains) |
---|
| 44 | logger.info("found %d students" % (total)) |
---|
| 45 | count = 0 |
---|
| 46 | moved = 0 |
---|
| 47 | cocount = 0 |
---|
[2513] | 48 | commit_after = 20 |
---|
[2736] | 49 | #moved_sids = context.course_results.uniqueValuesFor('student_id') |
---|
[2502] | 50 | for brain in brains: |
---|
[2516] | 51 | count += 1 |
---|
[2736] | 52 | #if brain.id in moved_sids: |
---|
| 53 | # continue |
---|
[2502] | 54 | try: |
---|
| 55 | study_level = getattr(getattr(getattr(students,brain.id), |
---|
| 56 | "study_course") |
---|
| 57 | ,brain.level) |
---|
| 58 | results = study_level.objectIds() |
---|
| 59 | except: |
---|
[2508] | 60 | #rwrite('not found %s/study_course/%s' % (brain.id,brain.level)) |
---|
[2502] | 61 | continue |
---|
| 62 | if not results: |
---|
[2737] | 63 | if not count % 100: |
---|
| 64 | logger.info("%s students searched" % (count)) |
---|
[2513] | 65 | continue |
---|
[2508] | 66 | #rwrite('no result objects in %s/study_course/%s' % (brain.id,brain.level)) |
---|
[2502] | 67 | else: |
---|
[2513] | 68 | #logger.info("moving results of student %s" % (brain.id)) |
---|
[2502] | 69 | context.course_results.moveResultsHere(study_level,brain.id) |
---|
| 70 | moved += 1 |
---|
[2516] | 71 | logger.info("moved results of student %s" % (brain.id)) |
---|
[2513] | 72 | if moved and not moved % commit_after: |
---|
| 73 | context.waeup_tool.doCommit() |
---|
| 74 | logger.info("Committing %s transactions, total %s" % (commit_after,count)) |
---|
[2602] | 75 | #cocount += 1 |
---|
| 76 | #if cocount > 2: |
---|
| 77 | # break |
---|
[2513] | 78 | |
---|
| 79 | msg = "finished moving results of %d students" % (moved) |
---|
[2502] | 80 | logger.info(msg) |
---|
[2508] | 81 | #rwrite(msg) |
---|
[2507] | 82 | |
---|
[2508] | 83 | |
---|