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 | request = REQUEST |
---|
15 | wftool = context.portal_workflow |
---|
16 | mtool = context.portal_membership |
---|
17 | member = mtool.getAuthenticatedMember() |
---|
18 | roles = member.getRolesInContext(context) |
---|
19 | #from Products.zdb import set_trace |
---|
20 | #set_trace() |
---|
21 | lt = context.portal_layouts |
---|
22 | validate = request.has_key("cpsdocument_edit_button") |
---|
23 | rend,psm,ds = lt.renderLayout(layout_id= 'scratch_card_search', |
---|
24 | schema_id= 'student_search', |
---|
25 | context=context, |
---|
26 | mapping=validate and request, |
---|
27 | ob={}, |
---|
28 | layout_mode='edit', |
---|
29 | formaction="search_pins", |
---|
30 | commit = False, |
---|
31 | ) |
---|
32 | info = {} |
---|
33 | info['batch_doc'] = context.getContent() |
---|
34 | info['unused'] = info['batch_doc'].getUnusedPins() |
---|
35 | info['used'] = [] |
---|
36 | |
---|
37 | if psm == '': |
---|
38 | return context.batch_view(rendered = rend, |
---|
39 | psm = psm, |
---|
40 | #psm = "%s, %s" % (psm,ds), |
---|
41 | info = info, |
---|
42 | allowed = True, |
---|
43 | ) |
---|
44 | #set_trace() |
---|
45 | what = ds.get('search_mode') |
---|
46 | term = ds.get('search_string') |
---|
47 | |
---|
48 | if what == 'student': |
---|
49 | items_2 = context.portal_pins(student = term) |
---|
50 | items_1 = context.portal_pins(student = term.upper()) |
---|
51 | items = items_1 + items_2 |
---|
52 | elif what == 'pin': |
---|
53 | items = context.portal_pins(pin = term.upper()) |
---|
54 | else: |
---|
55 | items = [] |
---|
56 | l = [] |
---|
57 | for i in items: |
---|
58 | item = {} |
---|
59 | sno = i['student'] |
---|
60 | item['student'] = sno |
---|
61 | item['serial'] = i.serial |
---|
62 | item['pin'] = i.pin |
---|
63 | if len(sno)==10: |
---|
64 | #if bd.prefix == "APP": |
---|
65 | #res = context.portal_catalog(SearchableText=sno,portal_type='StudentApplication') |
---|
66 | res = context.students_catalog(jamb_reg_no=sno.upper()) |
---|
67 | if len(res) > 0: |
---|
68 | item['student_url'] = "%s/%s" % (context.portal_url(),res[0].id) |
---|
69 | item['student_id'] = res[0].id |
---|
70 | else: |
---|
71 | item['student_url'] = None |
---|
72 | item['student_id'] = '' |
---|
73 | else: |
---|
74 | item['student_url'] = '%s/%s' % (students_url,item['student']) |
---|
75 | item['student_id'] = student |
---|
76 | l.append(item) |
---|
77 | |
---|
78 | info['used'] = l |
---|
79 | return context.batch_view(rendered = rend, |
---|
80 | psm = psm, |
---|
81 | #psm = "%s, %s" % (psm,ds), |
---|
82 | info = info, |
---|
83 | allowed = True, |
---|
84 | ) |
---|