source: WAeUP_SRP/base/skins/waeup_student/admitStudents.py @ 3349

Last change on this file since 3349 was 3349, checked in by joachim, 17 years ago

include timing functions,
to enable set with_timing to True

  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1## Script (Python) "admitStudents"
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: admitStudents.py 3349 2008-03-18 17:54:22Z joachim $
11"""
12"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18
19mtool = context.portal_membership
20member = mtool.getAuthenticatedMember()
21if str(member) not in ('admin','joachim'):
22    return
23
24entry_session = '07'
25pin_password = False
26
27import logging
28import DateTime
29logger = logging.getLogger('Skins.admitStudents')
30from Products.AdvancedQuery import Eq, Between, Le,In
31aq_applicants = context.applicants_catalog.evalAdvancedQuery
32request = context.REQUEST
33session = request.SESSION
34response = request.RESPONSE
35setheader = request.RESPONSE.setHeader
36def rwrite(s):
37    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
38    response.write("%s<br>\n\r" % s)
39
40brains = aq_applicants(In('status',('admitted'),))
41total = len(brains)
42logger.info("found %d students" % (total))
43count = 0
44admitted = 0
45cocount = 0
46old_commit_count = -1
47commit_after = 40
48d = {'status': 'created'}
49reg_nos = [brain.reg_no for brain in brains]
50with_timing = True
51for reg_no in reg_nos:
52    count += 1
53    must_commit = (admitted != old_commit_count) and (not admitted % commit_after)
54    if must_commit:
55        old_commit_count = admitted
56        context.waeup_tool.doCommit()
57        logger.info("Committing %s transactions, total %s" % (commit_after,count))
58        cocount += 1
59        if cocount > 2:
60            break
61    brain = aq_applicants(Eq('reg_no',reg_no))[0]
62    #logger.info("start creating  objects of student %s" % (brain.reg_no))
63    sid = d['student_id'] = context.waeup_tool.admitOneStudent(brain,
64                                                               entry_session,
65                                                               pin_password,
66                                                               with_timing = with_timing)
67       
68    if sid is not None:
69        d['reg_no'] = reg_no
70        context.applicants_catalog.modifyRecord(**d)
71        logger.info("created objects of student %s with id %s" % (reg_no,sid))
72        if with_timing:
73            data = context.waeup_tool.get_timing_data()
74            logger.info("timing %(i_time)6.2f/%(a_time)6.2f" % data['total'])
75        admitted += 1
76    else:
77        logger.info("could not create objects of student %s with pin %s" % (reg_no,brain.pin))
78
79msg = "finished admitting %d students" % (admitted)
80logger.info(msg)
81#rwrite(msg)
82return
Note: See TracBrowser for help on using the repository browser.