source: WAeUP_SRP/branches/uli/skins/waeup_utilities/reindexStudentsCatFacultyDepartment.py @ 17935

Last change on this file since 17935 was 1478, checked in by joachim, 18 years ago

new script for reindexing the studentscatalog faculty and department fields

  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1## Script (Python) "reindex_entry_mode"
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: reindexStudentsCatFacultyDepartment.py 1478 2007-02-23 15:09:15Z joachim $
11"""
12reindex students_catalog entry_mode index
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
20request = context.REQUEST
21session = request.SESSION
22response = request.RESPONSE
23setheader = request.RESPONSE.setHeader
24students_folder = context.portal_url.getPortalObject().campus.students
25
26def rwrite(s):
27    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
28    response.write(s)
29
30students_cat = context.students_catalog
31from Products.AdvancedQuery import Eq, Between, Le,In
32aq_portal = context.portal_catalog.evalAdvancedQuery
33
34students = students_cat()
35count = 0
36certificates = {}
37d = {}
38d['faculty'] = 'n/a'
39d['department'] = 'n/a'
40certificates['na'] = d
41count = 0
42ch_count = 0
43to_delete = []
44for student in students:
45    sc_found = False
46    student_found = False
47    changed = False
48    if students_folder.hasObject(student.id):
49        student_found = True
50        student_obj = getattr(students_folder,student.id)
51        if student_obj.hasObject('study_course'):
52            sc = getattr(student_obj,'study_course')
53            cert_id = sc.getContent().study_course
54            if certificates.has_key(cert_id):
55                d = certificates[cert_id]
56            else:
57                query = Eq('portal_type','Certificate') &\
58                        Eq('id',cert_id)
59                #set_trace()
60                cert_brain = aq_portal(query)[0]
61                d = {}
62                d['faculty'] = cert_brain.getPath().split('/')[-4]
63                d['department'] = cert_brain.getPath().split('/')[-3]
64                certificates[cert_id] = d
65            sc_found = True
66            if student.faculty != d['faculty'] or student.department != d['department']:
67                ch_count += 1
68                changed = True
69                d['id'] = student.id
70                students_cat.modifyRecord(**d)
71        else:
72            d = certificates['na']
73    else:
74        d = certificates['na']
75        to_delete.append(student.id)
76    count +=1   
77    s = '"%s ","%s","%s","%s","%s","%s","%s","%s"' % (count,student_found,sc_found,
78                                                changed,ch_count,
79                                                student.id,
80                                                d['faculty'],
81                                                d['department'],
82                                                )
83    rwrite("%s<br />" %s)
84
85#setheader('Content-type','text/semicolon-seperated-values')
86#setheader('Content-Disposition:', 'attachment; filename="fixLevelExport.csv"')
87#setheader('Expires',  'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past
88#setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1
89#setheader('Cache-Control', 'post-check=0,pre-check=0')
90#setheader('Pragma', 'no-cache') # HTTP/1.0
91#return '\n'.join(lines)
92
93rwrite("<br />\n Done" )
94
Note: See TracBrowser for help on using the repository browser.