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

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

propset Id

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