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