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

Last change on this file since 1062 was 1056, checked in by Henrik Bettermann, 18 years ago

last changes undone

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