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 | """ |
---|
12 | return Info about the current Student |
---|
13 | """ |
---|
14 | request = context.REQUEST |
---|
15 | form = request.form |
---|
16 | fget = form.get |
---|
17 | info = {} |
---|
18 | wf = context.portal_workflow |
---|
19 | catalog = context.portal_catalog |
---|
20 | lt = context.portal_layouts |
---|
21 | pr = context.portal_registration |
---|
22 | mtool = context.portal_membership |
---|
23 | path_info = request.get('PATH_INFO').split('/') |
---|
24 | is_sm = context.isSectionManager() |
---|
25 | validate = request.has_key("cpsdocument_edit_button") |
---|
26 | items = [] |
---|
27 | default = {'search_mode': 'course', |
---|
28 | 'review_state': 'unchecked', |
---|
29 | 'search_string': '' |
---|
30 | } |
---|
31 | choosen_ids = request.get('ids',[]) |
---|
32 | |
---|
33 | rend,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 | ) |
---|
41 | if 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 | ) |
---|
49 | what = ds.get('search_mode') |
---|
50 | state = ds.get('review_state') |
---|
51 | term = ds.get('search_string') |
---|
52 | err = False |
---|
53 | with_review = state != "all" |
---|
54 | if not term and not with_review: |
---|
55 | psm = "You must specify a search string when searching 'all states'!" |
---|
56 | err = True |
---|
57 | elif '*' in term: |
---|
58 | psm = "Wildcards are not supported!" |
---|
59 | err = True |
---|
60 | if 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 | ) |
---|
68 | with_review = state != "all" |
---|
69 | items = [] |
---|
70 | res = [] |
---|
71 | portal_type_query = {'query':['Course','CertificateCourse']} |
---|
72 | onlyreview = with_review and not term |
---|
73 | if onlyreview: |
---|
74 | res = catalog(portal_type=portal_type_query, |
---|
75 | review_state=state) |
---|
76 | elif what == "course": |
---|
77 | res = catalog(portal_type='Course', |
---|
78 | SearchableText="%s*" % term.strip().lower()) |
---|
79 | elif what == "certificate_course": |
---|
80 | res = catalog(portal_type='CertificateCourse', |
---|
81 | SearchableText="%s*" % term.strip().lower()) |
---|
82 | objects = [] |
---|
83 | if 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) |
---|
94 | return 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 | ) |
---|