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

Last change on this file since 8794 was 1164, checked in by Henrik Bettermann, 18 years ago

getStudentInfo replaced or removed

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1## Script (Python) "searchAcademics"
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: searchAcademics.py 1164 2006-12-31 10:32:05Z henrik $
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
20lt = context.portal_layouts
21pr = context.portal_registration
22mtool = context.portal_membership
23path_info = request.get('PATH_INFO').split('/')
24is_sm = context.isSectionManager()
25validate = request.has_key("cpsdocument_edit_button")
26items = []
27default = {'search_mode': 'course',
28        'review_state': 'unchecked',
29        'search_string': ''
30        }
31choosen_ids = request.get('ids',[])
32
33rend,psm,ds = lt.renderLayout(layout_id= 'academics_search',
34                      schema_id= 'academics_search',
35                      context=context,
36                      mapping=validate and request,
37                      ob=default,
38                      layout_mode='edit',
39                      formaction="searchAcademics"
40                      )
41if psm == '':
42    return context.academics_search_view(rendered = rend,
43                             psm = psm,
44                             #psm = "%s, %s" % (psm,ds),
45                             objects = items,
46                             is_sm = is_sm,
47                             choosen_ids = choosen_ids,
48                             )
49what = ds.get('search_mode')
50state = ds.get('review_state')
51term = ds.get('search_string')
52err = False
53with_review = state != "all"
54if not term and not with_review:
55    psm = "You must specify a search string when searching 'all states'!"
56    err = True
57elif '*' in term:
58    psm = "Wildcards are not supported!"
59    err = True
60if err:
61    return context.academics_search_view(rendered = rend,
62                             psm = psm,
63                             #psm = "%s, %s" % (psm,ds),
64                             students = items,
65                             is_sm = is_sm,
66                             choosen_ids = choosen_ids,
67                             )
68with_review = state != "all"
69items = []
70res = []
71portal_type_query = {'query':['Course','CertificateCourse']}
72onlyreview = with_review and not term
73if onlyreview:
74    res = catalog(portal_type=portal_type_query,
75                  review_state=state)
76elif what == "course":
77    res = catalog(portal_type='Course',
78                  SearchableText="%s*" % term.strip().lower())
79elif what == "certificate_course":
80    res = catalog(portal_type='CertificateCourse',
81                  SearchableText="%s*" % term.strip().lower())
82objects = []
83if res:
84    for r in res:
85        row = {}
86        ro = r.getObject()
87        rd = ro.getContent()
88        row['id'] = r.getId
89        row['title'] = rd.Title()
90        row['url'] = ro.absolute_url()
91        row['review_state'] = wf.getInfoFor(ro,'review_state','None')
92        row['is_editable'] = mtool.checkPermission('Modify portal content', ro)
93        objects.append(row)
94return context.academics_search_view(rendered = rend,
95                             psm = "%d matching objects found" % len(objects),
96                             #psm = "%s, %s" % (psm,ds),
97                             objects = objects,
98                             is_sm = is_sm,
99                             choosen_ids = choosen_ids,
100                             )
Note: See TracBrowser for help on using the repository browser.