[886] | 1 | ## Script (Python) "co_searchStudents" |
---|
[565] | 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
[886] | 7 | ##parameters=REQUEST |
---|
[565] | 8 | ##title= |
---|
| 9 | ## |
---|
[805] | 10 | # $Id: searchStudents.py 903 2006-11-20 08:08:10Z henrik $ |
---|
[565] | 11 | """ |
---|
[886] | 12 | list Students for ClearanceOfficers |
---|
[565] | 13 | """ |
---|
[886] | 14 | request = REQUEST |
---|
| 15 | wftool = context.portal_workflow |
---|
| 16 | mtool = context.portal_membership |
---|
| 17 | member = mtool.getAuthenticatedMember() |
---|
| 18 | roles = member.getRolesInContext(context) |
---|
[727] | 19 | try: |
---|
[750] | 20 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
[727] | 21 | evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery |
---|
| 22 | except: |
---|
| 23 | evalAdvancedQuery = None |
---|
[755] | 24 | |
---|
[765] | 25 | def cmp_id(a,b): |
---|
| 26 | if a.getId() > b.getId(): |
---|
| 27 | return 1 |
---|
| 28 | return -1 |
---|
| 29 | |
---|
[565] | 30 | request = context.REQUEST |
---|
| 31 | form = request.form |
---|
| 32 | fget = form.get |
---|
[750] | 33 | student_subobjects = ("StudentApplication", |
---|
| 34 | "StudentPersonal", |
---|
| 35 | "StudentStudyCourse", |
---|
| 36 | "StudentAccommodation", |
---|
| 37 | "StudentStudyLevel",) |
---|
[755] | 38 | |
---|
| 39 | student_objects = student_subobjects + ("Student",) |
---|
| 40 | |
---|
[572] | 41 | info = {} |
---|
[750] | 42 | items = [] |
---|
[565] | 43 | wf = context.portal_workflow |
---|
[572] | 44 | catalog = context.portal_catalog |
---|
[664] | 45 | #student_wf_states = wf.waeup_student_wf.states.keys() |
---|
| 46 | #info['wf_states'] = student_wf_states |
---|
| 47 | #info['wf_states'][0] = " ----- " |
---|
[584] | 48 | lt = context.portal_layouts |
---|
| 49 | pr = context.portal_registration |
---|
[565] | 50 | path_info = request.get('PATH_INFO').split('/') |
---|
[903] | 51 | is_manager = context.isSectionManager() |
---|
[584] | 52 | validate = request.has_key("cpsdocument_edit_button") |
---|
[603] | 53 | default = {'search_mode': 'name', |
---|
[886] | 54 | 'review_state': 'clearance_requested', |
---|
[587] | 55 | 'search_string': '' |
---|
[584] | 56 | } |
---|
[603] | 57 | |
---|
[584] | 58 | rend,psm,ds = lt.renderLayout(layout_id= 'student_search', |
---|
| 59 | schema_id= 'student_search', |
---|
| 60 | context=context, |
---|
| 61 | mapping=validate and request, |
---|
| 62 | ob=default, |
---|
| 63 | layout_mode='edit', |
---|
| 64 | formaction="searchStudents" |
---|
| 65 | ) |
---|
| 66 | if psm == '': |
---|
[896] | 67 | return context.students_view(rendered = rend, |
---|
[584] | 68 | psm = psm, |
---|
| 69 | #psm = "%s, %s" % (psm,ds), |
---|
| 70 | students = items, |
---|
[885] | 71 | allowed = True, |
---|
[584] | 72 | ) |
---|
| 73 | what = ds.get('search_mode') |
---|
| 74 | state = ds.get('review_state') |
---|
[678] | 75 | st = term = ds.get('search_string') |
---|
[589] | 76 | err = False |
---|
[599] | 77 | with_review = state != "all" |
---|
[751] | 78 | only_review = with_review and not term |
---|
[750] | 79 | ##with_level_results = state.startswith("category") or\ |
---|
| 80 | ## state in ('content_addable',) and\ |
---|
| 81 | ## evalAdvancedQuery is not None |
---|
[751] | 82 | bools = "with_review = %s<br\> only_review = %s<br\>" % (with_review,only_review) |
---|
[599] | 83 | if not term and not with_review: |
---|
[892] | 84 | psm = "You must specify a search string when searching 'all states'!" |
---|
[589] | 85 | err = True |
---|
| 86 | elif '*' in term: |
---|
[892] | 87 | psm = "Wildcards are not supported!" |
---|
[589] | 88 | err = True |
---|
[603] | 89 | if err: |
---|
[896] | 90 | return context.students_view(rendered = rend, |
---|
[589] | 91 | psm = psm, |
---|
[587] | 92 | #psm = "%s, %s" % (psm,ds), |
---|
| 93 | students = items, |
---|
[885] | 94 | allowed = True, |
---|
[587] | 95 | ) |
---|
[572] | 96 | items = [] |
---|
| 97 | res = [] |
---|
| 98 | portal_type_query = {'query':['Student','StudentApplication','StudentPersonal']} |
---|
[603] | 99 | st_queries = ('jamb_reg_no','matric_no','name') |
---|
[727] | 100 | query_step = 0 |
---|
[751] | 101 | review_res = None |
---|
| 102 | query = None |
---|
| 103 | if len(term) > 0: |
---|
| 104 | if what == "student_id": |
---|
| 105 | query_step = 1 |
---|
| 106 | query = Eq('portal_type','Student') & Eq('id', term.strip()) |
---|
| 107 | elif what in st_queries: |
---|
| 108 | if what == "jamb_reg_no": |
---|
| 109 | query_step = 2 |
---|
| 110 | pt = ('StudentApplication',) |
---|
| 111 | st = "%s" % term.strip().lower() |
---|
| 112 | elif what == "matric_no": |
---|
| 113 | query_step = 3 |
---|
| 114 | pt = ('StudentClearance',) |
---|
| 115 | st = "%s" % term.strip().lower() |
---|
| 116 | elif what == "name": |
---|
| 117 | query_step = 4 |
---|
| 118 | pt = ('StudentPersonal') |
---|
| 119 | st = "%s" % term.strip() |
---|
| 120 | query = In('portal_type',pt) & Eq('SearchableText',"%s*" % term.strip()) |
---|
[750] | 121 | res = evalAdvancedQuery(query) |
---|
[751] | 122 | if with_review: |
---|
| 123 | query_step += 10 |
---|
[755] | 124 | review_res = evalAdvancedQuery(In('portal_type',student_objects) & Eq('review_state',state)) |
---|
[751] | 125 | search_set = [] |
---|
[572] | 126 | if res: |
---|
| 127 | for r in res: |
---|
[750] | 128 | if r.portal_type in ("StudentStudyLevel",): |
---|
| 129 | student = r.getObject().aq_parent.aq_parent |
---|
| 130 | elif r.portal_type in student_subobjects: |
---|
[589] | 131 | student = r.getObject().aq_parent |
---|
[572] | 132 | else: |
---|
[589] | 133 | student = r.getObject() |
---|
[751] | 134 | search_set.append(student) |
---|
| 135 | review_set = [] |
---|
| 136 | if review_res: |
---|
| 137 | for r in review_res: |
---|
| 138 | if r.portal_type in ("StudentStudyLevel",): |
---|
| 139 | student = r.getObject().aq_parent.aq_parent |
---|
| 140 | elif r.portal_type in student_subobjects: |
---|
| 141 | student = r.getObject().aq_parent |
---|
| 142 | else: |
---|
| 143 | student = r.getObject() |
---|
| 144 | review_set.append(student) |
---|
| 145 | all = [] |
---|
| 146 | if only_review: |
---|
| 147 | all = review_set |
---|
| 148 | elif with_review: |
---|
| 149 | for i in search_set: |
---|
| 150 | if i in review_set: |
---|
| 151 | all.append(i) |
---|
| 152 | else: |
---|
| 153 | all = search_set |
---|
| 154 | for a in all: |
---|
| 155 | if a in items: |
---|
| 156 | continue |
---|
| 157 | items.append(a) |
---|
| 158 | students = [] |
---|
[765] | 159 | items.sort(cmp_id) |
---|
[887] | 160 | co_view = False |
---|
[584] | 161 | if items: |
---|
| 162 | for item in items: |
---|
[886] | 163 | #if context.isClearanceOfficer(info): |
---|
| 164 | if "ClearanceOfficers" in member.getGroups(): |
---|
[887] | 165 | co_view = True |
---|
[886] | 166 | droles = member.getRolesInContext(item) |
---|
| 167 | if "ClearanceOfficer" in droles: |
---|
| 168 | info = context.getStudentInfo(item) |
---|
| 169 | students.append(info) |
---|
| 170 | else: |
---|
| 171 | info = context.getStudentInfo(item) |
---|
| 172 | students.append(info) |
---|
[891] | 173 | |
---|
[896] | 174 | return context.students_view(rendered = rend, |
---|
[886] | 175 | psm = "", |
---|
| 176 | #psm = "%d,%d matching Students found QS = %s" %\ |
---|
| 177 | # (len(review_set),len(search_set),query_step), |
---|
[750] | 178 | #psm = "%d found QS = %s items: %s" % (len(items),query_step,items), |
---|
[584] | 179 | students = students, |
---|
[885] | 180 | allowed = True, |
---|
[887] | 181 | co_view = co_view, |
---|
[584] | 182 | ) |
---|
[896] | 183 | return context.students_view(rendered = rend, |
---|
[891] | 184 | psm = "No student found!", |
---|
| 185 | #psm = """Step: %s found: %s Your search for "%s" in %s with state %s failed.<br\>%s""" % (query_step,len(items),st,what,state,bools), |
---|
[663] | 186 | students = students, |
---|
[885] | 187 | allowed = True, |
---|
[663] | 188 | ) |
---|
[886] | 189 | |
---|
| 190 | |
---|