[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 | """ |
---|
[1006] | 14 | |
---|
[1002] | 15 | request = REQUEST |
---|
| 16 | wftool = context.portal_workflow |
---|
| 17 | mtool = context.portal_membership |
---|
| 18 | member = mtool.getAuthenticatedMember() |
---|
| 19 | roles = member.getRolesInContext(context) |
---|
[1134] | 20 | pincat = context.portal_pins |
---|
| 21 | students = context.portal_url.getPortalObject().campus.students |
---|
| 22 | def check_hostel_pins(term): |
---|
| 23 | items = pincat(prefix_batch = term) |
---|
| 24 | not_found = [] |
---|
| 25 | #from Products.zdb import set_trace;set_trace() |
---|
| 26 | for item in items: |
---|
| 27 | if item.student == '': |
---|
| 28 | continue |
---|
| 29 | student = getattr(students,item.student,None) |
---|
| 30 | if student is None: |
---|
| 31 | not_found.append(item) |
---|
| 32 | elif not "accommodation_2006" in student.objectIds(): |
---|
| 33 | not_found.append(item) |
---|
| 34 | else: |
---|
| 35 | acco = student.accommodation_2006 |
---|
| 36 | acco_doc = acco.getContent() |
---|
| 37 | pin = "".join(str(acco_doc.acco_res_sc_pin).split('-')) |
---|
| 38 | if pin != item.pin: |
---|
| 39 | not_found.append(item) |
---|
| 40 | return not_found |
---|
| 41 | |
---|
[1120] | 42 | def set_used_pins(items, from_cat=False): |
---|
| 43 | l = [] |
---|
| 44 | for i in items: |
---|
| 45 | item = {} |
---|
| 46 | if from_cat: |
---|
| 47 | sno = i.student |
---|
| 48 | prefix = i.prefix_batch |
---|
| 49 | serial = i.serial |
---|
| 50 | pin = i.pin |
---|
| 51 | else: |
---|
| 52 | sno = i['student'] |
---|
| 53 | prefix = i.get('prefix_batch') |
---|
| 54 | serial = i.get('serial') |
---|
| 55 | pin = i.get('pin') |
---|
| 56 | item['student'] = sno |
---|
| 57 | item['prefix'] = prefix |
---|
| 58 | item['serial'] = serial |
---|
| 59 | if len(sno) > 0: |
---|
| 60 | item['pin'] = pin |
---|
| 61 | else: |
---|
| 62 | if str(member) in ('henrik','joachim'): |
---|
| 63 | item['pin'] = "%s" % (pin,) |
---|
| 64 | else: |
---|
| 65 | item['pin'] = "%s%s****%s" % (i.prefix_batch,pin[-10:-7],pin[-3:]) |
---|
| 66 | if len(sno)==10: |
---|
| 67 | #res = context.portal_catalog(SearchableText=sno,portal_type='StudentApplication') |
---|
| 68 | res = context.students_catalog(jamb_reg_no=sno.upper()) |
---|
| 69 | if len(res) > 0: |
---|
| 70 | if sno.startswith('disabled'): |
---|
| 71 | item['student_url'] = None |
---|
| 72 | else: |
---|
| 73 | item['student_url'] = "%s/campus/students/%s" % (context.portal_url(),res[0].id) |
---|
| 74 | item['student_id'] = res[0].id |
---|
| 75 | else: |
---|
| 76 | item['student_url'] = None |
---|
| 77 | item['student_id'] = '' |
---|
| 78 | elif sno: |
---|
| 79 | if sno.startswith('disabled'): |
---|
| 80 | item['student_url'] = None |
---|
| 81 | else: |
---|
| 82 | item['student_url'] = '%s/campus/students/%s' % (context.portal_url(),item['student']) |
---|
| 83 | item['student_id'] = item['student'] |
---|
| 84 | else: |
---|
| 85 | item['student_url'] = '' |
---|
| 86 | item['student_id'] = "not used" |
---|
| 87 | l.append(item) |
---|
| 88 | return l |
---|
| 89 | |
---|
[1002] | 90 | lt = context.portal_layouts |
---|
| 91 | validate = request.has_key("cpsdocument_edit_button") |
---|
[1012] | 92 | default = {'search_mode': 'student',} |
---|
[1002] | 93 | rend,psm,ds = lt.renderLayout(layout_id= 'scratch_card_search', |
---|
| 94 | schema_id= 'student_search', |
---|
| 95 | context=context, |
---|
| 96 | mapping=validate and request, |
---|
[1012] | 97 | ob=default, |
---|
[1002] | 98 | layout_mode='edit', |
---|
| 99 | formaction="search_pins", |
---|
| 100 | commit = False, |
---|
| 101 | ) |
---|
| 102 | info = {} |
---|
| 103 | info['used'] = [] |
---|
[1062] | 104 | if context.portal_type == "ScratchCardBatch": |
---|
| 105 | info['batch_doc'] = context.getContent() |
---|
[1120] | 106 | info['used'] = set_used_pins(info['batch_doc'].getUsedPins()) |
---|
[1062] | 107 | info['unused'] = info['batch_doc'].getUnusedPins() |
---|
| 108 | info['nr_used'] = info['batch_doc'].getNumberOfUsedPins() |
---|
| 109 | view = context.batch_view |
---|
| 110 | elif context.portal_type == "ScratchCardBatchesFolder": |
---|
| 111 | view = context.pins_view |
---|
[1002] | 112 | if psm == '': |
---|
[1062] | 113 | return view(rendered = rend, |
---|
| 114 | psm = psm, |
---|
| 115 | #psm = "%s, %s" % (psm,ds), |
---|
| 116 | info = info, |
---|
| 117 | allowed = True, |
---|
| 118 | ) |
---|
[1002] | 119 | what = ds.get('search_mode') |
---|
| 120 | term = ds.get('search_string') |
---|
[1012] | 121 | if term != "": |
---|
| 122 | if what == 'student' : |
---|
[1062] | 123 | items_1 = pincat(student = term.upper()) |
---|
| 124 | items_2 = pincat(student = term.lower()) |
---|
[1012] | 125 | items = items_1 + items_2 |
---|
| 126 | elif what == 'pin': |
---|
[1134] | 127 | if context.portal_type == "ScratchCardBatch" and term == "HOS1": |
---|
| 128 | items = check_hostel_pins(term) |
---|
| 129 | else: |
---|
| 130 | items = pincat(pin = term.upper()) |
---|
[1062] | 131 | elif what == 'serial': |
---|
| 132 | try: |
---|
| 133 | snr = int(term.strip()) |
---|
| 134 | items = pincat(serial = snr) |
---|
| 135 | except ValueError: |
---|
| 136 | psm = "invalid number" |
---|
| 137 | items = [] |
---|
| 138 | pass |
---|
[1012] | 139 | else: |
---|
| 140 | items = [] |
---|
| 141 | |
---|
[1120] | 142 | info['used'] = set_used_pins(items,from_cat=True) |
---|
[1002] | 143 | |
---|
[1062] | 144 | return view(rendered = rend, |
---|
| 145 | psm = psm, |
---|
| 146 | #psm = "%s, %s" % (psm,ds), |
---|
| 147 | info = info, |
---|
| 148 | allowed = True, |
---|
| 149 | ) |
---|
[1070] | 150 | |
---|