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

Last change on this file since 10925 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
RevLine 
[845]1## Script (Python) "searchAcademics"
[600]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##
[805]10# $Id: searchAcademics.py 1164 2006-12-31 10:32:05Z henrik $
[600]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
[611]22mtool = context.portal_membership
[600]23path_info = request.get('PATH_INFO').split('/')
[911]24is_sm = context.isSectionManager()
[600]25validate = request.has_key("cpsdocument_edit_button")
26items = []
[603]27default = {'search_mode': 'course',
28        'review_state': 'unchecked',
[600]29        'search_string': ''
30        }
[622]31choosen_ids = request.get('ids',[])
[603]32
[600]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,
[911]46                             is_sm = is_sm,
[622]47                             choosen_ids = choosen_ids,
[600]48                             )
49what = ds.get('search_mode')
50state = ds.get('review_state')
51term = ds.get('search_string')
[611]52err = False
53with_review = state != "all"
54if not term and not with_review:
[892]55    psm = "You must specify a search string when searching 'all states'!"
[611]56    err = True
57elif '*' in term:
[892]58    psm = "Wildcards are not supported!"
[611]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,
[911]65                             is_sm = is_sm,
[622]66                             choosen_ids = choosen_ids,
[611]67                             )
68with_review = state != "all"
[600]69items = []
70res = []
[611]71portal_type_query = {'query':['Course','CertificateCourse']}
72onlyreview = with_review and not term
[600]73if onlyreview:
74    res = catalog(portal_type=portal_type_query,
75                  review_state=state)
[611]76elif what == "course":
77    res = catalog(portal_type='Course',
[600]78                  SearchableText="%s*" % term.strip().lower())
[611]79elif what == "certificate_course":
80    res = catalog(portal_type='CertificateCourse',
[600]81                  SearchableText="%s*" % term.strip().lower())
[611]82objects = []
[600]83if res:
84    for r in res:
85        row = {}
[611]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)
[600]94return context.academics_search_view(rendered = rend,
[611]95                             psm = "%d matching objects found" % len(objects),
[600]96                             #psm = "%s, %s" % (psm,ds),
97                             objects = objects,
[911]98                             is_sm = is_sm,
[622]99                             choosen_ids = choosen_ids,
[600]100                             )
Note: See TracBrowser for help on using the repository browser.