[1879] | 1 | ## Script (Python) "ti_229_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_229_resolve.py 1881 2007-06-12 08:03:32Z henrik $ |
---|
| 11 | """ |
---|
| 12 | resolve ticket #229 |
---|
| 13 | """ |
---|
| 14 | try: |
---|
| 15 | from Products.zdb import set_trace |
---|
| 16 | except: |
---|
| 17 | def set_trace(): |
---|
| 18 | pass |
---|
| 19 | import logging |
---|
| 20 | #>>>>>>>>>>>>>>>>< |
---|
| 21 | logger = logging.getLogger('Skins.ti_229_resolve') |
---|
| 22 | # logger.info('already done on by joachim') |
---|
| 23 | # return |
---|
| 24 | #<<<<<<<<<<<<<<<<< |
---|
| 25 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 26 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
| 27 | |
---|
| 28 | request = context.REQUEST |
---|
| 29 | session = request.SESSION |
---|
| 30 | response = request.RESPONSE |
---|
| 31 | setheader = request.RESPONSE.setHeader |
---|
| 32 | students = context.portal_url.getPortalObject().campus.students |
---|
| 33 | #from string import Template |
---|
| 34 | def rwrite(s): |
---|
| 35 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 36 | response.write("%s<br>\n\r" % s) |
---|
| 37 | |
---|
| 38 | logger.info('ti_229 started') |
---|
| 39 | |
---|
[1881] | 40 | query = In('level',(0,'')) |
---|
[1879] | 41 | brains = aq_students(query) |
---|
| 42 | total = len(brains) |
---|
| 43 | logger.info('found %d students' % total) |
---|
| 44 | count = 0 |
---|
| 45 | commit_after = 5 |
---|
| 46 | for brain in brains: |
---|
| 47 | try: |
---|
| 48 | study_course = getattr(getattr(students,brain.id),'study_course') |
---|
| 49 | except: |
---|
| 50 | logger.info('study_course of %s not found' % brain.id) |
---|
| 51 | continue |
---|
| 52 | s_results = context.results_import(matric_no = brain.matric_no) |
---|
| 53 | if s_results: |
---|
[1881] | 54 | lnr = context.getLevelFromResultsCosCode(s_results) |
---|
[1879] | 55 | level = "%d00" % lnr |
---|
[1881] | 56 | verdict,eligible = context.getVerdict(s_results[0].Verdict) |
---|
[1879] | 57 | if eligible: |
---|
| 58 | level = "%d00" % (lnr + 1) |
---|
| 59 | else: |
---|
| 60 | logger.info('matric_no %s not found in results_import' % brain.matric_no) |
---|
| 61 | continue |
---|
[1881] | 62 | count += 1 |
---|
| 63 | |
---|
[1879] | 64 | study_course.getContent().edit(mapping={'current_level': level, |
---|
| 65 | 'current_verdict': verdict, |
---|
| 66 | } |
---|
| 67 | ) |
---|
[1881] | 68 | logger.info('%d of %d changed level/verdict of %s to %s/%s' % (count, |
---|
[1879] | 69 | total, |
---|
| 70 | brain.id, |
---|
| 71 | level, |
---|
| 72 | verdict, |
---|
| 73 | )) |
---|
| 74 | if not count % commit_after: |
---|
| 75 | context.waeup_tool.doCommit() |
---|
| 76 | logger.info("committed %d transactions" % commit_after) |
---|
| 77 | logger.info('ti_229 finished for %d of %d' % (count,total)) |
---|
[1881] | 78 | return |
---|