source: WAeUP_SRP/branches/joachim-event-branch/skins/waeup_accommodation/getBedStatistics.py @ 12251

Last change on this file since 12251 was 1438, checked in by Henrik Bettermann, 18 years ago

bed statistics and folder view separated

File size: 1.3 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')
17reserved = [st for st in res if st]
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':reserved}))
26    sum_occupied += occupied
27    bt_list.append({'name': bt_names[bt],
28                    'total': total,
29                    'reserved': occupied,
30                    'full': occupied == total,
31                    })
32bt_list.append({'name': "All Categories",
33                'total': sum_total,
34                'reserved': sum_occupied,
35                })
36info['bed_types'] = bt_list
37reserved = pa.uniqueValuesFor('student')
38res_list = []
39if reserved > 1:
40    for st in reserved:
41        if st:
42            res = pa(student=st)
43            res_list.append({'student': st, 'bed': res[0].bed })
44info['reserved'] = res_list
45return info
Note: See TracBrowser for help on using the repository browser.