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

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

new function admitStudents please check

  • Property svn:keywords set to Id
File size: 1.9 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 2540 2007-11-05 18:47:31Z 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
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.admitStudents')
28from Products.AdvancedQuery import Eq, Between, Le,In
29aq_applicants = context.applicants_catalog.evalAdvancedQuery
30request = context.REQUEST
31session = request.SESSION
32response = request.RESPONSE
33setheader = request.RESPONSE.setHeader
34def rwrite(s):
35    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
36    response.write("%s<br>\n\r" % s)
37
38brains = aq_applicants(In('status',('admitted'),))
39total = len(brains)
40logger.info("found %d students" % (total))
41count = 0
42admitted = 0
43cocount = 0
44commit_after = 2
45d = {'status': 'created'}
46reg_nos = [brain.reg_no for brain in brains]
47for reg_no in reg_nos:
48    count += 1
49    if admitted and not admitted % commit_after:
50        context.waeup_tool.doCommit()
51        logger.info("Committing %s transactions, total %s" % (commit_after,count))
52        cocount += 1
53        if cocount > 3:
54            break
55    brain = aq_applicants(Eq('reg_no',reg_no))[0]
56    #logger.info("start creating  objects of student %s" % (brain.reg_no))
57    sid = d['student_id'] = context.waeup_tool.admitOneStudent(brain)
58    if sid is not None:
59        d['reg_no'] = reg_no
60        context.applicants_catalog.modifyRecord(**d)
61        logger.info("created objects of student %s with id %s" % (reg_no,sid))
62        admitted += 1
63    else:
64        logger.info("could not create  objects of student %s with pin " % (reg_no,brain.pin))
65       
66msg = "finished admitting %d students" % (admitted)
67logger.info(msg)
68rwrite(msg)
Note: See TracBrowser for help on using the repository browser.