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

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

PIN search results showed wrong link

File size: 5.0 KB
RevLine 
[1002]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"""
[1006]14
[1002]15request = REQUEST
16wftool = context.portal_workflow
17mtool = context.portal_membership
18member = mtool.getAuthenticatedMember()
19roles = member.getRolesInContext(context)
[1134]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
[1540]41
[1120]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
[1540]57        item['prefix'] = prefix
[1120]58        item['serial'] = serial
59        if len(sno) > 0:
60            item['pin'] = pin
61        else:
[1853]62            if str(member) in ('admin','joachim'):
[1120]63                item['pin'] = "%s" % (pin,)
64            else:
65                item['pin'] = "%s%s****%s" % (i.prefix_batch,pin[-10:-7],pin[-3:])
[1853]66        if len(sno)==10 or '/' in sno:
[1120]67            #res = context.portal_catalog(SearchableText=sno,portal_type='StudentApplication')
68            res = context.students_catalog(jamb_reg_no=sno.upper())
69            if len(res) > 0:
70                if sno.startswith('disabled'):
71                    item['student_url'] = None
72                else:
[1853]73                    item['student_url'] = "%s/campus/students/%s/application" % (context.portal_url(),res[0].id)
[1120]74                item['student_id'] = res[0].id
75            else:
76                item['student_url'] = None
77                item['student_id'] = ''
78        elif sno:
79            if sno.startswith('disabled'):
80                item['student_url'] = None
[1540]81                item['student_id'] = ''
[1120]82            else:
83                item['student_url'] = '%s/campus/students/%s' % (context.portal_url(),item['student'])
[1540]84                item['student_id'] = item['student']
[1120]85        else:
86            item['student_url'] = ''
87            item['student_id'] = "not used"
88        l.append(item)
89    return l
90
[1002]91lt = context.portal_layouts
92validate = request.has_key("cpsdocument_edit_button")
[1012]93default = {'search_mode': 'student',}
[1002]94rend,psm,ds = lt.renderLayout(layout_id= 'scratch_card_search',
95                      schema_id= 'student_search',
96                      context=context,
97                      mapping=validate and request,
[1012]98                      ob=default,
[1002]99                      layout_mode='edit',
100                      formaction="search_pins",
101                      commit = False,
102                      )
103info = {}
104info['used'] = []
[1401]105#from Products.zdb import set_trace;set_trace()
[1062]106if context.portal_type == "ScratchCardBatch":
[1540]107    info['batch_doc'] = context.getContent()
[1120]108    info['used'] = set_used_pins(info['batch_doc'].getUsedPins())
[1062]109    info['unused'] = info['batch_doc'].getUnusedPins()
110    info['nr_used'] = info['batch_doc'].getNumberOfUsedPins()
111    view = context.batch_view
112elif context.portal_type == "ScratchCardBatchesFolder":
113    view = context.pins_view
[1002]114if psm == '':
[1062]115    return view(rendered = rend,
116                psm = psm,
117                #psm = "%s, %s" % (psm,ds),
118                info = info,
119                allowed = True,
120                )
[1002]121what = ds.get('search_mode')
122term = ds.get('search_string')
[1797]123
124items=[]
[1012]125if term != "":
126    if what == 'student' :
[1062]127        items_1 = pincat(student = term.upper())
128        items_2 = pincat(student = term.lower())
[1012]129        items = items_1 + items_2
130    elif what == 'pin':
[1134]131        if context.portal_type == "ScratchCardBatch" and term == "HOS1":
132            items = check_hostel_pins(term)
133        else:
134            items = pincat(pin = term.upper())
[1062]135    elif what == 'serial':
136        try:
137            snr = int(term.strip())
138            items = pincat(serial = snr)
139        except ValueError:
140            psm = "invalid number"
141            items = []
142            pass
[1012]143    else:
144        items = []
[1540]145
[1120]146info['used'] = set_used_pins(items,from_cat=True)
[1002]147
[1853]148
149
[1062]150return view(rendered = rend,
151            psm = psm,
152            #psm = "%s, %s" % (psm,ds),
153            info = info,
154            allowed = True,
155            )
[1070]156
Note: See TracBrowser for help on using the repository browser.