## Script (Python) "getAccoHallInfo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=student=None ##title= ## # $Id: getAccoHallInfo.py 1301 2007-01-15 12:00:30Z joachim $ """ return Info about a Accommodation Hall """ def cmp_bed(a,b): if a['bed'] > b['bed']: return 1 return -1 request = context.REQUEST wf = context.portal_workflow path_info = request.get('PATH_INFO').split('/') mtool = context.portal_membership pa = context.portal_accommodation info = {} #dep_id = request.get('PATH_TRANSLATED').split('/')[-2] dep_id = context.aq_parent.getId() info['action'] = "%s" % context.absolute_url() info['choosen_ids'] = request.get('ids',[]) info['doc'] = context.getContent() bed_types = pa.uniqueValuesFor('bed_type') bt_list = [] bt_names = context.getBedTypeNames() res = pa.uniqueValuesFor('student') all_booked = [st for st in res if st] booked_list = [] #from Products.zdb import set_trace;set_trace() for bt in bed_types: total = len(pa(bed_type=bt,hall=context.getId())) if total <= 1: continue booked = pa.searchResults({'bed_type': bt, 'student':all_booked, 'hall': context.getId()}) bt_list.append({'name': bt_names[bt], 'total': total, 'reserved': len(booked), }) booked_list.extend(booked) info['bed_types'] = bt_list res_list = [] students_url = "%s/campus/students" % (context.portal_url()) for sbrain in booked_list: d = {} st = sbrain.student if not st: continue d['student'] = st d['student_url'] ='%s/%s' % (students_url,st) bed = context.formatBed(sbrain.bed).split('/') d['bed'] = " / ".join(bed[1:]) erg = context.students_catalog(id = st) if erg: sd = context.getFormattedStudentEntry(erg[0]) d.update(sd) res_list.append(d) res_list.sort(cmp_bed) info['reserved'] = res_list return info