## Script (Python) "search_pins" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=REQUEST ##title= ## # $Id: search_students.py 911 2006-11-20 15:11:29Z henrik $ """ list Students for ClearanceOfficers """ request = REQUEST wftool = context.portal_workflow mtool = context.portal_membership member = mtool.getAuthenticatedMember() roles = member.getRolesInContext(context) #from Products.zdb import set_trace #set_trace() lt = context.portal_layouts validate = request.has_key("cpsdocument_edit_button") default = {'search_mode': 'student',} rend,psm,ds = lt.renderLayout(layout_id= 'scratch_card_search', schema_id= 'student_search', context=context, mapping=validate and request, ob=default, layout_mode='edit', formaction="search_pins", commit = False, ) info = {} info['batch_doc'] = context.getContent() info['unused'] = info['batch_doc'].getUnusedPins() info['used'] = [] info['nr_used'] = info['batch_doc'].getNumberOfUsedPins() if psm == '': return context.batch_view(rendered = rend, psm = psm, #psm = "%s, %s" % (psm,ds), info = info, allowed = True, ) #set_trace() what = ds.get('search_mode') term = ds.get('search_string') if term != "": if what == 'student' : items_1 = context.portal_pins(student = term.upper()) items_2 = context.portal_pins(student = term.lower()) items = items_1 + items_2 elif what == 'pin': items = context.portal_pins(pin = term.upper()) else: items = [] l = [] students_url = "%s/%s" % (context.portal_url(),'students') pins = [] for i in items: item = {} sno = i['student'] item['student'] = sno item['serial'] = i.serial item['pin'] = i.pin if i.pin in pins: continue pins.append(i.pins) if len(sno)==10: #res = context.portal_catalog(SearchableText=sno,portal_type='StudentApplication') res = context.students_catalog(jamb_reg_no=sno.upper()) if len(res) > 0: item['student_url'] = "%s/campus/students/%s" % (context.portal_url(),res[0].id) item['student_id'] = res[0].id else: item['student_url'] = None item['student_id'] = '' elif sno: item['student_url'] = '%s/campus/students/%s' % (students_url,item['student']) item['student_id'] = student else: item['student_url'] = '' item['student_id'] = "not used" l.append(item) info['used'] = l return context.batch_view(rendered = rend, psm = psm, #psm = "%s, %s" % (psm,ds), info = info, allowed = True, )