[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 | """ |
---|
[727] | 14 | try: |
---|
| 15 | from Products.AdvancedQuery import Eq, Between, Le |
---|
| 16 | evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery |
---|
| 17 | except: |
---|
| 18 | evalAdvancedQuery = None |
---|
| 19 | |
---|
[565] | 20 | request = context.REQUEST |
---|
| 21 | form = request.form |
---|
| 22 | fget = form.get |
---|
[572] | 23 | info = {} |
---|
[565] | 24 | wf = context.portal_workflow |
---|
[572] | 25 | catalog = context.portal_catalog |
---|
[664] | 26 | #student_wf_states = wf.waeup_student_wf.states.keys() |
---|
| 27 | #info['wf_states'] = student_wf_states |
---|
| 28 | #info['wf_states'][0] = " ----- " |
---|
[584] | 29 | lt = context.portal_layouts |
---|
| 30 | pr = context.portal_registration |
---|
[565] | 31 | path_info = request.get('PATH_INFO').split('/') |
---|
[603] | 32 | is_manager = context.isManager |
---|
[584] | 33 | validate = request.has_key("cpsdocument_edit_button") |
---|
| 34 | items = [] |
---|
[603] | 35 | default = {'search_mode': 'name', |
---|
[663] | 36 | 'review_state': 'all', |
---|
[587] | 37 | 'search_string': '' |
---|
[584] | 38 | } |
---|
[603] | 39 | |
---|
[584] | 40 | rend,psm,ds = lt.renderLayout(layout_id= 'student_search', |
---|
| 41 | schema_id= 'student_search', |
---|
| 42 | context=context, |
---|
| 43 | mapping=validate and request, |
---|
| 44 | ob=default, |
---|
| 45 | layout_mode='edit', |
---|
| 46 | formaction="searchStudents" |
---|
| 47 | ) |
---|
| 48 | if psm == '': |
---|
| 49 | return context.students_manager_view(rendered = rend, |
---|
| 50 | psm = psm, |
---|
| 51 | #psm = "%s, %s" % (psm,ds), |
---|
| 52 | students = items, |
---|
| 53 | is_manager = is_manager, |
---|
| 54 | ) |
---|
| 55 | what = ds.get('search_mode') |
---|
| 56 | state = ds.get('review_state') |
---|
[678] | 57 | st = term = ds.get('search_string') |
---|
[589] | 58 | err = False |
---|
[599] | 59 | with_review = state != "all" |
---|
[727] | 60 | onlyreview = with_review and not term |
---|
[731] | 61 | with_level_results = state.startswith("category") or\ |
---|
| 62 | state in ('content_addable',) and\ |
---|
| 63 | evalAdvancedQuery is not None |
---|
[727] | 64 | bools = "with_review = %s<br\> onlyreview = %s<br\> with_level_results = %s" % (with_review,onlyreview,with_level_results) |
---|
[599] | 65 | if not term and not with_review: |
---|
[603] | 66 | psm = "You must specify a search string when searching 'all states'." |
---|
[589] | 67 | err = True |
---|
| 68 | elif '*' in term: |
---|
[596] | 69 | psm = "you cannot use the '*' alone" |
---|
[589] | 70 | err = True |
---|
[603] | 71 | if err: |
---|
[587] | 72 | return context.students_manager_view(rendered = rend, |
---|
[589] | 73 | psm = psm, |
---|
[587] | 74 | #psm = "%s, %s" % (psm,ds), |
---|
| 75 | students = items, |
---|
| 76 | is_manager = is_manager, |
---|
| 77 | ) |
---|
[572] | 78 | items = [] |
---|
| 79 | res = [] |
---|
| 80 | portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']} |
---|
[603] | 81 | st_queries = ('jamb_reg_no','matric_no','name') |
---|
[727] | 82 | query_step = 0 |
---|
| 83 | if onlyreview and not with_level_results: |
---|
| 84 | query_step = 1 |
---|
| 85 | query = Eq('portal_type','Student') & Eq('review_state',state) |
---|
| 86 | res = evalAdvancedQuery(query) |
---|
| 87 | ## res = catalog(portal_type='Student', |
---|
| 88 | ## review_state=state) |
---|
| 89 | elif onlyreview and with_level_results: |
---|
| 90 | query_step = 2 |
---|
[731] | 91 | query = (Eq('portal_type','StudentStudyLevel') | |
---|
| 92 | Eq('portal_type','StudentStudyCourse')) & Eq('review_state',state) |
---|
[727] | 93 | res = evalAdvancedQuery(query) |
---|
[584] | 94 | elif what == "student_id": |
---|
[596] | 95 | if with_review: |
---|
[727] | 96 | query_step = 3 |
---|
[596] | 97 | res = catalog(portal_type='Student', |
---|
| 98 | id = term.strip(), |
---|
| 99 | review_state=state) |
---|
| 100 | else: |
---|
[727] | 101 | query_step = 4 |
---|
[596] | 102 | res = catalog(portal_type='Student', |
---|
| 103 | id = term.strip()) |
---|
[727] | 104 | elif what in st_queries and not with_level_results: |
---|
[603] | 105 | if what == "jamb_reg_no": |
---|
[727] | 106 | query_step = 5 |
---|
[589] | 107 | pt = 'StudentApplication' |
---|
| 108 | st = "%s*" % term.strip().lower() |
---|
| 109 | elif what == "matric_no": |
---|
[727] | 110 | query_step = 6 |
---|
[589] | 111 | pt = 'StudentClearance' |
---|
| 112 | st = "%s*" % term.strip().lower() |
---|
| 113 | elif what == "name": |
---|
[727] | 114 | query_step = 7 |
---|
[589] | 115 | pt = portal_type_query |
---|
| 116 | st = "%s*" % term.strip() |
---|
[663] | 117 | try: |
---|
| 118 | res = catalog(portal_type=pt,SearchableText=st) |
---|
| 119 | except: |
---|
| 120 | return context.students_manager_view(rendered = rend, |
---|
| 121 | psm = 'Search string "%s" not allowed.' % term, |
---|
| 122 | #psm = "%s, %s" % (psm,ds), |
---|
| 123 | students = items, |
---|
| 124 | is_manager = is_manager, |
---|
| 125 | ) |
---|
[727] | 126 | elif what in st_queries and with_level_results and evalAdvancedQuery: |
---|
| 127 | if what == "jamb_reg_no": |
---|
| 128 | query_step = 8 |
---|
| 129 | pt = 'StudentApplication' |
---|
| 130 | st = "%s*" % term.strip().lower() |
---|
| 131 | elif what == "matric_no": |
---|
| 132 | query_step = 9 |
---|
| 133 | pt = 'StudentClearance' |
---|
| 134 | st = "%s*" % term.strip().lower() |
---|
| 135 | elif what == "name": |
---|
| 136 | query_step = 10 |
---|
| 137 | pt = portal_type_query |
---|
| 138 | st = "%s*" % term.strip() |
---|
| 139 | query = Eq('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip().lower())\ |
---|
[731] | 140 | | ((Eq('portal_type','StudentStudyLevel') | |
---|
| 141 | Eq('portal_type','StudentStudyCourse')) & Eq('review_state',state)) |
---|
[727] | 142 | try: |
---|
| 143 | res = evalAdvancedQuery(query) |
---|
| 144 | except: |
---|
| 145 | return context.students_manager_view(rendered = rend, |
---|
| 146 | psm = 'Advanced Query failed' % term, |
---|
| 147 | #psm = "%s, %s" % (psm,ds), |
---|
| 148 | students = items, |
---|
| 149 | is_manager = is_manager, |
---|
| 150 | ) |
---|
[663] | 151 | students = [] |
---|
[727] | 152 | raw_res = len(res) |
---|
[572] | 153 | if res: |
---|
| 154 | for r in res: |
---|
[731] | 155 | if r.portal_type in ("StudentApplication","StudentPersonal","StudentStudyCourse",): |
---|
[589] | 156 | student = r.getObject().aq_parent |
---|
[727] | 157 | elif r.portal_type in ("StudentStudyLevel",): |
---|
| 158 | student = r.getObject().aq_parent.aq_parent |
---|
[663] | 159 | ## pp = '/'.join(r.getPath().split('/')[:-1]) |
---|
| 160 | ## student_cat = catalog(pathindex=pp,portal_type='Student')[0] |
---|
| 161 | ## student_rs = student_cat.review_state |
---|
| 162 | ## student = student_cat.getObject() |
---|
[572] | 163 | else: |
---|
[589] | 164 | student = r.getObject() |
---|
[663] | 165 | student_rs = wf.getInfoFor(student,'review_state','keiner') |
---|
[727] | 166 | if (with_review and student_rs != state and not with_level_results) or student in items: |
---|
[663] | 167 | continue |
---|
| 168 | items.append(student) |
---|
[584] | 169 | if items: |
---|
| 170 | for item in items: |
---|
| 171 | students.append(context.getStudentInfo(item)) |
---|
[663] | 172 | return context.students_manager_view(rendered = rend, |
---|
[731] | 173 | psm = "%d matching Students found QS = %s" % (len(items),query_step), |
---|
[584] | 174 | students = students, |
---|
| 175 | is_manager = is_manager, |
---|
| 176 | ) |
---|
[663] | 177 | return context.students_manager_view(rendered = rend, |
---|
[727] | 178 | psm = """Step: %s found: %s Your search for "%s" in %s with state %s failed.<br\>%s""" % (query_step,raw_res,st,what,state,bools), |
---|
[663] | 179 | students = students, |
---|
| 180 | is_manager = is_manager, |
---|
| 181 | ) |
---|