| [1759] | 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 | """ |
|---|
| 12 | set current_session of all students |
|---|
| 13 | """ |
|---|
| 14 | import logging |
|---|
| [1760] | 15 | logger = logging.getLogger('Skins.setCurrentSession') |
|---|
| [1759] | 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 |
|---|
| [1760] | 45 | not_count2 = 0 |
|---|
| [1759] | 46 | #set_trace() |
|---|
| 47 | for student in all: |
|---|
| 48 | c += 1 |
|---|
| 49 | if c > 1000: |
|---|
| [1760] | 50 | logger.info('%s set %d, not found %d, session fields already set %d' % (member,count,not_count,not_count2)) |
|---|
| [1759] | 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) |
|---|
| [1760] | 64 | else: |
|---|
| 65 | not_count2 +=1 |
|---|
| [1759] | 66 | |
|---|
| 67 | logger.info('%s finished to set %d of %d ' % (member,count,len(all))) |
|---|
| 68 | return |
|---|
| 69 | |
|---|