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

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

more unifications

  • Property svn:keywords set to Id
File size: 6.3 KB
Line 
1## Script (Python) "co_searchStudents"
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: searchStudents.py 887 2006-11-17 16:38:42Z joachim $
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('/')
51is_manager = context.isManager()
52validate = request.has_key("cpsdocument_edit_button")
53default = {'search_mode': 'name',
54        'review_state': 'clearance_requested',
55        'search_string': ''
56        }
57
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="searchStudents"
65                      )
66if psm == '':
67    return context.students_manager_view(rendered = rend,
68                             psm = psm,
69                             #psm = "%s, %s" % (psm,ds),
70                             students = items,
71                             allowed = True,
72                             )
73what = ds.get('search_mode')
74state = ds.get('review_state')
75st = term = ds.get('search_string')
76err = False
77with_review = state != "all"
78only_review = with_review and not term
79##with_level_results = state.startswith("category") or\
80##                     state in ('content_addable',) and\
81##                     evalAdvancedQuery is not None
82bools = "with_review = %s<br\> only_review = %s<br\>" % (with_review,only_review)
83if not term and not with_review:
84    psm = "You must specify a search string when searching 'all states'."
85    err = True
86elif '*' in term:
87    psm = "you cannot use the '*' alone"
88    err = True
89if err:
90    return context.students_manager_view(rendered = rend,
91                             psm = psm,
92                             #psm = "%s, %s" % (psm,ds),
93                             students = items,
94                             allowed = True,
95                             )
96items = []
97res = []
98portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
99st_queries = ('jamb_reg_no','matric_no','name')
100query_step = 0
101review_res = None
102query = None
103if len(term) > 0:
104    if what == "student_id":
105        query_step = 1
106        query = Eq('portal_type','Student') & Eq('id', term.strip())
107    elif what in st_queries:
108        if what == "jamb_reg_no":
109            query_step = 2
110            pt = ('StudentApplication',)
111            st = "%s" % term.strip().lower()
112        elif what == "matric_no":
113            query_step = 3
114            pt = ('StudentClearance',)
115            st = "%s" % term.strip().lower()
116        elif what == "name":
117            query_step = 4
118            pt = ('StudentPersonal')
119            st = "%s" % term.strip()
120        query = In('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip())
121    res = evalAdvancedQuery(query)
122if with_review:
123    query_step += 10
124    review_res = evalAdvancedQuery(In('portal_type',student_objects) & Eq('review_state',state))
125search_set = []
126if res:
127    for r in res:
128        if r.portal_type in ("StudentStudyLevel",):
129            student = r.getObject().aq_parent.aq_parent
130        elif r.portal_type in student_subobjects:
131            student = r.getObject().aq_parent
132        else:
133            student = r.getObject()
134        search_set.append(student)
135review_set = []
136if review_res:
137    for r in review_res:
138        if r.portal_type in ("StudentStudyLevel",):
139            student = r.getObject().aq_parent.aq_parent
140        elif r.portal_type in student_subobjects:
141            student = r.getObject().aq_parent
142        else:
143            student = r.getObject()
144        review_set.append(student)
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:
155    if a in items:
156        continue
157    items.append(a)
158students = []
159items.sort(cmp_id)
160co_view = False
161if items:
162    for item in items:
163        #if context.isClearanceOfficer(info):
164        if "ClearanceOfficers" in member.getGroups():
165            co_view = True
166            droles = member.getRolesInContext(item)
167            if "ClearanceOfficer" in droles:
168                info = context.getStudentInfo(item)
169                students.append(info)
170        else:
171            info = context.getStudentInfo(item)
172            students.append(info)
173               
174    return context.students_manager_view(rendered = rend,
175                             psm = "",
176                             #psm = "%d,%d matching Students found QS = %s" %\
177                             #       (len(review_set),len(search_set),query_step),
178                             #psm = "%d found QS = %s items: %s" % (len(items),query_step,items),
179                             students = students,
180                             allowed = True,
181                             co_view = co_view,
182                             )
183return context.students_manager_view(rendered = rend,
184                             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),
185                             students = students,
186                             allowed = True,
187                             )
188
189
Note: See TracBrowser for help on using the repository browser.