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