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

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

academisSearch can now be used for searching Courses,
the context is not yet taken into account,
the delete button does not work correctly yet.
pleade edit layout academics_search and the vocabularies to fit your needs

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