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

Last change on this file since 1037 was 1012, checked in by joachim, 18 years ago

=clearance_edit_form fixed, nr_of used Pins is shown in batch_view

File size: 3.1 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['batch_doc'] = context.getContent()
36info['unused'] = info['batch_doc'].getUnusedPins()
37info['used'] = []
38info['nr_used'] = info['batch_doc'].getNumberOfUsedPins()
39
40if psm == '':
41    return context.batch_view(rendered = rend,
42                             psm = psm,
43                             #psm = "%s, %s" % (psm,ds),
44                             info = info,
45                             allowed = True,
46                             )
47#set_trace()
48what = ds.get('search_mode')
49term = ds.get('search_string')
50if term != "":
51    if what == 'student' :
52        items_1 = context.portal_pins(student = term.upper())
53        items_2 = context.portal_pins(student = term.lower())
54        items = items_1 + items_2
55    elif what == 'pin':
56        items = context.portal_pins(pin = term.upper())
57    else:
58        items = []
59    l = []
60    students_url = "%s/%s" % (context.portal_url(),'students')
61    pins = []
62    for i in items:
63        item = {}
64        sno = i['student']
65        item['student'] = sno
66        item['serial'] = i.serial
67        item['pin'] = i.pin
68        if i.pin in pins:
69            continue
70        pins.append(i.pins)
71        if len(sno)==10:
72            #res = context.portal_catalog(SearchableText=sno,portal_type='StudentApplication')
73            res = context.students_catalog(jamb_reg_no=sno.upper())
74            if len(res) > 0:
75                item['student_url'] = "%s/campus/students/%s" % (context.portal_url(),res[0].id)
76                item['student_id'] = res[0].id
77            else:
78                item['student_url'] = None
79                item['student_id'] = ''
80        elif sno:
81            item['student_url'] = '%s/campus/students/%s' % (students_url,item['student'])
82            item['student_id'] = student
83        else:
84            item['student_url'] = ''
85            item['student_id'] = "not used"
86        l.append(item)
87       
88    info['used'] = l
89
90return context.batch_view(rendered = rend,
91                             psm = psm,
92                             #psm = "%s, %s" % (psm,ds),
93                             info = info,
94                             allowed = True,
95                             )
Note: See TracBrowser for help on using the repository browser.