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