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