source: WAeUP_SRP/trunk/skins/waeup_student/admitStudents.py @ 5562

Last change on this file since 5562 was 5562, checked in by Henrik Bettermann, 14 years ago

Filter applicants by specifying the entry_session.

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