source: WAeUP_SRP/base/skins/waeup_utilities/ti_71fc_resolve.py @ 3084

Last change on this file since 3084 was 3084, checked in by joachim, 17 years ago

use portal_catalog instead of students_catalog to find levels

  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
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"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18
19mtool = context.portal_membership
20member = mtool.getAuthenticatedMember()
21if str(member) not in ('admin','joachim'):
22    return
23
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.ti_71fc_resolve')
28from Products.AdvancedQuery import Eq, Between, Le,In
29aq_students = context.students_catalog.evalAdvancedQuery
30aq_portal = context.portal_catalog_real.evalAdvancedQuery
31students_folder = context.portal_url.getPortalObject().campus.students
32
33request = context.REQUEST
34session = request.SESSION
35response = request.RESPONSE
36setheader = request.RESPONSE.setHeader
37def rwrite(s):
38    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
39    response.write("%s<br>\n\r" % s)
40levels_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
47query = In('id',levels_to_look_for) & Eq('portal_type','StudentStudyLevel')
48levels= aq_portal(query)
49logger.info('found %d students with levels %s' % (len(levels), " ".join(levels_to_look_for)))
50students = {}
51for level in levels:
52    student_id = level.getPath().split('/')[-3]
53    students[student_id] = level.getId
54
55for 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))
73logger.info('finished')
Note: See TracBrowser for help on using the repository browser.