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