## Script (Python) "search_pins"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# $Id: fixLevelFromResults.py 1392 2007-02-05 15:59:08Z henrik $
"""
list Students for ClearanceOfficers
"""
request = context.REQUEST
session = request.SESSION
response = request.RESPONSE
setheader = request.RESPONSE.setHeader
#def rwrite(s):
# response.setHeader('Content-type','text/html; charset=ISO-8859-15')
# response.write(s)
wftool = context.portal_workflow
mtool = context.portal_membership
member = mtool.getAuthenticatedMember()
roles = member.getRolesInContext(context)
retcat = context.returning_import
rcat = context.results_import
scat = context.students_catalog
from Products.AdvancedQuery import Eq, Between, Le,In
aq_students = context.students_catalog.evalAdvancedQuery
students = context.portal_url.getPortalObject().campus.students
if str(member) not in ('admin','joachim'):
return
count = 0
lc = 1
lines = []
#from Products.zdb import set_trace;set_trace()
res = scat()
for sbrain in res:
old_level = str(sbrain.level)
if str(sbrain.level) == '100':
ec = "new"
else:
ec = "nor"
erg = context.results_import(matric_no=sbrain.matric_no)
if erg and erg[0].Level:
ec = "e"
level = erg[0].Level
for e in erg:
ec = "E"
if level != e.Level:
ec = "%s:%s!=%s
\n" % (sbrain.matric_no,level,e.Level)
level = "%d" % (int(level) + 100)
context.students_catalog.modifyRecord(id = sbrain.id, level="")
while True:
student = getattr(students,sbrain.id,None)
ec = "nos"
if student is None:
break
ec = "nyr"
study_course = getattr(student,"study_course", None)
if study_course is None:
break
study_course.getContent().edit(mapping = {'current_level':level})
context.students_catalog.modifyRecord(id = sbrain.id, level=level)
ec = "reg"
break
# rwrite(ec +"--"+ sbrain.id +"--"+ sbrain.matric_no +"--"+ old_level +"--"+ level +"
")
lines.append('"%s","%s","%s","%s","%s"' % (ec,sbrain.id,sbrain.matric_no,old_level,level))
else:
# rwrite(ec +"--"+ sbrain.id +"--"+ sbrain.matric_no + "
")
lines.append('"%s","%s","%s","",""' % (ec,sbrain.id,sbrain.matric_no))
# count += 1
# if count > 60:
# lc += 1
# rwrite("
\n%3d " % lc)
# count = 0
#rwrite("
\n Done" )
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)