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