source: WAeUP_SRP/trunk/skins/waeup_utilities/setNewEntryMode.py @ 4062

Last change on this file since 4062 was 1715, checked in by joachim, 18 years ago

fix

  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
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"""
12reindex students_catalog entry_mode index
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19from Products.AdvancedQuery import Eq, Between, Le,In
20aq_students = context.students_catalog.evalAdvancedQuery
21
22request = context.REQUEST
23session = request.SESSION
24response = request.RESPONSE
25setheader = request.RESPONSE.setHeader
26#students = context.portal_url.getPortalObject().campus.students
27import logging
28logger = logging.getLogger('Skins.setNewEntryMode')
29
30def rwrite(s):
31    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
32    response.write("%s<br />\r\n" % s)
33
34brains = context.portal_catalog(portal_type = 'Student')
35count = 0
36commit_count = 0
37logger.info('setNewEntryMode start')
38#progress_log = context.waeup_tool.openLog('test')
39#context.waeup_tool.writeLog(progress_log,"Start \n")
40umede = aq_students(In('entry_mode',('DE','UME')))
41umede_ids = [r.id for r in umede]
42#set_trace()
43for 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)
88rwrite('Done')
89logger.info('setNewEntryMode finish')
90
91
Note: See TracBrowser for help on using the repository browser.