[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 | """ |
---|
| 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 |
---|
[611] | 22 | mtool = context.portal_membership |
---|
[600] | 23 | path_info = request.get('PATH_INFO').split('/') |
---|
[911] | 24 | is_sm = context.isSectionManager() |
---|
[600] | 25 | validate = request.has_key("cpsdocument_edit_button") |
---|
| 26 | items = [] |
---|
[603] | 27 | default = {'search_mode': 'course', |
---|
| 28 | 'review_state': 'unchecked', |
---|
[600] | 29 | 'search_string': '' |
---|
| 30 | } |
---|
[622] | 31 | choosen_ids = request.get('ids',[]) |
---|
[603] | 32 | |
---|
[600] | 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, |
---|
[911] | 46 | is_sm = is_sm, |
---|
[622] | 47 | choosen_ids = choosen_ids, |
---|
[600] | 48 | ) |
---|
| 49 | what = ds.get('search_mode') |
---|
| 50 | state = ds.get('review_state') |
---|
| 51 | term = ds.get('search_string') |
---|
[611] | 52 | err = False |
---|
| 53 | with_review = state != "all" |
---|
| 54 | if not term and not with_review: |
---|
[892] | 55 | psm = "You must specify a search string when searching 'all states'!" |
---|
[611] | 56 | err = True |
---|
| 57 | elif '*' in term: |
---|
[892] | 58 | psm = "Wildcards are not supported!" |
---|
[611] | 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, |
---|
[911] | 65 | is_sm = is_sm, |
---|
[622] | 66 | choosen_ids = choosen_ids, |
---|
[611] | 67 | ) |
---|
| 68 | with_review = state != "all" |
---|
[600] | 69 | items = [] |
---|
| 70 | res = [] |
---|
[611] | 71 | portal_type_query = {'query':['Course','CertificateCourse']} |
---|
| 72 | onlyreview = with_review and not term |
---|
[600] | 73 | if onlyreview: |
---|
| 74 | res = catalog(portal_type=portal_type_query, |
---|
| 75 | review_state=state) |
---|
[611] | 76 | elif what == "course": |
---|
| 77 | res = catalog(portal_type='Course', |
---|
[600] | 78 | SearchableText="%s*" % term.strip().lower()) |
---|
[611] | 79 | elif what == "certificate_course": |
---|
| 80 | res = catalog(portal_type='CertificateCourse', |
---|
[600] | 81 | SearchableText="%s*" % term.strip().lower()) |
---|
[611] | 82 | objects = [] |
---|
[600] | 83 | if 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] | 94 | return 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 | ) |
---|