1 | ## Script (Python) "reindex_entry_mode" |
---|
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 1704 2007-04-24 18:15:34Z 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 | |
---|
26 | def rwrite(s): |
---|
27 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
28 | response.write("%s<br />\r\n" % s) |
---|
29 | |
---|
30 | brains = context.portal_catalog(portal_type = 'Student') |
---|
31 | count = 0 |
---|
32 | #set_trace() |
---|
33 | for brain in brains: |
---|
34 | student_path = brain.getPath() |
---|
35 | sub_brains = context.portal_catalog(path = student_path) |
---|
36 | app_doc = None |
---|
37 | sc_doc = None |
---|
38 | for sb in sub_brains: |
---|
39 | if sb.getId == 'application': |
---|
40 | app_doc = sb.getObject().getContent() |
---|
41 | elif sb.getId == 'study_course': |
---|
42 | sc_doc = sb.getObject().getContent() |
---|
43 | if app_doc is None: |
---|
44 | continue |
---|
45 | em = getattr(app_doc,'entry_mode',None) |
---|
46 | new_em = "%s_ft" % em.lower() |
---|
47 | app_doc.edit(mapping={'entry_mode': new_em}) |
---|
48 | if sc_doc: |
---|
49 | sc_doc.edit(mapping={'current_mode': new_em}) |
---|
50 | count += 1 |
---|
51 | s = "%d: %s %s -> %s" % (count,brain.getPath(),em,new_em) |
---|
52 | rwrite(s) |
---|
53 | rwrite('Done') |
---|