## Script (Python) "getAccoFolderInfo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=student=None ##title= ## # $Id: getAccoFolderInfo.py 1301 2007-01-15 12:00:30Z joachim $ """ return Info about the Faculties """ request = context.REQUEST wf = context.portal_workflow mtool = context.portal_membership path_info = request.get('PATH_INFO').split('/') info = {} info['action'] = "%s" % context.absolute_url() info['choosen_ids'] = request.get('ids',[]) items = [] halls = context.portal_catalog(portal_type='AccoHall') for f in halls: row = {} fo = f.getObject() fd = fo.getContent() row['id'] = fo.getId() row['title'] = fd.Title() row['url'] = fo.absolute_url() row['is_editable'] = mtool.checkPermission('Modify portal content', fo) items.append(row) info['items'] = items pa = context.portal_accommodation bed_types = pa.uniqueValuesFor('bed_type') bt_list = [] bt_names = context.getBedTypeNames() res = pa.uniqueValuesFor('student') reserved = [st for st in res if st] sum_total = 0 sum_occupied = 0 #from Products.zdb import set_trace;set_trace() for bt in bed_types: total = len(pa(bed_type=bt)) sum_total += total occupied = len(pa.searchResults({'bed_type': bt,'student':reserved})) sum_occupied += occupied bt_list.append({'name': bt_names[bt], 'total': total, 'reserved': occupied, 'full': occupied == total, }) bt_list.append({'name': "All Categories", 'total': sum_total, 'reserved': sum_occupied, }) info['bed_types'] = bt_list reserved = pa.uniqueValuesFor('student') res_list = [] if reserved > 1: for st in reserved: if st: res = pa(student=st) res_list.append({'student': st, 'bed': res[0].bed }) info['reserved'] = res_list return info