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

Last change on this file since 1713 was 1713, checked in by Henrik Bettermann, 18 years ago

this fix takes 10 hours, thus we have to run it several times and check if records have already been changed

  • Property svn:keywords set to Id
File size: 2.3 KB
RevLine 
[1706]1## Script (Python) "setNewEntryMode"
[1703]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 1713 2007-04-26 05:04:59Z henrik $
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
[1707]25import logging
26logger = logging.getLogger('Skins.setNewEntryMode')
[1703]27
28def rwrite(s):
29    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
30    response.write("%s<br />\r\n" % s)
31
[1704]32brains = context.portal_catalog(portal_type = 'Student')
[1703]33count = 0
[1707]34commit_count = 0
[1703]35#set_trace()
[1707]36logger.info('setNewEntryMode start')
[1703]37for brain in brains:
[1713]38    if not brain.entry_mode in ('UME','DE'):
39        continue
[1706]40    stud_obj = brain.getObject()
[1713]41    try:
[1706]42        app_doc = stud_obj.application.getContent()
43    except:
[1704]44        continue
[1713]45    try:
[1707]46        sc_doc = stud_obj.study_course.getContent()
47    except:
48        sc_doc = None
[1703]49    em = getattr(app_doc,'entry_mode',None)
[1707]50    if em in ('ume_ft','de_ft'):
51        new_em = em
52    else:
53        new_em = "%s_ft" % em.lower()
54    if em in ('ume_ft','UME'):
55        el = "100"
56    elif em in ('de_ft','DE'):
57        el = "200"
58    app_doc.edit(mapping={'entry_mode': new_em,
59                          'entry_level': el})
60    sid = brain.getId
[1704]61    if sc_doc:
62        sc_doc.edit(mapping={'current_mode': new_em})
[1713]63        context.students_catalog.modifyRecord(id = sid,
[1707]64                                              mode=new_em,
65                                              entry_mode=new_em,
66                                              entry_level=el)
67    else:
[1713]68        context.students_catalog.modifyRecord(id = sid,
[1707]69                                              entry_mode=new_em,
70                                              entry_level=el)
[1713]71
[1703]72    count += 1
[1707]73    commit_count += 1
74    if commit_count > 1000:
75        context.waeup_tool.doCommit()
76        logger.info('committing %d total %d' % (commit_count,count))
77        commit_count = 0
[1704]78    s = "%d: %s %s -> %s" % (count,brain.getPath(),em,new_em)
[1703]79    rwrite(s)
80rwrite('Done')
[1707]81logger.info('setNewEntryMode finish')
[1706]82
83
Note: See TracBrowser for help on using the repository browser.