source: WAeUP_SRP/trunk/skins/waeup_student/searchStudents.py @ 754

Last change on this file since 754 was 751, checked in by joachim, 18 years ago

fixed searchStudents

File size: 5.6 KB
Line 
1## Script (Python) "cpsdocument_edit"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: student_edit.py 486 2006-09-06 10:09:39Z joachim $
11"""
12return Info about the current Student
13"""
14try:
15    from Products.AdvancedQuery import Eq, Between, Le,In
16    evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery
17except:
18    evalAdvancedQuery = None
19   
20request = context.REQUEST
21form = request.form
22fget = form.get
23student_subobjects = ("StudentApplication",
24                      "StudentPersonal",
25                      "StudentStudyCourse",
26                      "StudentAccommodation",
27                      "StudentStudyLevel",)
28info = {}
29items = []
30wf = context.portal_workflow
31catalog = context.portal_catalog
32#student_wf_states = wf.waeup_student_wf.states.keys()
33#info['wf_states'] = student_wf_states
34#info['wf_states'][0] = " ----- "
35lt = context.portal_layouts
36pr = context.portal_registration
37path_info = request.get('PATH_INFO').split('/')
38is_manager = context.isManager
39validate = request.has_key("cpsdocument_edit_button")
40default = {'search_mode': 'name',
41        'review_state': 'all',
42        'search_string': ''
43        }
44
45rend,psm,ds = lt.renderLayout(layout_id= 'student_search',
46                      schema_id= 'student_search',
47                      context=context,
48                      mapping=validate and request,
49                      ob=default,
50                      layout_mode='edit',
51                      formaction="searchStudents"
52                      )
53if psm == '':
54    return context.students_manager_view(rendered = rend,
55                             psm = psm,
56                             #psm = "%s, %s" % (psm,ds),
57                             students = items,
58                             is_manager = is_manager,
59                             )
60what = ds.get('search_mode')
61state = ds.get('review_state')
62st = term = ds.get('search_string')
63err = False
64with_review = state != "all"
65only_review = with_review and not term
66##with_level_results = state.startswith("category") or\
67##                     state in ('content_addable',) and\
68##                     evalAdvancedQuery is not None
69bools = "with_review = %s<br\> only_review = %s<br\>" % (with_review,only_review)
70if not term and not with_review:
71    psm = "You must specify a search string when searching 'all states'."
72    err = True
73elif '*' in term:
74    psm = "you cannot use the '*' alone"
75    err = True
76if err:
77    return context.students_manager_view(rendered = rend,
78                             psm = psm,
79                             #psm = "%s, %s" % (psm,ds),
80                             students = items,
81                             is_manager = is_manager,
82                             )
83items = []
84res = []
85portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
86st_queries = ('jamb_reg_no','matric_no','name')
87query_step = 0
88review_res = None
89query = None
90if len(term) > 0:
91    if what == "student_id":
92        query_step = 1
93        query = Eq('portal_type','Student') & Eq('id', term.strip())
94    elif what in st_queries:
95        if what == "jamb_reg_no":
96            query_step = 2
97            pt = ('StudentApplication',)
98            st = "%s" % term.strip().lower()
99        elif what == "matric_no":
100            query_step = 3
101            pt = ('StudentClearance',)
102            st = "%s" % term.strip().lower()
103        elif what == "name":
104            query_step = 4
105            pt = ('StudentPersonal')
106            st = "%s" % term.strip()
107        query = In('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip())
108    res = evalAdvancedQuery(query)
109if with_review:
110    query_step += 10
111    review_res = evalAdvancedQuery(In('portal_type',student_subobjects) & Eq('review_state',state))
112search_set = []
113if res:
114    for r in res:
115        if r.portal_type in ("StudentStudyLevel",):
116            student = r.getObject().aq_parent.aq_parent
117        elif r.portal_type in student_subobjects:
118            student = r.getObject().aq_parent
119        else:
120            student = r.getObject()
121        search_set.append(student)
122review_set = []
123if review_res:
124    for r in review_res:
125        if r.portal_type in ("StudentStudyLevel",):
126            student = r.getObject().aq_parent.aq_parent
127        elif r.portal_type in student_subobjects:
128            student = r.getObject().aq_parent
129        else:
130            student = r.getObject()
131        review_set.append(student)
132all = []
133if only_review:
134    all = review_set
135elif with_review:
136    for i in search_set:
137        if i in review_set:
138            all.append(i)
139else:
140    all = search_set
141for a in all:
142    if a in items:
143        continue
144    items.append(a)
145students = []
146if items:
147    for item in items:
148        info = context.getStudentInfo(item)
149        students.append(info)
150    return context.students_manager_view(rendered = rend,
151                             psm = "%d,%d matching Students found QS = %s" %\
152                                    (len(review_set),len(search_set),query_step),
153                             #psm = "%d found QS = %s items: %s" % (len(items),query_step,items),
154                             students = students,
155                             is_manager = is_manager,
156                             )
157return context.students_manager_view(rendered = rend,
158                             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),
159                             students = students,
160                             is_manager = is_manager,
161                             )
Note: See TracBrowser for help on using the repository browser.