Index: /WAeUP_SRP/base/skins/waeup_student/search_students.py
===================================================================
--- /WAeUP_SRP/base/skins/waeup_student/search_students.py	(revision 3023)
+++ /WAeUP_SRP/base/skins/waeup_student/search_students.py	(revision 3024)
@@ -42,24 +42,15 @@
     aq_portal = context.portal_catalog_real.evalAdvancedQuery
 students_catalog = context.students_catalog
-aq_students = context.students_catalog.evalAdvancedQuery
-
-def cmp_id(a,b):
-    if a.getId() > b.getId():
-        return 1
-    return -1
-
-student_subobjects = ("StudentApplication",
-                      "StudentPersonal",
-                      "StudentStudyCourse",
-                      "StudentAccommodation",
-                      "StudentStudyLevel",)
-
-student_objects = ("Student",)
+aq_students = students_catalog.evalAdvancedQuery
+
+#def cmp_id(a,b):
+#    if a.getId() > b.getId():
+#        return 1
+#    return -1
 
 user_info = {}
-items = []
 validate = request.has_key("cpsdocument_edit_button")
 
-state = "all"
+default_state = "all"
 user_info['member'] = str(member)
 user_info['departments'] = []
@@ -71,7 +62,9 @@
 certificate_levels = fget('certificate_levels')
 dep_str = fac_str = certificate_levels_str = ''
+
+# determine local roles
+
 if "ClearanceOfficers" in member.getGroups():
-    state = "clearance_requested"
-    only_review = False
+    default_state = "clearance_requested"
     co_view = True
     if faculties or departments:
@@ -102,6 +95,5 @@
         dep_str = " ".join(departments)
 elif "CourseAdvisers" in member.getGroups():
-    state = "courses_registered"
-    only_review = False
+    default_state = "courses_registered"
     ca_view = True
     if certificate_levels:
@@ -137,5 +129,5 @@
 
 default = {'search_mode': 'student_id',
-        'review_state': state,
+        'review_state': default_state,
         'search_string': ''
         }
@@ -160,14 +152,13 @@
                              allowed = allowed,
                              )
+                             
+# return to search form  if form was not properly filled
+                             
 what = ds.get('search_mode')
 state = ds.get('review_state')
 st = term = ds.get('search_string')
 err = False
-with_review = state != "all"
-if not co_view or not ca_view:
-    only_review = with_review and not term
-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'!"
+if not term and state == "all":
+    psm = "You must specify a search string when searching for students in all states!"
     err = True
 elif '*' in term:
@@ -179,14 +170,10 @@
                              #psm = "%s, %s" % (psm,ds),
                              info = user_info,
-                             students = items,
-                             allowed = allowed,
-                             )
-#st_queries = ('jamb_reg_no','matric_no','name')
-review_res = None
-query = None
-items = []
-res = []
-review_set = []
-search_set = []
+                             students = [],
+                             allowed = allowed,
+                             )
+
+# build query string part 1
+
 query = None
 if len(term) > 0:
@@ -224,5 +211,8 @@
         logger.info('%s searches for student with name %s' % (member,term))
 
-if only_review or with_review or co_view:
+
+# build query string part 2
+
+if state != 'all':
     if query is not None:
         query = Eq('review_state',state) & query
@@ -231,7 +221,7 @@
     logger.info('%s searches for students in review_state %s' % (member,state))
 
+# build query string part 3
+
 if co_view:
-    only_review = False
-    with_review = True
     if query is not None:
         query = query & In('faculty',faculties) | In('department',departments)
@@ -239,10 +229,11 @@
         query = In('faculty',faculties) | In('department',departments)
 elif ca_view:
-    only_review = False
-    with_review = True
     courses = [cl.split('/')[0] for cl in certificate_levels]
     levels = [cl.split('/')[1] for cl in certificate_levels]
     if query is not None:
         query = query & In('course',courses) & In('level',levels)
+
+# search students_catalog
+
 student_records = aq_students(query)
 students = []
