## Script (Python) "ti_151_resolve"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# $Id: ti_151_resolve.py 1642 2007-03-26 20:10:15Z joachim $
"""
resolve ticket #151
"""
try:
from Products.zdb import set_trace
except:
def set_trace():
pass
import logging
#>>>>>>>>>>>>>>>><
logger = logging.getLogger('Skins.ti_151_resolve')
logger.info('already done on 26.3.07 by joachim')
return
#<<<<<<<<<<<<<<<<<
request = context.REQUEST
session = request.SESSION
response = request.RESPONSE
setheader = request.RESPONSE.setHeader
students = context.portal_url.getPortalObject().campus.students
#from string import Template
def rwrite(s):
response.setHeader('Content-type','text/html; charset=ISO-8859-15')
response.write(s)
def getObject(outer,object):
if outer.hasObject(object):
return getattr(outer,object)
return None
try:
from Products.AdvancedQuery import Eq, Between, Le,In
aq_students = context.students_catalog.evalAdvancedQuery
except:
evalAdvancedQuery = None
students_cat = context.students_catalog
query = Eq('faculty','PSC') & Eq('department','PHY') & In('level',('300','400'))
brains = aq_students(query)
#brains = students_cat(faculty = 'PSC',department='PHY', level='400')
total = 0
count_ok = 0
count_nosc = 0
count_nolevel = 0
count_level = 0
count_renamed = 0
#set_trace()
#template = Template('"$count","$id","$course"')
to_rename = []
for student in brains:
student_dict = {}
for field in students_cat.schema():
student_dict[field] = getattr(student,field)
#s = template.substitute(student_dict,count=count,)
student_dict['total'] = total
while True:
if student.course == "BSCINP":
student_dict['message'] = "OK"
count_ok += 1
student_dict['sp_count'] = count_ok
s = '"%(total)d","%(sp_count)s","%(id)s","%(course)s","%(message)s",' % student_dict
break
student_dict['message'] = ""
student_obj = getObject(students,student.id)
if student_obj is None:
student_dict['message'] = "No student object"
break
study_course_obj = getObject(student_obj,'study_course')
if study_course_obj is None:
student_dict['message'] = "No study_course object"
count_nosc += 1
student_dict['sp_count'] = count_nosc
break
level_obj = getObject(student_obj,student.level)
if level_obj:
count_level += 1
study_course.manage_delObjects((student.level,))
student_dict['message'] = "Level deleted"
student_dict['sp_count'] = count_level
count_renamed += 1
to_rename.append(student.id)
student_dict['sp_count'] = count_renamed
student_dict['message'] = student_dict['message'] + "renamed to BSCINP"
study_course_doc = study_course_obj.getContent()
study_course_obj.edit(mapping = {'study_course': "BSCINP"})
total += 1
s = '"%(total)d","%(sp_count)s","%(id)s","%(course)s","%(message)s",' % student_dict
rwrite("%s
\r\n" %s)
break
total += 1
s = '"%(total)d","%(sp_count)s","%(id)s","%(course)s","%(message)s",' % student_dict
rwrite("%s
\r\n" %s)
for sid in to_rename:
students_cat.modifyRecord(id = sid,course="BSCINP")
sum = count_ok + count_nosc + count_nolevel + count_level
rwrite("total=%d,sum of below=%d,
\r\n correct study_course=%d
\r\n no study_course=%d
\r\n no level=%d
\r\n with level =%d,
\n Done" %
(total,
sum,
count_ok,
count_nosc,
count_nolevel,
count_level)
)
logger.info("total=%d,sum=%d,ok=%d,no study_course=%d,no level=%d,with level =%d,\n Done" %
(total,sum,count_ok,count_nosc,count_nolevel,count_level))