## Script (Python) "fixLevelForNewStudents"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=REQUEST
##title=
##
# $Id: fixLevelForNewStudents.py 1593 2007-03-19 18:57:54Z uli $
"""
list Students for ClearanceOfficers
"""
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
import logging
logger = logging.getLogger('Skins.fixLevelForNewStudents')
def rwrite(s):
response.setHeader('Content-type','text/html; charset=ISO-8859-15')
response.write(s)
mtool = context.portal_membership
member = mtool.getAuthenticatedMember()
retcat = context.returning_import
rcat = context.results_import
students_cat = context.students_catalog
from Products.AdvancedQuery import Eq, Between, Le,In
aq_students = students_cat.evalAdvancedQuery
aq_portal = context.portal_catalog.evalAdvancedQuery
students = context.portal_url.getPortalObject().campus.students
count = 0
##query = Eq('portal_type','Student') & In('review_state',('admitted',
## 'clearance_requested',
## 'cleared_and_validated',
## 'objection_raised',
## )
##res = aq_portal(query)
query = Eq('level','100')
#res = aq_students(query)
res = students_cat(level='100')
#set_trace()
count = 0
count_full = 0
commit_count = 0
logger.info("Started for %s students" % len(res))
to_change = {}
for sbrain in res:
#count_full += 1
#rwrite("%s: %s %s %s
" % (count_full,sbrain.id,sbrain.entry_mode,sbrain.level))
student_obj = getattr(students,sbrain.id)
changed = False
if sbrain.entry_mode == "":
if not student_obj.hasObject('application'):
rwrite("%s %s %s application not found
" % (sbrain.id,sbrain.entry_mode,level))
continue
changed = True
app_doc = student_obj.application.getContent()
entry_mode = app_doc.entry_mode
else:
entry_mode = sbrain.entry_mode
if entry_mode == "DE":
changed = True
level = "200"
else:
level = "100"
if changed:
d = {}
d['id'] = sbrain.id
d['level'] = level
d['entry_mode'] = entry_mode
to_change[sbrain.id] = d
## students_cat.modifyRecord(id=sbrain.id,
## level=level,
## entry_mode=entry_mode)
if not student_obj.hasObject('study_course'):
rwrite("%s %s %s study_course not found
" % (sbrain.id,sbrain.entry_mode,level))
continue
student_obj.study_course.getContent().edit(mapping={'current_level': level,
'current_verdict': 'N/A'})
count += 1
commit_count += 1
if commit_count > 1000:
context.waeup_tool.doCommit()
logger.info("Committing %s transactions, total %s" % (commit_count,count))
commit_count = 0
rwrite("%s: %s %s %s
" % (count,sbrain.id,entry_mode,level))
for entry in to_change.keys():
students_cat.modifyRecord(**to_change[entry])
rwrite("finished")
logger.info("Finished %s students" % count)