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 | """ |
---|
14 | |
---|
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") |
---|
24 | default = {'search_mode': 'student',} |
---|
25 | rend,psm,ds = lt.renderLayout(layout_id= 'scratch_card_search', |
---|
26 | schema_id= 'student_search', |
---|
27 | context=context, |
---|
28 | mapping=validate and request, |
---|
29 | ob=default, |
---|
30 | layout_mode='edit', |
---|
31 | formaction="search_pins", |
---|
32 | commit = False, |
---|
33 | ) |
---|
34 | info = {} |
---|
35 | info['batch_doc'] = context.getContent() |
---|
36 | info['unused'] = info['batch_doc'].getUnusedPins() |
---|
37 | info['used'] = [] |
---|
38 | info['nr_used'] = info['batch_doc'].getNumberOfUsedPins() |
---|
39 | |
---|
40 | if psm == '': |
---|
41 | return context.batch_view(rendered = rend, |
---|
42 | psm = psm, |
---|
43 | #psm = "%s, %s" % (psm,ds), |
---|
44 | info = info, |
---|
45 | allowed = True, |
---|
46 | ) |
---|
47 | #set_trace() |
---|
48 | what = ds.get('search_mode') |
---|
49 | term = ds.get('search_string') |
---|
50 | if term != "": |
---|
51 | if what == 'student' : |
---|
52 | items_1 = context.portal_pins(student = term.upper()) |
---|
53 | items_2 = context.portal_pins(student = term.lower()) |
---|
54 | items = items_1 + items_2 |
---|
55 | elif what == 'pin': |
---|
56 | items = context.portal_pins(pin = term.upper()) |
---|
57 | else: |
---|
58 | items = [] |
---|
59 | l = [] |
---|
60 | students_url = "%s/%s" % (context.portal_url(),'students') |
---|
61 | pins = [] |
---|
62 | for i in items: |
---|
63 | item = {} |
---|
64 | sno = i['student'] |
---|
65 | item['student'] = sno |
---|
66 | item['serial'] = i.serial |
---|
67 | item['pin'] = i.pin |
---|
68 | if i.pin in pins: |
---|
69 | continue |
---|
70 | pins.append(i.pins) |
---|
71 | if len(sno)==10: |
---|
72 | #res = context.portal_catalog(SearchableText=sno,portal_type='StudentApplication') |
---|
73 | res = context.students_catalog(jamb_reg_no=sno.upper()) |
---|
74 | if len(res) > 0: |
---|
75 | item['student_url'] = "%s/campus/students/%s" % (context.portal_url(),res[0].id) |
---|
76 | item['student_id'] = res[0].id |
---|
77 | else: |
---|
78 | item['student_url'] = None |
---|
79 | item['student_id'] = '' |
---|
80 | elif sno: |
---|
81 | item['student_url'] = '%s/campus/students/%s' % (students_url,item['student']) |
---|
82 | item['student_id'] = student |
---|
83 | else: |
---|
84 | item['student_url'] = '' |
---|
85 | item['student_id'] = "not used" |
---|
86 | l.append(item) |
---|
87 | |
---|
88 | info['used'] = l |
---|
89 | |
---|
90 | return context.batch_view(rendered = rend, |
---|
91 | psm = psm, |
---|
92 | #psm = "%s, %s" % (psm,ds), |
---|
93 | info = info, |
---|
94 | allowed = True, |
---|
95 | ) |
---|