## Script (Python) "cpsdocument_edit"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# $Id: searchStudents.py 805 2006-11-09 09:38:29Z joachim $
"""
return Info about the current Student
"""
try:
from Products.AdvancedQuery import Eq, Between, Le,In
evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery
except:
evalAdvancedQuery = None
def cmp_id(a,b):
if a.getId() > b.getId():
return 1
return -1
request = context.REQUEST
form = request.form
fget = form.get
student_subobjects = ("StudentApplication",
"StudentPersonal",
"StudentStudyCourse",
"StudentAccommodation",
"StudentStudyLevel",)
student_objects = student_subobjects + ("Student",)
info = {}
items = []
wf = context.portal_workflow
catalog = context.portal_catalog
#student_wf_states = wf.waeup_student_wf.states.keys()
#info['wf_states'] = student_wf_states
#info['wf_states'][0] = " ----- "
lt = context.portal_layouts
pr = context.portal_registration
path_info = request.get('PATH_INFO').split('/')
is_manager = context.isManager
validate = request.has_key("cpsdocument_edit_button")
default = {'search_mode': 'name',
'review_state': 'all',
'search_string': ''
}
rend,psm,ds = lt.renderLayout(layout_id= 'student_search',
schema_id= 'student_search',
context=context,
mapping=validate and request,
ob=default,
layout_mode='edit',
formaction="searchStudents"
)
if psm == '':
return context.students_manager_view(rendered = rend,
psm = psm,
#psm = "%s, %s" % (psm,ds),
students = items,
is_manager = is_manager,
)
what = ds.get('search_mode')
state = ds.get('review_state')
st = term = ds.get('search_string')
err = False
with_review = state != "all"
only_review = with_review and not term
##with_level_results = state.startswith("category") or\
## state in ('content_addable',) and\
## evalAdvancedQuery is not None
bools = "with_review = %s
only_review = %s
" % (with_review,only_review)
if not term and not with_review:
psm = "You must specify a search string when searching 'all states'."
err = True
elif '*' in term:
psm = "you cannot use the '*' alone"
err = True
if err:
return context.students_manager_view(rendered = rend,
psm = psm,
#psm = "%s, %s" % (psm,ds),
students = items,
is_manager = is_manager,
)
items = []
res = []
portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
st_queries = ('jamb_reg_no','matric_no','name')
query_step = 0
review_res = None
query = None
if len(term) > 0:
if what == "student_id":
query_step = 1
query = Eq('portal_type','Student') & Eq('id', term.strip())
elif what in st_queries:
if what == "jamb_reg_no":
query_step = 2
pt = ('StudentApplication',)
st = "%s" % term.strip().lower()
elif what == "matric_no":
query_step = 3
pt = ('StudentClearance',)
st = "%s" % term.strip().lower()
elif what == "name":
query_step = 4
pt = ('StudentPersonal')
st = "%s" % term.strip()
query = In('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip())
res = evalAdvancedQuery(query)
if with_review:
query_step += 10
review_res = evalAdvancedQuery(In('portal_type',student_objects) & Eq('review_state',state))
search_set = []
if res:
for r in res:
if r.portal_type in ("StudentStudyLevel",):
student = r.getObject().aq_parent.aq_parent
elif r.portal_type in student_subobjects:
student = r.getObject().aq_parent
else:
student = r.getObject()
search_set.append(student)
review_set = []
if review_res:
for r in review_res:
if r.portal_type in ("StudentStudyLevel",):
student = r.getObject().aq_parent.aq_parent
elif r.portal_type in student_subobjects:
student = r.getObject().aq_parent
else:
student = r.getObject()
review_set.append(student)
all = []
if only_review:
all = review_set
elif with_review:
for i in search_set:
if i in review_set:
all.append(i)
else:
all = search_set
for a in all:
if a in items:
continue
items.append(a)
students = []
items.sort(cmp_id)
if items:
for item in items:
info = context.getStudentInfo(item)
students.append(info)
return context.students_manager_view(rendered = rend,
psm = "%d,%d matching Students found QS = %s" %\
(len(review_set),len(search_set),query_step),
#psm = "%d found QS = %s items: %s" % (len(items),query_step,items),
students = students,
is_manager = is_manager,
)
return context.students_manager_view(rendered = rend,
psm = """Step: %s found: %s Your search for "%s" in %s with state %s failed.
%s""" % (query_step,len(items),st,what,state,bools),
students = students,
is_manager = is_manager,
)