source: WAeUP_SRP/trunk/skins/waeup_academics/searchAcademics.py @ 600

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

added new methods isManager and isStudent, which are now used in all
getXXXInfo Scripts,
searchAcademics Form added - search not working yet.

File size: 3.4 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"""
14request = context.REQUEST
15form = request.form
16fget = form.get
17info = {}
18wf = context.portal_workflow
19catalog = context.portal_catalog
20mtool = context.portal_membership
21member = mtool.getAuthenticatedMember()
22lt = context.portal_layouts
23pr = context.portal_registration
24path_info = request.get('PATH_INFO').split('/')
25roles = member.getRoles()
26is_manager = 'Manager' in roles or 'SectionManager' in roles
27validate = request.has_key("cpsdocument_edit_button")
28items = []
29default = {'search_mode': 'course',
30        'review_state': 'unchecked',
31        'search_string': ''
32        }
33       
34rend,psm,ds = lt.renderLayout(layout_id= 'academics_search',
35                      schema_id= 'academics_search',
36                      context=context,
37                      mapping=validate and request,
38                      ob=default,
39                      layout_mode='edit',
40                      formaction="searchAcademics"
41                      )
42if psm == '':
43    return context.academics_search_view(rendered = rend,
44                             psm = psm,
45                             #psm = "%s, %s" % (psm,ds),
46                             objects = items,
47                             is_manager = is_manager,
48                             )
49what = ds.get('search_mode')
50state = ds.get('review_state')
51term = ds.get('search_string')
52if state == " ----- ":
53    state = ''
54if not term and what in ('student_edit','jamb_id','name','matric_no'):
55    return context.academics_search_view(rendered = rend,
56                             psm = "You must specify a search string",
57                             #psm = "%s, %s" % (psm,ds),
58                             objects = items,
59                             is_manager = is_manager,
60                             )
61onlyreview = state and what == "review_state"
62items = []
63res = []
64portal_type_query = {'query':['Department','Course','CertificateCourse']}
65if onlyreview:
66    res = catalog(portal_type=portal_type_query,
67                  review_state=state)
68elif what == "student_id":
69    res = catalog(portal_type='Student',
70                  id = term.strip())
71elif what == "jamb_id":
72    res = catalog(portal_type='StudentApplication',
73                  SearchableText="%s*" % term.strip().lower())
74elif what == "matric_no":
75    res = catalog(portal_type='StudentClearance',
76                  SearchableText="%s*" % term.strip().lower())
77elif what == "name":
78    res = catalog(portal_type=portal_type_query,
79                  SearchableText="%s*" % term.strip())
80if res:
81    for r in res:
82        row = {}
83        if r.portal_type in ("StudentApplication","StudentPersonal"):
84            items.append(r.getObject().aq_parent)
85        else:
86            items.append(r.getObject())
87objects = []
88if items:
89    for item in items:
90        objects.append(context.getStudentInfo(item))
91return context.academics_search_view(rendered = rend,
92                             psm = "%d matching objects found" % len(items),
93                             #psm = "%s, %s" % (psm,ds),
94                             objects = objects,
95                             is_manager = is_manager,
96                             )
Note: See TracBrowser for help on using the repository browser.