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

Last change on this file since 1070 was 1070, checked in by Henrik Bettermann, 18 years ago

fixed bug, link to student was wrong

File size: 3.8 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            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:])
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:
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)
97                item['student_id'] = res[0].id
98            else:
99                item['student_url'] = None
100                item['student_id'] = ''
101        elif sno:
102            if sno.startswith('disabled'):
103                item['student_url'] = None
104            else:
105                item['student_url'] = '%s/campus/students/%s' % (context.portal_url(),item['student'])
106            item['student_id'] = item['student']
107        else:
108            item['student_url'] = ''
109            item['student_id'] = "not used"
110        l.append(item)
111       
112    info['used'] = l
113
114return view(rendered = rend,
115            psm = psm,
116            #psm = "%s, %s" % (psm,ds),
117            info = info,
118            allowed = True,
119            )
120
Note: See TracBrowser for help on using the repository browser.