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

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

propset Id

  • Property svn:keywords set to Id
File size: 3.4 KB
RevLine 
[600]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##
[805]10# $Id: searchAcademics.py 805 2006-11-09 09:38:29Z joachim $
[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('/')
[603]24is_manager = context.isManager
[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,
46                             is_manager = is_manager,
[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:
55    psm = "You must specify a search string when searching 'all states'."
56    err = True
57elif '*' in term:
58    psm = "you cannot use the '*' alone"
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_manager = is_manager,
[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)
94        #objects.append(context.getStudentInfo(item))
[600]95return context.academics_search_view(rendered = rend,
[611]96                             psm = "%d matching objects found" % len(objects),
[600]97                             #psm = "%s, %s" % (psm,ds),
98                             objects = objects,
99                             is_manager = is_manager,
[622]100                             choosen_ids = choosen_ids,
[600]101                             )
Note: See TracBrowser for help on using the repository browser.