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

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

improved student import,
renamed layout/schema student_course_results to student_course_result

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