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: reindex_entry_mode.py 1328 2007-01-19 18:16:32Z joachim $ |
---|
11 | """ |
---|
12 | reindex students_catalog entry_mode index |
---|
13 | """ |
---|
14 | request = context.REQUEST |
---|
15 | session = request.SESSION |
---|
16 | response = request.RESPONSE |
---|
17 | students = context.portal_url.getPortalObject().campus.students |
---|
18 | def rwrite(s): |
---|
19 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
20 | #response.setHeader('Content-length','%d' % (len(s))) |
---|
21 | #response.setStatus('OK') |
---|
22 | response.write(s) |
---|
23 | |
---|
24 | cat = context.students_catalog |
---|
25 | ems = cat.uniqueValuesFor('entry_mode') |
---|
26 | rwrite("entry_mode values: %s<br />\n" % (str(ems))) |
---|
27 | for em in ems: |
---|
28 | res = cat(entry_mode = em) |
---|
29 | rwrite("entry_mode: %s = %d<br />\n" % (em,len(res))) |
---|
30 | #from Products.zdb import set_trace;set_trace() |
---|
31 | sbrains = cat() |
---|
32 | count = 0 |
---|
33 | lc = 1 |
---|
34 | rwrite("%3d " % lc) |
---|
35 | for sb in sbrains: |
---|
36 | normalized = False |
---|
37 | em = context.getFromData_entry_mode(sb.id) |
---|
38 | ec = 'x' |
---|
39 | if em is None: |
---|
40 | ec = 'n' |
---|
41 | em = 'None' |
---|
42 | if em in ('UME','DE'): |
---|
43 | ec = 'C' |
---|
44 | normalized = True |
---|
45 | elif sb.entry_mode in ('DIRECT', 'DIRECT ENTRY',): |
---|
46 | ec = 'D' |
---|
47 | em = 'DE' |
---|
48 | normalized = True |
---|
49 | elif sb.entry_mode in ('U.M.E', 'UNE',): |
---|
50 | ec = 'U' |
---|
51 | em ="UME" |
---|
52 | normalized = True |
---|
53 | elif not sb.entry_mode: |
---|
54 | ec = 'u' |
---|
55 | em ="UME" |
---|
56 | normalized = True |
---|
57 | if ec != "C" and em != sb.entry_mode: |
---|
58 | #from Products.zdb import set_trace;set_trace() |
---|
59 | app = getattr(getattr(students,sb.id),'application',None) |
---|
60 | ec = 'a' |
---|
61 | if app is not None: |
---|
62 | ec = 'A' |
---|
63 | app.getContent().edit(mapping={'entry_mode': sb.entry_mode}) |
---|
64 | if normalized: |
---|
65 | cat.modifyRecord(id = sb.id, |
---|
66 | entry_mode = em) |
---|
67 | rwrite(ec) |
---|
68 | count += 1 |
---|
69 | if count > 60: |
---|
70 | lc += 1 |
---|
71 | rwrite("<br />\n%3d " % lc) |
---|
72 | count = 0 |
---|
73 | |
---|