source: WAeUP_SRP/trunk/skins/waeup_accommodation/getBedStatistics.py @ 8679

Last change on this file since 8679 was 3007, checked in by Henrik Bettermann, 17 years ago

fix bed statistics

File size: 1.4 KB
Line 
1## Script (Python) "getBedStatistics"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=student=None
8##title=
9##
10# $Id: getAccoFolderInfo.py 1301 2007-01-15 12:00:30Z joachim $
11
12pa = context.portal_accommodation
13bed_types = pa.uniqueValuesFor('bed_type')
14bt_list = []
15bt_names =  context.getBedTypeNames()
16res = pa.uniqueValuesFor('student')
17occupied_types = [st for st in res if st and st != 'not_occupied']
18sum_total = 0
19sum_occupied = 0
20info = {}
21#from Products.zdb import set_trace;set_trace()
22for bt in bed_types:
23    total = len(pa(bed_type=bt))
24    sum_total += total
25    occupied = len(pa.searchResults({'bed_type': bt,'student':occupied_types}))
26    sum_occupied += occupied
27    bt_list.append({'name': bt_names[bt],
28                    'total': total,
29                    'occupied': occupied,
30                    'full': occupied == total,
31                    })
32bt_list.append({'name': "All Categories",
33                'total': sum_total,
34                'occupied': sum_occupied,
35                })
36info['bed_types'] = bt_list
37
38#reserved = pa.uniqueValuesFor('student')
39#res_list = []
40#if reserved > 1:
41#    for st in reserved:
42#        if st:
43#            res = pa(student=st)
44#            res_list.append({'student': st, 'bed': res[0].bed })
45#info['reserved'] = res_list
46                 
47return info
Note: See TracBrowser for help on using the repository browser.