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

Last change on this file since 1712 was 1707, checked in by joachim, 18 years ago

new import function for createStudents,
catalog fields added

  • Property svn:keywords set to Id
File size: 2.2 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 1707 2007-04-25 11:58:39Z joachim $
11"""
12reindex students_catalog entry_mode index
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
20request = context.REQUEST
21session = request.SESSION
22response = request.RESPONSE
23setheader = request.RESPONSE.setHeader
24students = context.portal_url.getPortalObject().campus.students
25import logging
26logger = logging.getLogger('Skins.setNewEntryMode')
27
28def rwrite(s):
29    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
30    response.write("%s<br />\r\n" % s)
31
32brains = context.portal_catalog(portal_type = 'Student')
33count = 0
34commit_count = 0
35#set_trace()
36logger.info('setNewEntryMode start')
37for 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)
78rwrite('Done')
79logger.info('setNewEntryMode finish')
80
81
Note: See TracBrowser for help on using the repository browser.