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

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

fix

  • Property svn:keywords set to Id
File size: 2.6 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 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
[1714]19from Products.AdvancedQuery import Eq, Between, Le,In
20aq_students = context.students_catalog.evalAdvancedQuery
[1703]21
22request = context.REQUEST
23session = request.SESSION
24response = request.RESPONSE
25setheader = request.RESPONSE.setHeader
[1714]26#students = context.portal_url.getPortalObject().campus.students
[1707]27import logging
28logger = logging.getLogger('Skins.setNewEntryMode')
[1703]29
30def rwrite(s):
31    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
32    response.write("%s<br />\r\n" % s)
33
[1704]34brains = context.portal_catalog(portal_type = 'Student')
[1703]35count = 0
[1707]36commit_count = 0
37logger.info('setNewEntryMode start')
[1714]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')))
[1715]41umede_ids = [r.id for r in umede]
42#set_trace()
[1703]43for brain in brains:
[1714]44    if brain.getId not in umede_ids:
[1713]45        continue
[1706]46    stud_obj = brain.getObject()
[1713]47    try:
[1706]48        app_doc = stud_obj.application.getContent()
49    except:
[1704]50        continue
[1714]51    em = getattr(app_doc,'entry_mode',None)
52    if em not in ('UME','DE'):
53        continue
[1713]54    try:
[1707]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
[1704]69    if sc_doc:
70        sc_doc.edit(mapping={'current_mode': new_em})
[1713]71        context.students_catalog.modifyRecord(id = sid,
[1707]72                                              mode=new_em,
73                                              entry_mode=new_em,
74                                              entry_level=el)
75    else:
[1713]76        context.students_catalog.modifyRecord(id = sid,
[1707]77                                              entry_mode=new_em,
78                                              entry_level=el)
[1713]79
[1703]80    count += 1
[1707]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
[1704]86    s = "%d: %s %s -> %s" % (count,brain.getPath(),em,new_em)
[1703]87    rwrite(s)
88rwrite('Done')
[1707]89logger.info('setNewEntryMode finish')
[1706]90
91
Note: See TracBrowser for help on using the repository browser.