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
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##
[805]10# $Id: searchStudents.py 805 2006-11-09 09:38:29Z joachim $
[565]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
[765]20def cmp_id(a,b):
21    if a.getId() > b.getId():
22        return 1
23    return -1
24
[565]25request = context.REQUEST
26form = request.form
27fget = form.get
[750]28student_subobjects = ("StudentApplication",
29                      "StudentPersonal",
30                      "StudentStudyCourse",
31                      "StudentAccommodation",
32                      "StudentStudyLevel",)
[755]33
34student_objects = student_subobjects + ("Student",)
35
[572]36info = {}
[750]37items = []
[565]38wf = context.portal_workflow
[572]39catalog = context.portal_catalog
[664]40#student_wf_states = wf.waeup_student_wf.states.keys()
41#info['wf_states'] = student_wf_states
42#info['wf_states'][0] = " ----- "
[584]43lt = context.portal_layouts
44pr = context.portal_registration
[565]45path_info = request.get('PATH_INFO').split('/')
[603]46is_manager = context.isManager
[584]47validate = request.has_key("cpsdocument_edit_button")
[603]48default = {'search_mode': 'name',
[663]49        'review_state': 'all',
[587]50        'search_string': ''
[584]51        }
[603]52
[584]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')
[678]70st = term = ds.get('search_string')
[589]71err = False
[599]72with_review = state != "all"
[751]73only_review = with_review and not term
[750]74##with_level_results = state.startswith("category") or\
75##                     state in ('content_addable',) and\
76##                     evalAdvancedQuery is not None
[751]77bools = "with_review = %s<br\> only_review = %s<br\>" % (with_review,only_review)
[599]78if not term and not with_review:
[603]79    psm = "You must specify a search string when searching 'all states'."
[589]80    err = True
81elif '*' in term:
[596]82    psm = "you cannot use the '*' alone"
[589]83    err = True
[603]84if err:
[587]85    return context.students_manager_view(rendered = rend,
[589]86                             psm = psm,
[587]87                             #psm = "%s, %s" % (psm,ds),
88                             students = items,
89                             is_manager = is_manager,
90                             )
[572]91items = []
92res = []
93portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
[603]94st_queries = ('jamb_reg_no','matric_no','name')
[727]95query_step = 0
[751]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())
[750]116    res = evalAdvancedQuery(query)
[751]117if with_review:
118    query_step += 10
[755]119    review_res = evalAdvancedQuery(In('portal_type',student_objects) & Eq('review_state',state))
[751]120search_set = []
[572]121if res:
122    for r in res:
[750]123        if r.portal_type in ("StudentStudyLevel",):
124            student = r.getObject().aq_parent.aq_parent
125        elif r.portal_type in student_subobjects:
[589]126            student = r.getObject().aq_parent
[572]127        else:
[589]128            student = r.getObject()
[751]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 = []
[765]154items.sort(cmp_id)
[584]155if items:
156    for item in items:
[750]157        info = context.getStudentInfo(item)
158        students.append(info)
[663]159    return context.students_manager_view(rendered = rend,
[751]160                             psm = "%d,%d matching Students found QS = %s" %\
161                                    (len(review_set),len(search_set),query_step),
[750]162                             #psm = "%d found QS = %s items: %s" % (len(items),query_step,items),
[584]163                             students = students,
164                             is_manager = is_manager,
165                             )
[663]166return context.students_manager_view(rendered = rend,
[751]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),
[663]168                             students = students,
169                             is_manager = is_manager,
170                             )
Note: See TracBrowser for help on using the repository browser.