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

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

student_study_level.xml: all fields read-only

admitStudents.py: change default value for entry_level

  • 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 5567 2010-10-14 06:10:25Z 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',):
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    brains = aq_applicants(In('status',('admitted'),))
41else:
42    brains = aq_applicants(In('status',('admitted'),) & Eq('entry_session',entry_session))
43
44total = len(brains)
45logger.info("found %d students" % (total))
46count = 0
47admitted = 0
48cocount = 0
49old_commit_count = 0
50commit_after = 40
51d = {'status': 'created'}
52reg_nos = [brain.reg_no for brain in brains]
53with_timing = False
54for reg_no in reg_nos:
55    count += 1
56    must_commit = (admitted != old_commit_count) and (not admitted % commit_after)
57    if must_commit:
58        old_commit_count = admitted
59        context.waeup_tool.doCommit()
60        logger.info("Committing %s transactions, total %s" % (commit_after,count))
61        cocount += 1
62        if with_timing and cocount > 2:
63            break
64    brain = aq_applicants(Eq('reg_no',reg_no))[0]
65    #logger.info("start creating  objects of student %s" % (brain.reg_no))
66    sid = d['student_id'] = context.waeup_tool.admitOneStudent(brain,
67                                                               entry_session,
68                                                               pin_password,
69                                                               with_timing = with_timing)
70
71    if sid is not None:
72        d['reg_no'] = reg_no
73        context.applicants_catalog.modifyRecord(**d)
74        logger.info("created objects of student %s with id %s" % (reg_no,sid))
75        if with_timing:
76            data = context.waeup_tool.get_timing_data()
77            for k,d in data.items():
78                s = "timing line %s" % k
79                s += " %(i_time)6.2f/%(a_time)6.2f" % d
80                logger.info(s)
81        admitted += 1
82    else:
83        logger.info("could not create objects of student %s with pin %s" % (reg_no,brain.pin))
84
85msg = "finished admitting %d students" % (admitted)
86logger.info(msg)
87#rwrite(msg)
88return
Note: See TracBrowser for help on using the repository browser.