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

Last change on this file since 14656 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
RevLine 
[2540]1## Script (Python) "admitStudents"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
[5562]7##parameters=entry_session=''
[2540]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()
[5563]21if str(member) not in ('admin',):
[2540]22    return
23
[2576]24pin_password = False
[2540]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
[5562]39if not entry_session:
[5567]40    brains = aq_applicants(In('status',('admitted'),))
41else:
42    brains = aq_applicants(In('status',('admitted'),) & Eq('entry_session',entry_session))
[5562]43
[2540]44total = len(brains)
45logger.info("found %d students" % (total))
46count = 0
47admitted = 0
48cocount = 0
[3350]49old_commit_count = 0
[3349]50commit_after = 40
[2540]51d = {'status': 'created'}
52reg_nos = [brain.reg_no for brain in brains]
[3351]53with_timing = False
[2540]54for reg_no in reg_nos:
55    count += 1
[3349]56    must_commit = (admitted != old_commit_count) and (not admitted % commit_after)
57    if must_commit:
58        old_commit_count = admitted
[2540]59        context.waeup_tool.doCommit()
60        logger.info("Committing %s transactions, total %s" % (commit_after,count))
[3339]61        cocount += 1
[3350]62        if with_timing and cocount > 2:
[3349]63            break
[2540]64    brain = aq_applicants(Eq('reg_no',reg_no))[0]
65    #logger.info("start creating  objects of student %s" % (brain.reg_no))
[3349]66    sid = d['student_id'] = context.waeup_tool.admitOneStudent(brain,
67                                                               entry_session,
68                                                               pin_password,
69                                                               with_timing = with_timing)
[3351]70
[2540]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))
[3349]75        if with_timing:
76            data = context.waeup_tool.get_timing_data()
[3350]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)
[2540]81        admitted += 1
82    else:
[2727]83        logger.info("could not create objects of student %s with pin %s" % (reg_no,brain.pin))
[2575]84
[2540]85msg = "finished admitting %d students" % (admitted)
86logger.info(msg)
[2671]87#rwrite(msg)
88return
Note: See TracBrowser for help on using the repository browser.