## Script (Python) "reindex_entry_mode"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# $Id: reindexStudentsCatFacultyDepartment.py 1478 2007-02-23 15:09:15Z joachim $
"""
reindex students_catalog entry_mode index
"""
try:
from Products.zdb import set_trace
except:
def set_trace():
pass
request = context.REQUEST
session = request.SESSION
response = request.RESPONSE
setheader = request.RESPONSE.setHeader
students_folder = context.portal_url.getPortalObject().campus.students
def rwrite(s):
response.setHeader('Content-type','text/html; charset=ISO-8859-15')
response.write(s)
students_cat = context.students_catalog
from Products.AdvancedQuery import Eq, Between, Le,In
aq_portal = context.portal_catalog.evalAdvancedQuery
students = students_cat()
count = 0
certificates = {}
d = {}
d['faculty'] = 'n/a'
d['department'] = 'n/a'
certificates['na'] = d
count = 0
ch_count = 0
to_delete = []
for student in students:
sc_found = False
student_found = False
changed = False
if students_folder.hasObject(student.id):
student_found = True
student_obj = getattr(students_folder,student.id)
if student_obj.hasObject('study_course'):
sc = getattr(student_obj,'study_course')
cert_id = sc.getContent().study_course
if certificates.has_key(cert_id):
d = certificates[cert_id]
else:
query = Eq('portal_type','Certificate') &\
Eq('id',cert_id)
#set_trace()
cert_brain = aq_portal(query)[0]
d = {}
d['faculty'] = cert_brain.getPath().split('/')[-4]
d['department'] = cert_brain.getPath().split('/')[-3]
certificates[cert_id] = d
sc_found = True
if student.faculty != d['faculty'] or student.department != d['department']:
ch_count += 1
changed = True
d['id'] = student.id
students_cat.modifyRecord(**d)
else:
d = certificates['na']
else:
d = certificates['na']
to_delete.append(student.id)
count +=1
s = '"%s ","%s","%s","%s","%s","%s","%s","%s"' % (count,student_found,sc_found,
changed,ch_count,
student.id,
d['faculty'],
d['department'],
)
rwrite("%s
" %s)
#setheader('Content-type','text/semicolon-seperated-values')
#setheader('Content-Disposition:', 'attachment; filename="fixLevelExport.csv"')
#setheader('Expires', 'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past
#setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1
#setheader('Cache-Control', 'post-check=0,pre-check=0')
#setheader('Pragma', 'no-cache') # HTTP/1.0
#return '\n'.join(lines)
rwrite("
\n Done" )