[1706] | 1 | ## Script (Python) "setNewEntryMode" |
---|
[1703] | 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: setNewEntryMode.py 1713 2007-04-26 05:04:59Z henrik $ |
---|
| 11 | """ |
---|
| 12 | reindex students_catalog entry_mode index |
---|
| 13 | """ |
---|
| 14 | try: |
---|
| 15 | from Products.zdb import set_trace |
---|
| 16 | except: |
---|
| 17 | def set_trace(): |
---|
| 18 | pass |
---|
| 19 | |
---|
| 20 | request = context.REQUEST |
---|
| 21 | session = request.SESSION |
---|
| 22 | response = request.RESPONSE |
---|
| 23 | setheader = request.RESPONSE.setHeader |
---|
| 24 | students = context.portal_url.getPortalObject().campus.students |
---|
[1707] | 25 | import logging |
---|
| 26 | logger = logging.getLogger('Skins.setNewEntryMode') |
---|
[1703] | 27 | |
---|
| 28 | def rwrite(s): |
---|
| 29 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 30 | response.write("%s<br />\r\n" % s) |
---|
| 31 | |
---|
[1704] | 32 | brains = context.portal_catalog(portal_type = 'Student') |
---|
[1703] | 33 | count = 0 |
---|
[1707] | 34 | commit_count = 0 |
---|
[1703] | 35 | #set_trace() |
---|
[1707] | 36 | logger.info('setNewEntryMode start') |
---|
[1703] | 37 | for brain in brains: |
---|
[1713] | 38 | if not brain.entry_mode in ('UME','DE'): |
---|
| 39 | continue |
---|
[1706] | 40 | stud_obj = brain.getObject() |
---|
[1713] | 41 | try: |
---|
[1706] | 42 | app_doc = stud_obj.application.getContent() |
---|
| 43 | except: |
---|
[1704] | 44 | continue |
---|
[1713] | 45 | try: |
---|
[1707] | 46 | sc_doc = stud_obj.study_course.getContent() |
---|
| 47 | except: |
---|
| 48 | sc_doc = None |
---|
[1703] | 49 | em = getattr(app_doc,'entry_mode',None) |
---|
[1707] | 50 | if em in ('ume_ft','de_ft'): |
---|
| 51 | new_em = em |
---|
| 52 | else: |
---|
| 53 | new_em = "%s_ft" % em.lower() |
---|
| 54 | if em in ('ume_ft','UME'): |
---|
| 55 | el = "100" |
---|
| 56 | elif em in ('de_ft','DE'): |
---|
| 57 | el = "200" |
---|
| 58 | app_doc.edit(mapping={'entry_mode': new_em, |
---|
| 59 | 'entry_level': el}) |
---|
| 60 | sid = brain.getId |
---|
[1704] | 61 | if sc_doc: |
---|
| 62 | sc_doc.edit(mapping={'current_mode': new_em}) |
---|
[1713] | 63 | context.students_catalog.modifyRecord(id = sid, |
---|
[1707] | 64 | mode=new_em, |
---|
| 65 | entry_mode=new_em, |
---|
| 66 | entry_level=el) |
---|
| 67 | else: |
---|
[1713] | 68 | context.students_catalog.modifyRecord(id = sid, |
---|
[1707] | 69 | entry_mode=new_em, |
---|
| 70 | entry_level=el) |
---|
[1713] | 71 | |
---|
[1703] | 72 | count += 1 |
---|
[1707] | 73 | commit_count += 1 |
---|
| 74 | if commit_count > 1000: |
---|
| 75 | context.waeup_tool.doCommit() |
---|
| 76 | logger.info('committing %d total %d' % (commit_count,count)) |
---|
| 77 | commit_count = 0 |
---|
[1704] | 78 | s = "%d: %s %s -> %s" % (count,brain.getPath(),em,new_em) |
---|
[1703] | 79 | rwrite(s) |
---|
| 80 | rwrite('Done') |
---|
[1707] | 81 | logger.info('setNewEntryMode finish') |
---|
[1706] | 82 | |
---|
| 83 | |
---|