## 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['used'] = [] if context.portal_type == "ScratchCardBatch": info['batch_doc'] = context.getContent() info['unused'] = info['batch_doc'].getUnusedPins() info['nr_used'] = info['batch_doc'].getNumberOfUsedPins() view = context.batch_view elif context.portal_type == "ScratchCardBatchesFolder": view = context.pins_view if psm == '': return view(rendered = rend, psm = psm, #psm = "%s, %s" % (psm,ds), info = info, allowed = True, ) what = ds.get('search_mode') term = ds.get('search_string') pincat = context.portal_pins if term != "": if what == 'student' : items_1 = pincat(student = term.upper()) items_2 = pincat(student = term.lower()) items = items_1 + items_2 elif what == 'pin': items = pincat(pin = term.upper()) elif what == 'serial': try: snr = int(term.strip()) items = pincat(serial = snr) except ValueError: psm = "invalid number" items = [] pass else: items = [] l = [] ## students_url = "%s/%s" % (context.portal_url(),'students') pins = [] for i in items: item = {} sno = i['student'] item['student'] = sno item['prefix'] = i.prefix_batch item['serial'] = i.serial if len(sno) > 0: item['pin'] = i.pin else: if str(member) in ('henrik','joachim'): item['pin'] = "%s" % (i.pin,) else: item['pin'] = "%s%s****%s" % (i.prefix_batch,i.pin[-10:-7],i.pin[-3:]) 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: if sno.startswith('disabled'): item['student_url'] = None else: 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: if sno.startswith('disabled'): item['student_url'] = None else: item['student_url'] = '%s/campus/students/%s' % (context.portal_url(),item['student']) item['student_id'] = item['student'] else: item['student_url'] = '' item['student_id'] = "not used" l.append(item) info['used'] = l return view(rendered = rend, psm = psm, #psm = "%s, %s" % (psm,ds), info = info, allowed = True, )