[1002] | 1 | ## Script (Python) "search_pins" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=REQUEST |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: search_students.py 911 2006-11-20 15:11:29Z henrik $ |
---|
| 11 | """ |
---|
| 12 | list Students for ClearanceOfficers |
---|
| 13 | """ |
---|
[3076] | 14 | try: |
---|
| 15 | from Products.zdb import set_trace |
---|
| 16 | except: |
---|
| 17 | def set_trace(): |
---|
| 18 | pass |
---|
[1006] | 19 | |
---|
[1002] | 20 | request = REQUEST |
---|
| 21 | wftool = context.portal_workflow |
---|
| 22 | mtool = context.portal_membership |
---|
| 23 | member = mtool.getAuthenticatedMember() |
---|
| 24 | roles = member.getRolesInContext(context) |
---|
[1134] | 25 | pincat = context.portal_pins |
---|
| 26 | students = context.portal_url.getPortalObject().campus.students |
---|
| 27 | def check_hostel_pins(term): |
---|
| 28 | items = pincat(prefix_batch = term) |
---|
| 29 | not_found = [] |
---|
| 30 | #from Products.zdb import set_trace;set_trace() |
---|
| 31 | for item in items: |
---|
| 32 | if item.student == '': |
---|
| 33 | continue |
---|
| 34 | student = getattr(students,item.student,None) |
---|
| 35 | if student is None: |
---|
| 36 | not_found.append(item) |
---|
| 37 | elif not "accommodation_2006" in student.objectIds(): |
---|
| 38 | not_found.append(item) |
---|
| 39 | else: |
---|
| 40 | acco = student.accommodation_2006 |
---|
| 41 | acco_doc = acco.getContent() |
---|
| 42 | pin = "".join(str(acco_doc.acco_res_sc_pin).split('-')) |
---|
| 43 | if pin != item.pin: |
---|
| 44 | not_found.append(item) |
---|
| 45 | return not_found |
---|
[1540] | 46 | |
---|
[1120] | 47 | def set_used_pins(items, from_cat=False): |
---|
| 48 | l = [] |
---|
| 49 | for i in items: |
---|
| 50 | item = {} |
---|
| 51 | if from_cat: |
---|
| 52 | sno = i.student |
---|
| 53 | prefix = i.prefix_batch |
---|
| 54 | serial = i.serial |
---|
| 55 | pin = i.pin |
---|
| 56 | else: |
---|
| 57 | sno = i['student'] |
---|
| 58 | prefix = i.get('prefix_batch') |
---|
| 59 | serial = i.get('serial') |
---|
| 60 | pin = i.get('pin') |
---|
| 61 | item['student'] = sno |
---|
[1540] | 62 | item['prefix'] = prefix |
---|
[1120] | 63 | item['serial'] = serial |
---|
| 64 | if len(sno) > 0: |
---|
| 65 | item['pin'] = pin |
---|
| 66 | else: |
---|
[1853] | 67 | if str(member) in ('admin','joachim'): |
---|
[1120] | 68 | item['pin'] = "%s" % (pin,) |
---|
| 69 | else: |
---|
| 70 | item['pin'] = "%s%s****%s" % (i.prefix_batch,pin[-10:-7],pin[-3:]) |
---|
[2615] | 71 | |
---|
[2140] | 72 | if sno.startswith('disabled'): |
---|
| 73 | item['student_url'] = None |
---|
| 74 | item['student_id'] = sno |
---|
| 75 | elif len(sno)==10 or '/' in sno: |
---|
[1120] | 76 | #res = context.portal_catalog(SearchableText=sno,portal_type='StudentApplication') |
---|
| 77 | res = context.students_catalog(jamb_reg_no=sno.upper()) |
---|
| 78 | if len(res) > 0: |
---|
[2140] | 79 | item['student_url'] = "%s/campus/students/%s/application" % (context.portal_url(),res[0].id) |
---|
[1120] | 80 | item['student_id'] = res[0].id |
---|
| 81 | else: |
---|
| 82 | item['student_url'] = None |
---|
| 83 | item['student_id'] = '' |
---|
[2615] | 84 | elif len(sno) == 7: |
---|
[2140] | 85 | item['student_url'] = '%s/campus/students/%s' % (context.portal_url(),item['student']) |
---|
| 86 | item['student_id'] = item['student'] |
---|
[1120] | 87 | else: |
---|
| 88 | item['student_url'] = '' |
---|
| 89 | item['student_id'] = "not used" |
---|
| 90 | l.append(item) |
---|
| 91 | return l |
---|
| 92 | |
---|
[1002] | 93 | lt = context.portal_layouts |
---|
| 94 | validate = request.has_key("cpsdocument_edit_button") |
---|
[1012] | 95 | default = {'search_mode': 'student',} |
---|
[1002] | 96 | rend,psm,ds = lt.renderLayout(layout_id= 'scratch_card_search', |
---|
| 97 | schema_id= 'student_search', |
---|
| 98 | context=context, |
---|
| 99 | mapping=validate and request, |
---|
[1012] | 100 | ob=default, |
---|
[1002] | 101 | layout_mode='edit', |
---|
| 102 | formaction="search_pins", |
---|
| 103 | commit = False, |
---|
| 104 | ) |
---|
| 105 | info = {} |
---|
| 106 | info['used'] = [] |
---|
[1401] | 107 | #from Products.zdb import set_trace;set_trace() |
---|
[1062] | 108 | if context.portal_type == "ScratchCardBatch": |
---|
[1540] | 109 | info['batch_doc'] = context.getContent() |
---|
[2163] | 110 | #info['used'] = set_used_pins(info['batch_doc'].getUsedPins()) |
---|
| 111 | info['used'] = [] |
---|
[1062] | 112 | info['unused'] = info['batch_doc'].getUnusedPins() |
---|
| 113 | info['nr_used'] = info['batch_doc'].getNumberOfUsedPins() |
---|
| 114 | view = context.batch_view |
---|
| 115 | elif context.portal_type == "ScratchCardBatchesFolder": |
---|
[2766] | 116 | batches = context.objectIds() |
---|
| 117 | batches.sort() |
---|
[3076] | 118 | l = [] |
---|
| 119 | cols = 6 |
---|
| 120 | rows,rest = divmod(len(batches),cols) |
---|
[3081] | 121 | bis = 0 |
---|
[3076] | 122 | for r in range(rows): |
---|
| 123 | von = r*cols |
---|
[3081] | 124 | bis = von + cols |
---|
| 125 | l += batches[von:bis], |
---|
[3076] | 126 | if rest: |
---|
[3081] | 127 | von = bis |
---|
[3076] | 128 | l += batches[von:von+rest], |
---|
| 129 | info['batches'] = l |
---|
[1062] | 130 | view = context.pins_view |
---|
[1002] | 131 | if psm == '': |
---|
[1062] | 132 | return view(rendered = rend, |
---|
| 133 | psm = psm, |
---|
| 134 | #psm = "%s, %s" % (psm,ds), |
---|
| 135 | info = info, |
---|
| 136 | allowed = True, |
---|
| 137 | ) |
---|
[1002] | 138 | what = ds.get('search_mode') |
---|
| 139 | term = ds.get('search_string') |
---|
[1797] | 140 | |
---|
| 141 | items=[] |
---|
[1012] | 142 | if term != "": |
---|
| 143 | if what == 'student' : |
---|
[1062] | 144 | items_1 = pincat(student = term.upper()) |
---|
| 145 | items_2 = pincat(student = term.lower()) |
---|
[1012] | 146 | items = items_1 + items_2 |
---|
| 147 | elif what == 'pin': |
---|
[1134] | 148 | if context.portal_type == "ScratchCardBatch" and term == "HOS1": |
---|
| 149 | items = check_hostel_pins(term) |
---|
| 150 | else: |
---|
| 151 | items = pincat(pin = term.upper()) |
---|
[1062] | 152 | elif what == 'serial': |
---|
| 153 | try: |
---|
| 154 | snr = int(term.strip()) |
---|
| 155 | items = pincat(serial = snr) |
---|
| 156 | except ValueError: |
---|
| 157 | psm = "invalid number" |
---|
| 158 | items = [] |
---|
| 159 | pass |
---|
[1012] | 160 | else: |
---|
| 161 | items = [] |
---|
[1540] | 162 | |
---|
[1120] | 163 | info['used'] = set_used_pins(items,from_cat=True) |
---|
[1002] | 164 | |
---|
[1853] | 165 | |
---|
| 166 | |
---|
[1062] | 167 | return view(rendered = rend, |
---|
| 168 | psm = psm, |
---|
| 169 | #psm = "%s, %s" % (psm,ds), |
---|
| 170 | info = info, |
---|
| 171 | allowed = True, |
---|
| 172 | ) |
---|
[1070] | 173 | |
---|