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 | """ |
---|
13 | try: |
---|
14 | from Products.zdb import set_trace |
---|
15 | except: |
---|
16 | def set_trace(): |
---|
17 | pass |
---|
18 | |
---|
19 | mtool = context.portal_membership |
---|
20 | member = mtool.getAuthenticatedMember() |
---|
21 | if str(member) not in ('admin',): |
---|
22 | return |
---|
23 | |
---|
24 | pin_password = False |
---|
25 | |
---|
26 | import logging |
---|
27 | import DateTime |
---|
28 | logger = logging.getLogger('Skins.admitStudents') |
---|
29 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
30 | aq_applicants = context.applicants_catalog.evalAdvancedQuery |
---|
31 | request = context.REQUEST |
---|
32 | session = request.SESSION |
---|
33 | response = request.RESPONSE |
---|
34 | setheader = request.RESPONSE.setHeader |
---|
35 | def rwrite(s): |
---|
36 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
37 | response.write("%s<br>\n\r" % s) |
---|
38 | |
---|
39 | if not entry_session: |
---|
40 | brains = aq_applicants(In('status',('admitted'),)) |
---|
41 | else: |
---|
42 | brains = aq_applicants(In('status',('admitted'),) & Eq('entry_session',entry_session)) |
---|
43 | |
---|
44 | total = len(brains) |
---|
45 | logger.info("found %d students" % (total)) |
---|
46 | count = 0 |
---|
47 | admitted = 0 |
---|
48 | cocount = 0 |
---|
49 | old_commit_count = 0 |
---|
50 | commit_after = 40 |
---|
51 | d = {'status': 'created'} |
---|
52 | reg_nos = [brain.reg_no for brain in brains] |
---|
53 | with_timing = False |
---|
54 | for 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 | |
---|
85 | msg = "finished admitting %d students" % (admitted) |
---|
86 | logger.info(msg) |
---|
87 | #rwrite(msg) |
---|
88 | return |
---|