[565] | 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 |
---|
[584] | 7 | ##parameters= |
---|
[565] | 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: student_edit.py 486 2006-09-06 10:09:39Z joachim $ |
---|
| 11 | """ |
---|
| 12 | return Info about the current Student |
---|
| 13 | """ |
---|
[589] | 14 | #from Products.ZCTextIndex.QueryParser import ParseError,QueryError |
---|
[565] | 15 | request = context.REQUEST |
---|
| 16 | form = request.form |
---|
| 17 | fget = form.get |
---|
[572] | 18 | info = {} |
---|
[565] | 19 | wf = context.portal_workflow |
---|
[572] | 20 | catalog = context.portal_catalog |
---|
| 21 | student_wf_states = wf.waeup_student_wf.states.keys() |
---|
| 22 | info['wf_states'] = student_wf_states |
---|
| 23 | info['wf_states'][0] = " ----- " |
---|
[584] | 24 | lt = context.portal_layouts |
---|
| 25 | pr = context.portal_registration |
---|
[565] | 26 | path_info = request.get('PATH_INFO').split('/') |
---|
[603] | 27 | is_manager = context.isManager |
---|
[584] | 28 | validate = request.has_key("cpsdocument_edit_button") |
---|
| 29 | items = [] |
---|
[603] | 30 | default = {'search_mode': 'name', |
---|
| 31 | 'review_state': 'created', |
---|
[587] | 32 | 'search_string': '' |
---|
[584] | 33 | } |
---|
[603] | 34 | |
---|
[584] | 35 | rend,psm,ds = lt.renderLayout(layout_id= 'student_search', |
---|
| 36 | schema_id= 'student_search', |
---|
| 37 | context=context, |
---|
| 38 | mapping=validate and request, |
---|
| 39 | ob=default, |
---|
| 40 | layout_mode='edit', |
---|
| 41 | formaction="searchStudents" |
---|
| 42 | ) |
---|
| 43 | if psm == '': |
---|
| 44 | return context.students_manager_view(rendered = rend, |
---|
| 45 | psm = psm, |
---|
| 46 | #psm = "%s, %s" % (psm,ds), |
---|
| 47 | students = items, |
---|
| 48 | is_manager = is_manager, |
---|
| 49 | ) |
---|
| 50 | what = ds.get('search_mode') |
---|
| 51 | state = ds.get('review_state') |
---|
| 52 | term = ds.get('search_string') |
---|
[589] | 53 | err = False |
---|
[599] | 54 | with_review = state != "all" |
---|
| 55 | if not term and not with_review: |
---|
[603] | 56 | psm = "You must specify a search string when searching 'all states'." |
---|
[589] | 57 | err = True |
---|
| 58 | elif '*' in term: |
---|
[596] | 59 | psm = "you cannot use the '*' alone" |
---|
[589] | 60 | err = True |
---|
[603] | 61 | if err: |
---|
[587] | 62 | return context.students_manager_view(rendered = rend, |
---|
[589] | 63 | psm = psm, |
---|
[587] | 64 | #psm = "%s, %s" % (psm,ds), |
---|
| 65 | students = items, |
---|
| 66 | is_manager = is_manager, |
---|
| 67 | ) |
---|
[596] | 68 | with_review = state != "all" |
---|
[572] | 69 | items = [] |
---|
| 70 | res = [] |
---|
| 71 | portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']} |
---|
[603] | 72 | st_queries = ('jamb_reg_no','matric_no','name') |
---|
[599] | 73 | onlyreview = with_review and not term |
---|
[572] | 74 | if onlyreview: |
---|
[622] | 75 | res = catalog(portal_type=portal_type_query, |
---|
[572] | 76 | review_state=state) |
---|
[584] | 77 | elif what == "student_id": |
---|
[596] | 78 | if with_review: |
---|
| 79 | res = catalog(portal_type='Student', |
---|
| 80 | id = term.strip(), |
---|
| 81 | review_state=state) |
---|
| 82 | else: |
---|
| 83 | res = catalog(portal_type='Student', |
---|
| 84 | id = term.strip()) |
---|
[603] | 85 | elif what in st_queries: |
---|
| 86 | if what == "jamb_reg_no": |
---|
[589] | 87 | pt = 'StudentApplication' |
---|
| 88 | st = "%s*" % term.strip().lower() |
---|
| 89 | elif what == "matric_no": |
---|
| 90 | pt = 'StudentClearance' |
---|
| 91 | st = "%s*" % term.strip().lower() |
---|
| 92 | elif what == "name": |
---|
| 93 | pt = portal_type_query |
---|
| 94 | st = "%s*" % term.strip() |
---|
[596] | 95 | if with_review: |
---|
| 96 | try: |
---|
[622] | 97 | res = catalog(portal_type=pt,SearchableText=st, |
---|
[596] | 98 | review_state=state) |
---|
| 99 | except: |
---|
| 100 | return context.students_manager_view(rendered = rend, |
---|
[603] | 101 | psm = 'Search string "%s" not allowed.' % term, |
---|
[596] | 102 | #psm = "%s, %s" % (psm,ds), |
---|
| 103 | students = items, |
---|
| 104 | is_manager = is_manager, |
---|
| 105 | ) |
---|
| 106 | else: |
---|
| 107 | try: |
---|
| 108 | res = catalog(portal_type=pt,SearchableText=st,) |
---|
| 109 | except: |
---|
| 110 | return context.students_manager_view(rendered = rend, |
---|
| 111 | psm = 'Searchstring "%s" not allowed' % term, |
---|
| 112 | #psm = "%s, %s" % (psm,ds), |
---|
| 113 | students = items, |
---|
| 114 | is_manager = is_manager, |
---|
| 115 | ) |
---|
[603] | 116 | |
---|
[572] | 117 | if res: |
---|
| 118 | for r in res: |
---|
| 119 | if r.portal_type in ("StudentApplication","StudentPersonal"): |
---|
[589] | 120 | student = r.getObject().aq_parent |
---|
[572] | 121 | else: |
---|
[589] | 122 | student = r.getObject() |
---|
| 123 | if student not in items: |
---|
| 124 | items.append(student) |
---|
[584] | 125 | students = [] |
---|
| 126 | if items: |
---|
| 127 | for item in items: |
---|
| 128 | students.append(context.getStudentInfo(item)) |
---|
| 129 | return context.students_manager_view(rendered = rend, |
---|
| 130 | psm = "%d matching Students found" % len(items), |
---|
| 131 | #psm = "%s, %s" % (psm,ds), |
---|
| 132 | students = students, |
---|
| 133 | is_manager = is_manager, |
---|
| 134 | ) |
---|