source: WAeUP_SRP/trunk/skins/waeup_pins/search_pins.py @ 1065

Last change on this file since 1065 was 1062, checked in by joachim, 18 years ago

add search for serial No

File size: 3.7 KB
Line 
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"""
12list Students for ClearanceOfficers
13"""
14
15request = REQUEST
16wftool = context.portal_workflow
17mtool = context.portal_membership
18member = mtool.getAuthenticatedMember()
19roles = member.getRolesInContext(context)
20#from Products.zdb import set_trace
21#set_trace()
22lt = context.portal_layouts
23validate = request.has_key("cpsdocument_edit_button")
24default = {'search_mode': 'student',}
25rend,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                      )
34info = {}
35info['used'] = []
36if 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
41elif context.portal_type == "ScratchCardBatchesFolder":
42    view = context.pins_view
43if psm == '':
44    return view(rendered = rend,
45                psm = psm,
46                #psm = "%s, %s" % (psm,ds),
47                info = info,
48                allowed = True,
49                )
50what = ds.get('search_mode')
51term = ds.get('search_string')
52pincat = context.portal_pins
53if term != "":
54    if what == 'student' :
55        items_1 = pincat(student = term.upper())
56        items_2 = pincat(student = term.lower())
57        items = items_1 + items_2
58    elif what == 'pin':
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
68    else:
69        items = []
70    l = []
71    students_url = "%s/%s" % (context.portal_url(),'students')
72    pins = []
73    for i in items:
74        item = {}
75        sno = i['student']
76        item['student'] = sno
77        item['prefix'] = i.prefix_batch
78        item['serial'] = i.serial
79        if len(sno) > 0:
80            item['pin'] = i.pin
81        else:
82            item['pin'] = "%s%s****%s" % (i.prefix_batch,i.pin[-10:-7],i.pin[-3:])
83        if i.pin in pins:
84            continue
85        pins.append(i.pins)
86        if len(sno)==10:
87            #res = context.portal_catalog(SearchableText=sno,portal_type='StudentApplication')
88            res = context.students_catalog(jamb_reg_no=sno.upper())
89            if len(res) > 0:
90                if sno.startswith('disabled'):
91                    item['student_url'] = None
92                else:
93                    item['student_url'] = "%s/campus/students/%s" % (context.portal_url(),res[0].id)
94                item['student_id'] = res[0].id
95            else:
96                item['student_url'] = None
97                item['student_id'] = ''
98        elif sno:
99            if sno.startswith('disabled'):
100                item['student_url'] = None
101            else:
102                item['student_url'] = '%s/campus/students/%s' % (students_url,item['student'])
103            item['student_id'] = item['student']
104        else:
105            item['student_url'] = ''
106            item['student_id'] = "not used"
107        l.append(item)
108       
109    info['used'] = l
110
111return view(rendered = rend,
112            psm = psm,
113            #psm = "%s, %s" % (psm,ds),
114            info = info,
115            allowed = True,
116            )
Note: See TracBrowser for help on using the repository browser.