source: WAeUP_SRP/trunk/skins/waeup_student/search_students.py @ 967

Last change on this file since 967 was 966, checked in by joachim, 18 years ago

created new catalog pumeresults for pumeresult checking
modified pume_anon_view and pume_anon_slip to use it.

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