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

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

search for student review_states included

File size: 5.6 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:
[750]15    from Products.AdvancedQuery import Eq, Between, Le,In
[727]16    evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery
17except:
18    evalAdvancedQuery = None
[755]19
[565]20request = context.REQUEST
21form = request.form
22fget = form.get
[750]23student_subobjects = ("StudentApplication",
24                      "StudentPersonal",
25                      "StudentStudyCourse",
26                      "StudentAccommodation",
27                      "StudentStudyLevel",)
[755]28
29student_objects = student_subobjects + ("Student",)
30
[572]31info = {}
[750]32items = []
[565]33wf = context.portal_workflow
[572]34catalog = context.portal_catalog
[664]35#student_wf_states = wf.waeup_student_wf.states.keys()
36#info['wf_states'] = student_wf_states
37#info['wf_states'][0] = " ----- "
[584]38lt = context.portal_layouts
39pr = context.portal_registration
[565]40path_info = request.get('PATH_INFO').split('/')
[603]41is_manager = context.isManager
[584]42validate = request.has_key("cpsdocument_edit_button")
[603]43default = {'search_mode': 'name',
[663]44        'review_state': 'all',
[587]45        'search_string': ''
[584]46        }
[603]47
[584]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')
[678]65st = term = ds.get('search_string')
[589]66err = False
[599]67with_review = state != "all"
[751]68only_review = with_review and not term
[750]69##with_level_results = state.startswith("category") or\
70##                     state in ('content_addable',) and\
71##                     evalAdvancedQuery is not None
[751]72bools = "with_review = %s<br\> only_review = %s<br\>" % (with_review,only_review)
[599]73if not term and not with_review:
[603]74    psm = "You must specify a search string when searching 'all states'."
[589]75    err = True
76elif '*' in term:
[596]77    psm = "you cannot use the '*' alone"
[589]78    err = True
[603]79if err:
[587]80    return context.students_manager_view(rendered = rend,
[589]81                             psm = psm,
[587]82                             #psm = "%s, %s" % (psm,ds),
83                             students = items,
84                             is_manager = is_manager,
85                             )
[572]86items = []
87res = []
88portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
[603]89st_queries = ('jamb_reg_no','matric_no','name')
[727]90query_step = 0
[751]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())
[750]111    res = evalAdvancedQuery(query)
[751]112if with_review:
113    query_step += 10
[755]114    review_res = evalAdvancedQuery(In('portal_type',student_objects) & Eq('review_state',state))
[751]115search_set = []
[572]116if res:
117    for r in res:
[750]118        if r.portal_type in ("StudentStudyLevel",):
119            student = r.getObject().aq_parent.aq_parent
120        elif r.portal_type in student_subobjects:
[589]121            student = r.getObject().aq_parent
[572]122        else:
[589]123            student = r.getObject()
[751]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 = []
[584]149if items:
150    for item in items:
[750]151        info = context.getStudentInfo(item)
152        students.append(info)
[663]153    return context.students_manager_view(rendered = rend,
[751]154                             psm = "%d,%d matching Students found QS = %s" %\
155                                    (len(review_set),len(search_set),query_step),
[750]156                             #psm = "%d found QS = %s items: %s" % (len(items),query_step,items),
[584]157                             students = students,
158                             is_manager = is_manager,
159                             )
[663]160return context.students_manager_view(rendered = rend,
[751]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),
[663]162                             students = students,
163                             is_manager = is_manager,
164                             )
Note: See TracBrowser for help on using the repository browser.