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

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

search for student review_states included

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