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