source: WAeUP_SRP/base/skins/waeup_pins/search_pins.py @ 2605

Last change on this file since 2605 was 2163, checked in by joachim, 17 years ago

do not show used pins

File size: 4.9 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)
20pincat = context.portal_pins
21students = context.portal_url.getPortalObject().campus.students
22def check_hostel_pins(term):
23    items = pincat(prefix_batch = term)
24    not_found = []
25    #from Products.zdb import set_trace;set_trace()
26    for item in items:
27        if item.student == '':
28            continue
29        student = getattr(students,item.student,None)
30        if student is None:
31            not_found.append(item)
32        elif not "accommodation_2006" in student.objectIds():
33            not_found.append(item)
34        else:
35            acco = student.accommodation_2006
36            acco_doc = acco.getContent()
37            pin = "".join(str(acco_doc.acco_res_sc_pin).split('-'))
38            if pin != item.pin:
39                not_found.append(item)
40    return not_found
41
42def set_used_pins(items, from_cat=False):
43    l = []
44    for i in items:
45        item = {}
46        if from_cat:
47            sno = i.student
48            prefix = i.prefix_batch
49            serial = i.serial
50            pin = i.pin
51        else:
52            sno = i['student']
53            prefix = i.get('prefix_batch')
54            serial = i.get('serial')
55            pin = i.get('pin')
56        item['student'] = sno
57        item['prefix'] = prefix
58        item['serial'] = serial
59        if len(sno) > 0:
60            item['pin'] = pin
61        else:
62            if str(member) in ('admin','joachim'):
63                item['pin'] = "%s" % (pin,)
64            else:
65                item['pin'] = "%s%s****%s" % (i.prefix_batch,pin[-10:-7],pin[-3:])
66       
67        if sno.startswith('disabled'):
68            item['student_url'] = None
69            item['student_id'] = sno
70        elif len(sno)==10 or '/' in sno:
71            #res = context.portal_catalog(SearchableText=sno,portal_type='StudentApplication')
72            res = context.students_catalog(jamb_reg_no=sno.upper())
73            if len(res) > 0:
74                item['student_url'] = "%s/campus/students/%s/application" % (context.portal_url(),res[0].id)
75                item['student_id'] = res[0].id
76            else:
77                item['student_url'] = None
78                item['student_id'] = ''
79        elif sno:
80            item['student_url'] = '%s/campus/students/%s' % (context.portal_url(),item['student'])
81            item['student_id'] = item['student']
82        else:
83            item['student_url'] = ''
84            item['student_id'] = "not used"
85        l.append(item)
86    return l
87
88lt = context.portal_layouts
89validate = request.has_key("cpsdocument_edit_button")
90default = {'search_mode': 'student',}
91rend,psm,ds = lt.renderLayout(layout_id= 'scratch_card_search',
92                      schema_id= 'student_search',
93                      context=context,
94                      mapping=validate and request,
95                      ob=default,
96                      layout_mode='edit',
97                      formaction="search_pins",
98                      commit = False,
99                      )
100info = {}
101info['used'] = []
102#from Products.zdb import set_trace;set_trace()
103if context.portal_type == "ScratchCardBatch":
104    info['batch_doc'] = context.getContent()
105    #info['used'] = set_used_pins(info['batch_doc'].getUsedPins())
106    info['used'] = []
107    info['unused'] = info['batch_doc'].getUnusedPins()
108    info['nr_used'] = info['batch_doc'].getNumberOfUsedPins()
109    view = context.batch_view
110elif context.portal_type == "ScratchCardBatchesFolder":
111    view = context.pins_view
112if psm == '':
113    return view(rendered = rend,
114                psm = psm,
115                #psm = "%s, %s" % (psm,ds),
116                info = info,
117                allowed = True,
118                )
119what = ds.get('search_mode')
120term = ds.get('search_string')
121
122items=[]
123if term != "":
124    if what == 'student' :
125        items_1 = pincat(student = term.upper())
126        items_2 = pincat(student = term.lower())
127        items = items_1 + items_2
128    elif what == 'pin':
129        if context.portal_type == "ScratchCardBatch" and term == "HOS1":
130            items = check_hostel_pins(term)
131        else:
132            items = pincat(pin = term.upper())
133    elif what == 'serial':
134        try:
135            snr = int(term.strip())
136            items = pincat(serial = snr)
137        except ValueError:
138            psm = "invalid number"
139            items = []
140            pass
141    else:
142        items = []
143
144info['used'] = set_used_pins(items,from_cat=True)
145
146
147
148return view(rendered = rend,
149            psm = psm,
150            #psm = "%s, %s" % (psm,ds),
151            info = info,
152            allowed = True,
153            )
154
Note: See TracBrowser for help on using the repository browser.