[3082] | 1 | ## Script (Python) "ti_71fc_resolve" |
---|
| 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: ti_71fc_resolve.py 3084 2008-02-01 12:15:11Z joachim $ |
---|
| 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 | |
---|
| 24 | |
---|
| 25 | import logging |
---|
| 26 | import DateTime |
---|
| 27 | logger = logging.getLogger('Skins.ti_71fc_resolve') |
---|
| 28 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 29 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
[3084] | 30 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
[3082] | 31 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
| 32 | |
---|
| 33 | request = context.REQUEST |
---|
| 34 | session = request.SESSION |
---|
| 35 | response = request.RESPONSE |
---|
| 36 | setheader = request.RESPONSE.setHeader |
---|
| 37 | def rwrite(s): |
---|
| 38 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 39 | response.write("%s<br>\n\r" % s) |
---|
[3084] | 40 | levels_to_look_for = ("110","210") |
---|
| 41 | # query = In('level',levels_to_look_for) |
---|
| 42 | # student_records = aq_students(query) |
---|
| 43 | # logger.info('found %d students with levels %s' % (len(student_records), " ".join(levels_to_look_for))) |
---|
| 44 | # students = {} |
---|
| 45 | # for student_record in student_records: |
---|
| 46 | # students[student_record.id] = student_record.level |
---|
| 47 | query = In('id',levels_to_look_for) & Eq('portal_type','StudentStudyLevel') |
---|
| 48 | levels= aq_portal(query) |
---|
| 49 | logger.info('found %d students with levels %s' % (len(levels), " ".join(levels_to_look_for))) |
---|
[3082] | 50 | students = {} |
---|
[3084] | 51 | for level in levels: |
---|
| 52 | student_id = level.getPath().split('/')[-3] |
---|
| 53 | students[student_id] = level.getId |
---|
[3082] | 54 | |
---|
| 55 | for student_id,level in students.items(): |
---|
| 56 | study_course = getattr(getattr(students_folder,student_id),'study_course',None) |
---|
| 57 | if study_course is None: |
---|
| 58 | logger.info('%s study_course not found' % (student_record.id)) |
---|
| 59 | continue |
---|
| 60 | #logger.info('%s renaming level' % (student_id)) |
---|
| 61 | if level == '110': |
---|
| 62 | if hasattr(study_course,'110'): |
---|
| 63 | study_course.manage_renameObjects(('110',),('200',)) |
---|
| 64 | logger.info('%s renamed level from 110 to 200' % (student_id)) |
---|
| 65 | else: |
---|
| 66 | logger.info('%s no level-object for 110' % (student_id)) |
---|
| 67 | elif level == '210': |
---|
| 68 | if hasattr(study_course,'210'): |
---|
| 69 | study_course.manage_renameObjects(('210',),('300',)) |
---|
| 70 | logger.info('%s renamed level from 110 to 200' % (student_id)) |
---|
| 71 | else: |
---|
| 72 | logger.info('%s no level-object for 210' % (student_id)) |
---|
| 73 | logger.info('finished') |
---|