1 | ## Script (Python) "set_current_session" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=REQUEST |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: set_current_session.py 1757 2007-05-08 17:22:45Z joachim $ |
---|
11 | """ |
---|
12 | set current_session of all students |
---|
13 | """ |
---|
14 | import logging |
---|
15 | logger = logging.getLogger('Skins.set_current_session') |
---|
16 | |
---|
17 | request = REQUEST |
---|
18 | response = request.RESPONSE |
---|
19 | try: |
---|
20 | from Products.zdb import set_trace |
---|
21 | except: |
---|
22 | def set_trace(): |
---|
23 | pass |
---|
24 | |
---|
25 | def rwrite(s): |
---|
26 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
27 | #response.setHeader('Content-length','%d' % (len(s))) |
---|
28 | #response.setStatus('OK') |
---|
29 | response.write("%s <br/>\n\r" % s) |
---|
30 | return |
---|
31 | |
---|
32 | mtool = context.portal_membership |
---|
33 | member = mtool.getAuthenticatedMember() |
---|
34 | students_catalog = context.students_catalog |
---|
35 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
36 | |
---|
37 | #rwrite("start") |
---|
38 | if str(member) not in ('admin','joachim'): |
---|
39 | return |
---|
40 | all = students_catalog() |
---|
41 | logger.info('%s starts to set %s ' % (member,len(all))) |
---|
42 | c = 0 |
---|
43 | count = 0 |
---|
44 | not_count = 0 |
---|
45 | #set_trace() |
---|
46 | for student in all: |
---|
47 | c += 1 |
---|
48 | if c > 1000: |
---|
49 | logger.info('%s set %d not_found %d ' % (member,count,not_count)) |
---|
50 | c = 0 |
---|
51 | context.waeup_tool.doCommit() |
---|
52 | if not student.session: |
---|
53 | try: |
---|
54 | study_course_doc = getattr(getattr(students_folder,student.id),'study_course').getContent() |
---|
55 | study_course_doc.edit(mapping = {'current_session': '06'}) |
---|
56 | count += 1 |
---|
57 | data = {'session':'06'} |
---|
58 | data['id'] = student.id |
---|
59 | students_catalog.modifyRecord(**data) |
---|
60 | except: |
---|
61 | not_count += 1 |
---|
62 | #rwrite("%s/study_course not found" % student.id) |
---|
63 | |
---|
64 | logger.info('%s finished to set %d of %d ' % (member,count,len(all))) |
---|
65 | return |
---|
66 | |
---|