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

Last change on this file since 984 was 971, checked in by joachim, 18 years ago

modified pumeresults upload to update results
filename must be pup_update
IMPORTANT the heading must be the same as in the first upload.
Resolved PUME Results contains a different heading.
Import of admitted Students with pictures
students_catalog created
searchStudents speedup

File size: 6.1 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                      commit = False,
66                      )
67if psm == '':
68    return context.search_students_form(rendered = rend,
69                             psm = psm,
70                             #psm = "%s, %s" % (psm,ds),
71                             students = [],
72                             allowed = True,
73                             )
74#set_trace()
75what = ds.get('search_mode')
76state = ds.get('review_state')
77st = term = ds.get('search_string')
78err = False
79with_review = state != "all"
80only_review = with_review and not term
81##with_level_results = state.startswith("category") or\
82##                     state in ('content_addable',) and\
83##                     evalAdvancedQuery is not None
84bools = "with_review = %s<br\> only_review = %s<br\>" % (with_review,only_review)
85if not term and not with_review:
86    psm = "You must specify a search string when searching 'all states'!"
87    err = True
88elif '*' in term:
89    psm = "Wildcards are not supported!"
90    err = True
91if err:
92    return context.search_students_form(rendered = rend,
93                             psm = psm,
94                             #psm = "%s, %s" % (psm,ds),
95                             students = items,
96                             allowed = True,
97                             )
98items = []
99res = []
100portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
101st_queries = ('jamb_reg_no','matric_no','name')
102query_step = 0
103review_res = None
104query = None
105if len(term) > 0:
106    if what == "student_id":
107        query_step = 1
108        query = Eq('portal_type','Student') & Eq('id', term.strip())
109    elif what in st_queries:
110        if what == "jamb_reg_no":
111            query_step = 2
112            pt = ('StudentApplication',)
113            st = "%s" % term.strip().lower()
114        elif what == "matric_no":
115            query_step = 3
116            pt = ('StudentClearance',)
117            st = "%s" % term.strip().lower()
118        elif what == "name":
119            query_step = 4
120            pt = ('StudentPersonal')
121            st = "%s" % term.strip()
122        query = In('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip())
123    res = evalAdvancedQuery(query)
124if with_review:
125    query_step += 10
126    review_res = evalAdvancedQuery(In('portal_type',student_objects) & Eq('review_state',state))
127search_set = []
128if res:
129    for r in res:
130        pl = r.getPath().split('/')
131        search_set.append(pl[pl.index('students') + 1])
132review_set = []
133if review_res:
134    for r in review_res:
135        pl = r.getPath().split('/')
136        review_set.append(pl[pl.index('students') + 1])
137all = []
138if only_review:
139    all = review_set
140elif with_review:
141    for i in search_set:
142        if i in review_set:
143            all.append(i)
144else:
145    all = search_set
146for a in all:
147    if a in items:
148        continue
149    items.append(a)
150students = []
151items.sort()
152co_view = False
153if items:
154    for item in items:
155        #if context.isClearanceOfficer(info):
156        info = {}
157        if "ClearanceOfficers" in member.getGroups():
158            co_view = True
159##            droles = member.getRolesInContext(item)
160##            if "ClearanceOfficer" in droles:
161##                info = context.getStudentInfo(item)
162##                students.append(info)
163        else:
164            #info = context.getStudentInfo(item)
165            info = context.students_catalog(id = item)
166            if len(info) == 1:
167                students.append(info[0])
168
169    return context.search_students_form(rendered = rend,
170                             psm = "",
171                             #psm = "%d,%d matching Students found QS = %s" %\
172                             #       (len(review_set),len(search_set),query_step),
173                             #psm = "%d found QS = %s items: %s" % (len(items),query_step,items),
174                             students = students,
175                             allowed = True,
176                             co_view = co_view,
177                             )
178return context.search_students_form(rendered = rend,
179                             psm = "No student found!",
180                             #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),
181                             students = students,
182                             allowed = True,
183                             )
184
185
Note: See TracBrowser for help on using the repository browser.