[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] = " ----- " |
---|
[565] | 24 | mtool = context.portal_membership |
---|
| 25 | member = mtool.getAuthenticatedMember() |
---|
[584] | 26 | lt = context.portal_layouts |
---|
| 27 | pr = context.portal_registration |
---|
[565] | 28 | path_info = request.get('PATH_INFO').split('/') |
---|
| 29 | roles = member.getRoles() |
---|
[584] | 30 | is_manager = 'Manager' in roles or 'SectionManager' in roles |
---|
| 31 | validate = request.has_key("cpsdocument_edit_button") |
---|
| 32 | items = [] |
---|
| 33 | default = {'search_mode': 'name', |
---|
| 34 | 'review_state': 'admission_applied ', |
---|
[587] | 35 | 'search_string': '' |
---|
[584] | 36 | } |
---|
| 37 | |
---|
| 38 | rend,psm,ds = lt.renderLayout(layout_id= 'student_search', |
---|
| 39 | schema_id= 'student_search', |
---|
| 40 | context=context, |
---|
| 41 | mapping=validate and request, |
---|
| 42 | ob=default, |
---|
| 43 | layout_mode='edit', |
---|
| 44 | formaction="searchStudents" |
---|
| 45 | ) |
---|
| 46 | if psm == '': |
---|
| 47 | return context.students_manager_view(rendered = rend, |
---|
| 48 | psm = psm, |
---|
| 49 | #psm = "%s, %s" % (psm,ds), |
---|
| 50 | students = items, |
---|
| 51 | is_manager = is_manager, |
---|
| 52 | ) |
---|
| 53 | what = ds.get('search_mode') |
---|
| 54 | state = ds.get('review_state') |
---|
| 55 | term = ds.get('search_string') |
---|
[589] | 56 | err = False |
---|
[599] | 57 | with_review = state != "all" |
---|
| 58 | if not term and not with_review: |
---|
[596] | 59 | psm = "You must specify a search string when searching in 'All States'" |
---|
[589] | 60 | err = True |
---|
| 61 | elif '*' in term: |
---|
[596] | 62 | psm = "you cannot use the '*' alone" |
---|
[589] | 63 | err = True |
---|
| 64 | if err: |
---|
[587] | 65 | return context.students_manager_view(rendered = rend, |
---|
[589] | 66 | psm = psm, |
---|
[587] | 67 | #psm = "%s, %s" % (psm,ds), |
---|
| 68 | students = items, |
---|
| 69 | is_manager = is_manager, |
---|
| 70 | ) |
---|
[596] | 71 | with_review = state != "all" |
---|
[572] | 72 | items = [] |
---|
| 73 | res = [] |
---|
| 74 | portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']} |
---|
[589] | 75 | st_queries = ('jamb_id','matric_no','name') |
---|
[599] | 76 | onlyreview = with_review and not term |
---|
[572] | 77 | if onlyreview: |
---|
| 78 | res = catalog(portal_type=portal_type_query, |
---|
| 79 | review_state=state) |
---|
[584] | 80 | elif what == "student_id": |
---|
[596] | 81 | if with_review: |
---|
| 82 | res = catalog(portal_type='Student', |
---|
| 83 | id = term.strip(), |
---|
| 84 | review_state=state) |
---|
| 85 | else: |
---|
| 86 | res = catalog(portal_type='Student', |
---|
| 87 | id = term.strip()) |
---|
[589] | 88 | elif what in st_queries: |
---|
| 89 | if what == "jamb_id": |
---|
| 90 | pt = 'StudentApplication' |
---|
| 91 | st = "%s*" % term.strip().lower() |
---|
| 92 | elif what == "matric_no": |
---|
| 93 | pt = 'StudentClearance' |
---|
| 94 | st = "%s*" % term.strip().lower() |
---|
| 95 | elif what == "name": |
---|
| 96 | pt = portal_type_query |
---|
| 97 | st = "%s*" % term.strip() |
---|
[596] | 98 | if with_review: |
---|
| 99 | try: |
---|
| 100 | res = catalog(portal_type=pt,SearchableText=st, |
---|
| 101 | review_state=state) |
---|
| 102 | except: |
---|
| 103 | return context.students_manager_view(rendered = rend, |
---|
| 104 | psm = 'Searchstring "%s" not allowed' % term, |
---|
| 105 | #psm = "%s, %s" % (psm,ds), |
---|
| 106 | students = items, |
---|
| 107 | is_manager = is_manager, |
---|
| 108 | ) |
---|
| 109 | else: |
---|
| 110 | try: |
---|
| 111 | res = catalog(portal_type=pt,SearchableText=st,) |
---|
| 112 | except: |
---|
| 113 | return context.students_manager_view(rendered = rend, |
---|
| 114 | psm = 'Searchstring "%s" not allowed' % term, |
---|
| 115 | #psm = "%s, %s" % (psm,ds), |
---|
| 116 | students = items, |
---|
| 117 | is_manager = is_manager, |
---|
| 118 | ) |
---|
[589] | 119 | |
---|
[572] | 120 | if res: |
---|
| 121 | for r in res: |
---|
| 122 | if r.portal_type in ("StudentApplication","StudentPersonal"): |
---|
[589] | 123 | student = r.getObject().aq_parent |
---|
[572] | 124 | else: |
---|
[589] | 125 | student = r.getObject() |
---|
| 126 | if student not in items: |
---|
| 127 | items.append(student) |
---|
[584] | 128 | students = [] |
---|
| 129 | if items: |
---|
| 130 | for item in items: |
---|
| 131 | students.append(context.getStudentInfo(item)) |
---|
| 132 | return context.students_manager_view(rendered = rend, |
---|
| 133 | psm = "%d matching Students found" % len(items), |
---|
| 134 | #psm = "%s, %s" % (psm,ds), |
---|
| 135 | students = students, |
---|
| 136 | is_manager = is_manager, |
---|
| 137 | ) |
---|