[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 | """ |
---|
| 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() |
---|
[5563] | 21 | if str(member) not in ('admin',): |
---|
[2540] | 22 | return |
---|
| 23 | |
---|
[2576] | 24 | pin_password = False |
---|
[2540] | 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 | |
---|
[5562] | 39 | if not entry_session: |
---|
[5567] | 40 | brains = aq_applicants(In('status',('admitted'),)) |
---|
| 41 | else: |
---|
| 42 | brains = aq_applicants(In('status',('admitted'),) & Eq('entry_session',entry_session)) |
---|
[5562] | 43 | |
---|
[2540] | 44 | total = len(brains) |
---|
| 45 | logger.info("found %d students" % (total)) |
---|
| 46 | count = 0 |
---|
| 47 | admitted = 0 |
---|
| 48 | cocount = 0 |
---|
[3350] | 49 | old_commit_count = 0 |
---|
[3349] | 50 | commit_after = 40 |
---|
[2540] | 51 | d = {'status': 'created'} |
---|
| 52 | reg_nos = [brain.reg_no for brain in brains] |
---|
[3351] | 53 | with_timing = False |
---|
[2540] | 54 | for 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] | 85 | msg = "finished admitting %d students" % (admitted) |
---|
| 86 | logger.info(msg) |
---|
[2671] | 87 | #rwrite(msg) |
---|
| 88 | return |
---|