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

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

new local roles implemented
role SectionOfficer? not yet tested

  • Property svn:keywords set to Id
File size: 6.2 KB
RevLine 
[911]1## Script (Python) "searchStudents"
[565]2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
[886]7##parameters=REQUEST
[565]8##title=
9##
[805]10# $Id: searchStudents.py 911 2006-11-20 15:11:29Z henrik $
[565]11"""
[886]12list Students for ClearanceOfficers
[565]13"""
[886]14request = REQUEST
15wftool = context.portal_workflow
16mtool = context.portal_membership
17member = mtool.getAuthenticatedMember()
18roles = member.getRolesInContext(context)
[727]19try:
[750]20    from Products.AdvancedQuery import Eq, Between, Le,In
[727]21    evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery
22except:
23    evalAdvancedQuery = None
[755]24
[765]25def cmp_id(a,b):
26    if a.getId() > b.getId():
27        return 1
28    return -1
29
[565]30request = context.REQUEST
31form = request.form
32fget = form.get
[750]33student_subobjects = ("StudentApplication",
34                      "StudentPersonal",
35                      "StudentStudyCourse",
36                      "StudentAccommodation",
37                      "StudentStudyLevel",)
[755]38
39student_objects = student_subobjects + ("Student",)
40
[572]41info = {}
[750]42items = []
[565]43wf = context.portal_workflow
[572]44catalog = context.portal_catalog
[664]45#student_wf_states = wf.waeup_student_wf.states.keys()
46#info['wf_states'] = student_wf_states
47#info['wf_states'][0] = " ----- "
[584]48lt = context.portal_layouts
49pr = context.portal_registration
[565]50path_info = request.get('PATH_INFO').split('/')
[584]51validate = request.has_key("cpsdocument_edit_button")
[603]52default = {'search_mode': 'name',
[886]53        'review_state': 'clearance_requested',
[587]54        'search_string': ''
[584]55        }
[603]56
[584]57rend,psm,ds = lt.renderLayout(layout_id= 'student_search',
58                      schema_id= 'student_search',
59                      context=context,
60                      mapping=validate and request,
61                      ob=default,
62                      layout_mode='edit',
63                      formaction="searchStudents"
64                      )
65if psm == '':
[896]66    return context.students_view(rendered = rend,
[584]67                             psm = psm,
68                             #psm = "%s, %s" % (psm,ds),
69                             students = items,
[885]70                             allowed = True,
[584]71                             )
72what = ds.get('search_mode')
73state = ds.get('review_state')
[678]74st = term = ds.get('search_string')
[589]75err = False
[599]76with_review = state != "all"
[751]77only_review = with_review and not term
[750]78##with_level_results = state.startswith("category") or\
79##                     state in ('content_addable',) and\
80##                     evalAdvancedQuery is not None
[751]81bools = "with_review = %s<br\> only_review = %s<br\>" % (with_review,only_review)
[599]82if not term and not with_review:
[892]83    psm = "You must specify a search string when searching 'all states'!"
[589]84    err = True
85elif '*' in term:
[892]86    psm = "Wildcards are not supported!"
[589]87    err = True
[603]88if err:
[896]89    return context.students_view(rendered = rend,
[589]90                             psm = psm,
[587]91                             #psm = "%s, %s" % (psm,ds),
92                             students = items,
[885]93                             allowed = True,
[587]94                             )
[572]95items = []
96res = []
97portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']}
[603]98st_queries = ('jamb_reg_no','matric_no','name')
[727]99query_step = 0
[751]100review_res = None
101query = None
102if len(term) > 0:
103    if what == "student_id":
104        query_step = 1
105        query = Eq('portal_type','Student') & Eq('id', term.strip())
106    elif what in st_queries:
107        if what == "jamb_reg_no":
108            query_step = 2
109            pt = ('StudentApplication',)
110            st = "%s" % term.strip().lower()
111        elif what == "matric_no":
112            query_step = 3
113            pt = ('StudentClearance',)
114            st = "%s" % term.strip().lower()
115        elif what == "name":
116            query_step = 4
117            pt = ('StudentPersonal')
118            st = "%s" % term.strip()
119        query = In('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip())
[750]120    res = evalAdvancedQuery(query)
[751]121if with_review:
122    query_step += 10
[755]123    review_res = evalAdvancedQuery(In('portal_type',student_objects) & Eq('review_state',state))
[751]124search_set = []
[572]125if res:
126    for r in res:
[750]127        if r.portal_type in ("StudentStudyLevel",):
128            student = r.getObject().aq_parent.aq_parent
129        elif r.portal_type in student_subobjects:
[589]130            student = r.getObject().aq_parent
[572]131        else:
[589]132            student = r.getObject()
[751]133        search_set.append(student)
134review_set = []
135if review_res:
136    for r in review_res:
137        if r.portal_type in ("StudentStudyLevel",):
138            student = r.getObject().aq_parent.aq_parent
139        elif r.portal_type in student_subobjects:
140            student = r.getObject().aq_parent
141        else:
142            student = r.getObject()
143        review_set.append(student)
144all = []
145if only_review:
146    all = review_set
147elif with_review:
148    for i in search_set:
149        if i in review_set:
150            all.append(i)
151else:
152    all = search_set
153for a in all:
154    if a in items:
155        continue
156    items.append(a)
157students = []
[765]158items.sort(cmp_id)
[887]159co_view = False
[584]160if items:
161    for item in items:
[886]162        #if context.isClearanceOfficer(info):
163        if "ClearanceOfficers" in member.getGroups():
[887]164            co_view = True
[886]165            droles = member.getRolesInContext(item)
166            if "ClearanceOfficer" in droles:
167                info = context.getStudentInfo(item)
168                students.append(info)
169        else:
170            info = context.getStudentInfo(item)
171            students.append(info)
[891]172
[896]173    return context.students_view(rendered = rend,
[886]174                             psm = "",
175                             #psm = "%d,%d matching Students found QS = %s" %\
176                             #       (len(review_set),len(search_set),query_step),
[750]177                             #psm = "%d found QS = %s items: %s" % (len(items),query_step,items),
[584]178                             students = students,
[885]179                             allowed = True,
[887]180                             co_view = co_view,
[584]181                             )
[896]182return context.students_view(rendered = rend,
[891]183                             psm = "No student found!",
184                             #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]185                             students = students,
[885]186                             allowed = True,
[663]187                             )
[886]188
189
Note: See TracBrowser for help on using the repository browser.