source: WAeUP_SRP/trunk/skins/waeup_utilities/setCurrentSession.py @ 16414

Last change on this file since 16414 was 1760, checked in by Henrik Bettermann, 18 years ago

count also 'session fields already set'

File size: 1.9 KB
Line 
1## Script (Python) "setCurrentSession"
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"""
12set current_session of all students
13"""
14import logging
15logger = logging.getLogger('Skins.setCurrentSession')
16
17request = REQUEST
18response = request.RESPONSE
19try:
20    from Products.zdb import set_trace
21except:
22    def set_trace():
23        pass
24
25def 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
32mtool = context.portal_membership
33member = mtool.getAuthenticatedMember()
34students_catalog = context.students_catalog
35students_folder = context.portal_url.getPortalObject().campus.students
36
37#rwrite("start")
38if str(member) not in ('admin','joachim'):
39    return
40all = students_catalog()
41logger.info('%s starts to set %s ' % (member,len(all)))
42c = 0
43count = 0
44not_count = 0
45not_count2 = 0
46#set_trace()
47for student in all:
48    c += 1
49    if c > 1000:
50        logger.info('%s set %d, not found %d, session fields already set %d' % (member,count,not_count,not_count2))
51        c = 0
52        context.waeup_tool.doCommit()
53    if not student.session:
54        try:
55            study_course_doc = getattr(getattr(students_folder,student.id),'study_course').getContent()
56            study_course_doc.edit(mapping = {'current_session': '06'})
57            count += 1
58            data = {'session':'06'}
59            data['id'] = student.id
60            students_catalog.modifyRecord(**data)
61        except:
62            not_count += 1
63            #rwrite("%s/study_course not found" % student.id)
64    else:
65        not_count2 +=1
66
67logger.info('%s finished to set %d of %d ' % (member,count,len(all)))
68return
69
Note: See TracBrowser for help on using the repository browser.