[1833] | 1 | ## Script (Python) "ti_231_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_231_resolve.py 1833 2007-05-30 09:50:39Z joachim $ |
---|
| 11 | """ |
---|
| 12 | resolve ticket #231 |
---|
| 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_231_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_231 started') |
---|
| 39 | |
---|
| 40 | query = In('entry_mode',('DE','UME')) |
---|
| 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 | application = getattr(getattr(students,brain.id),'application') |
---|
| 49 | except: |
---|
| 50 | logger.info('application of %s not found' % brain.id) |
---|
| 51 | continue |
---|
| 52 | count += 1 |
---|
| 53 | application.getContent().edit(mapping={'entry_mode': '%s_ft' % brain.entry_mode.lower()}) |
---|
| 54 | try: |
---|
| 55 | study_course = getattr(getattr(students,brain.id),'study_course') |
---|
| 56 | except: |
---|
| 57 | logger.info('study_course of %s not found' % brain.id) |
---|
| 58 | continue |
---|
| 59 | study_course.getContent().edit(mapping={'current_mode': '%s_ft' % brain.entry_mode.lower()}) |
---|
| 60 | logger.info('%d of %d changed modes of %s from %s to %s_ft' % (count, |
---|
| 61 | total, |
---|
| 62 | brain.id, |
---|
| 63 | brain.entry_mode, |
---|
| 64 | brain.entry_mode.lower() |
---|
| 65 | )) |
---|
| 66 | if not count % commit_after: |
---|
| 67 | context.waeup_tool.doCommit() |
---|
| 68 | logger.info("committed %d transactions" % commit_after) |
---|
| 69 | logger.info('ti_231 finished for %d of %d' % (count,total)) |
---|