1 | ## Script (Python) "setNewEntryMode" |
---|
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 1707 2007-04-25 11:58:39Z joachim $ |
---|
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 |
---|
25 | import logging |
---|
26 | logger = logging.getLogger('Skins.setNewEntryMode') |
---|
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 | |
---|
32 | brains = context.portal_catalog(portal_type = 'Student') |
---|
33 | count = 0 |
---|
34 | commit_count = 0 |
---|
35 | #set_trace() |
---|
36 | logger.info('setNewEntryMode start') |
---|
37 | for brain in brains: |
---|
38 | stud_obj = brain.getObject() |
---|
39 | try: |
---|
40 | app_doc = stud_obj.application.getContent() |
---|
41 | except: |
---|
42 | continue |
---|
43 | try: |
---|
44 | sc_doc = stud_obj.study_course.getContent() |
---|
45 | except: |
---|
46 | sc_doc = None |
---|
47 | em = getattr(app_doc,'entry_mode',None) |
---|
48 | if em in ('ume_ft','de_ft'): |
---|
49 | new_em = em |
---|
50 | else: |
---|
51 | new_em = "%s_ft" % em.lower() |
---|
52 | if em in ('ume_ft','UME'): |
---|
53 | el = "100" |
---|
54 | elif em in ('de_ft','DE'): |
---|
55 | el = "200" |
---|
56 | app_doc.edit(mapping={'entry_mode': new_em, |
---|
57 | 'entry_level': el}) |
---|
58 | sid = brain.getId |
---|
59 | if sc_doc: |
---|
60 | sc_doc.edit(mapping={'current_mode': new_em}) |
---|
61 | context.students_catalog.modifyRecord(id = sid, |
---|
62 | mode=new_em, |
---|
63 | entry_mode=new_em, |
---|
64 | entry_level=el) |
---|
65 | else: |
---|
66 | context.students_catalog.modifyRecord(id = sid, |
---|
67 | entry_mode=new_em, |
---|
68 | entry_level=el) |
---|
69 | |
---|
70 | count += 1 |
---|
71 | commit_count += 1 |
---|
72 | if commit_count > 1000: |
---|
73 | context.waeup_tool.doCommit() |
---|
74 | logger.info('committing %d total %d' % (commit_count,count)) |
---|
75 | commit_count = 0 |
---|
76 | s = "%d: %s %s -> %s" % (count,brain.getPath(),em,new_em) |
---|
77 | rwrite(s) |
---|
78 | rwrite('Done') |
---|
79 | logger.info('setNewEntryMode finish') |
---|
80 | |
---|
81 | |
---|