Index: WAeUP_SRP/trunk/skins/waeup_student/searchStudents.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_student/searchStudents.py	(revision 750)
+++ WAeUP_SRP/trunk/skins/waeup_student/searchStudents.py	(revision 751)
@@ -63,9 +63,9 @@
 err = False
 with_review = state != "all"
-onlyreview = with_review and not term
+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<br\> onlyreview = %s<br\>" % (with_review,onlyreview)
+bools = "with_review = %s<br\> only_review = %s<br\>" % (with_review,only_review)
 if not term and not with_review:
     psm = "You must specify a search string when searching 'all states'."
@@ -86,79 +86,29 @@
 st_queries = ('jamb_reg_no','matric_no','name')
 query_step = 0
-review_query = None
-if onlyreview:
-    query_step = 1
-    query =   In('portal_type',student_subobjects) & Eq('review_state',state) 
-    #res = evalAdvancedQuery(query)
-elif what == "student_id":
-    if with_review:
-        query_step = 3
-        res = catalog(portal_type='Student',
-                      id = term.strip(),
-                      review_state=state)
-    else:
-        query_step = 4
-        res = catalog(portal_type='Student',
-                      id = term.strip())
-elif what in st_queries:
-    if what == "jamb_reg_no":
-        query_step = 5
-        pt = ('StudentApplication',)
-        st = "%s*" % term.strip().lower()
-    elif what == "matric_no":
-        query_step = 6
-        pt = ('StudentClearance',)
-        st = "%s*" % term.strip().lower()
-    elif what == "name":
-        query_step = 7
-        pt = portal_type_query
-        st = "%s*" % term.strip()
-    if with_review:
-        review_query = In('portal_type',student_subobjects) & Eq('review_state',state)
-    query = (In('portal_type',pt) & Eq('SearchableText',st))
-##    try:
-##        res = catalog(portal_type=pt,SearchableText=st)
-##    except:
-##        return context.students_manager_view(rendered = rend,
-##                             psm = 'Search string "%s" not allowed.' % term,
-##                             #psm = "%s, %s" % (psm,ds),
-##                             students = items,
-##                             is_manager = is_manager,
-##                             )
-##elif what in st_queries and with_level_results and evalAdvancedQuery:
-##    if what == "jamb_reg_no":
-##        query_step = 8
-##        pt = 'StudentApplication'
-##        st = "%s*" % term.strip().lower()
-##    elif what == "matric_no":
-##        query_step = 9
-##        pt = 'StudentClearance'
-##        st = "%s*" % term.strip().lower()
-##    elif what == "name":
-##        query_step = 10
-##        pt = portal_type_query
-##        st = "%s*" % term.strip()
-##    query = Eq('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip().lower())\
-##                | ((Eq('portal_type','StudentStudyLevel') | 
-##                   Eq('portal_type','StudentStudyCourse')) & Eq('review_state',state))
-if review_query:
-    res = evalAdvancedQuery(query | review_query)
-else:
+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)
-##try:
-##    if review_query:
-##        res = evalAdvancedQuery(query) & evalAdvancedQuery(review_query)
-##    else:
-##        res = evalAdvancedQuery(query)
-##except:
-##    return context.students_manager_view(rendered = rend,
-##                         psm = 'Advanced Query failed' % term,
-##                         #psm = "%s, %s" % (psm,ds),
-##                         students = items,
-##                         is_manager = is_manager,
-##                         )
-students = []
-raw_res = len(res)
-all = []
+if with_review:
+    query_step += 10
+    review_res = evalAdvancedQuery(In('portal_type',student_subobjects) & Eq('review_state',state))
+search_set = []
 if res:
     for r in res:
@@ -169,10 +119,29 @@
         else:
             student = r.getObject()
-        if student in all:
-            items.append(student)
-            continue
-        all.append(student)
-if onlyreview:
-    items = all
+        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 = []
 if items:
     for item in items:
@@ -180,5 +149,6 @@
         students.append(info)
     return context.students_manager_view(rendered = rend,
-                             psm = "%d matching Students found QS = %s" % (len(items),query_step),
+                             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,
@@ -186,5 +156,5 @@
                              )
 return context.students_manager_view(rendered = rend,
-                             psm = """Step: %s found: %s Your search for "%s" in %s with state %s failed.<br\>%s""" % (query_step,raw_res,st,what,state,bools),
+                             psm = """Step: %s found: %s Your search for "%s" in %s with state %s failed.<br\>%s""" % (query_step,len(items),st,what,state,bools),
                              students = students,
                              is_manager = is_manager,
