## Script (Python) "getBedStatistics"
##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 $

pa = context.portal_accommodation
bed_types = pa.uniqueValuesFor('bed_type')
bt_list = []
bt_names =  context.getBedTypeNames()
res = pa.uniqueValuesFor('student')
occupied_types = [st for st in res if st and st != 'not_occupied']
sum_total = 0
sum_occupied = 0
info = {}
#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':occupied_types}))
    sum_occupied += occupied
    bt_list.append({'name': bt_names[bt],
                    'total': total,
                    'occupied': occupied,
                    'full': occupied == total,
                    })
bt_list.append({'name': "All Categories",
                'total': sum_total,
                'occupied': 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