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