| 1 | ## Script (Python) "fix06Verdict" |
|---|
| 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: fixReturningSession.py 2456 2007-10-28 07:09:46Z henrik $ |
|---|
| 11 | """ |
|---|
| 12 | """ |
|---|
| 13 | try: |
|---|
| 14 | from Products.zdb import set_trace |
|---|
| 15 | except: |
|---|
| 16 | def set_trace(): |
|---|
| 17 | pass |
|---|
| 18 | import logging |
|---|
| 19 | logger = logging.getLogger('Skins.fix06Verdict') |
|---|
| 20 | from Products.AdvancedQuery import Eq, Between, Le,In |
|---|
| 21 | aq_students = context.students_catalog.evalAdvancedQuery |
|---|
| 22 | |
|---|
| 23 | request = context.REQUEST |
|---|
| 24 | session = request.SESSION |
|---|
| 25 | response = request.RESPONSE |
|---|
| 26 | setheader = request.RESPONSE.setHeader |
|---|
| 27 | students = context.portal_url.getPortalObject().campus.students |
|---|
| 28 | #from string import Template |
|---|
| 29 | #def rwrite(s): |
|---|
| 30 | # response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
|---|
| 31 | # response.write("%s<br>\n\r" % s) |
|---|
| 32 | |
|---|
| 33 | #logger.info('') |
|---|
| 34 | |
|---|
| 35 | query = ~ Eq('verdict','N/A') & ~ Eq('verdict','') & In('session',('2006/2007','06','6')) |
|---|
| 36 | brains = aq_students(query) |
|---|
| 37 | total = len(brains) |
|---|
| 38 | logger.info('started editing %d students with session 06 and non-empty verdict' % total) |
|---|
| 39 | count = 0 |
|---|
| 40 | commit_after = 100 |
|---|
| 41 | |
|---|
| 42 | for brain in brains: |
|---|
| 43 | count += 1 |
|---|
| 44 | if count and not count % commit_after: |
|---|
| 45 | context.waeup_tool.doCommit() |
|---|
| 46 | logger.info("Committing %s transactions, total %s" % (commit_after,count)) |
|---|
| 47 | try: |
|---|
| 48 | study_course_doc = getattr(getattr(students,brain.id),'study_course').getContent() |
|---|
| 49 | |
|---|
| 50 | # final fix |
|---|
| 51 | if brain.matric_no: |
|---|
| 52 | verdict = study_course_doc.current_verdict |
|---|
| 53 | else: |
|---|
| 54 | verdict = '' |
|---|
| 55 | study_course_doc.edit(mapping = { "current_verdict": '', |
|---|
| 56 | "previous_verdict": verdict}) |
|---|
| 57 | |
|---|
| 58 | # Info: The logging message is wrong if not matric_no |
|---|
| 59 | logger.info("Current verdict of %s (%s, %s, %s, %s) moved to previous verdict" % (brain.id, |
|---|
| 60 | brain.matric_no, |
|---|
| 61 | brain.name, |
|---|
| 62 | brain.review_state, |
|---|
| 63 | brain.verdict, |
|---|
| 64 | )) |
|---|
| 65 | except: |
|---|
| 66 | #rwrite('>>>> not found %s study_course' % (brain.id)) |
|---|
| 67 | pass |
|---|
| 68 | logger.info('finished editing %d students' % total) |
|---|
| 69 | |
|---|
| 70 | return |
|---|