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

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

add and delete for student_study_level and student_course_result

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