source: WAeUP_SRP/base/skins/waeup_accommodation/getBedStatistics.py @ 3687

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

fix bed statistics

File size: 1.4 KB
RevLine 
[1438]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')
[3007]17occupied_types = [st for st in res if st and st != 'not_occupied']
[1438]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
[3007]25    occupied = len(pa.searchResults({'bed_type': bt,'student':occupied_types}))
[1438]26    sum_occupied += occupied
27    bt_list.append({'name': bt_names[bt],
28                    'total': total,
[3007]29                    'occupied': occupied,
[1438]30                    'full': occupied == total,
31                    })
32bt_list.append({'name': "All Categories",
33                'total': sum_total,
[3007]34                'occupied': sum_occupied,
[1438]35                })
36info['bed_types'] = bt_list
[3007]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                 
[1438]47return info
Note: See TracBrowser for help on using the repository browser.