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 |
|
---|
12 | pa = context.portal_accommodation
|
---|
13 | bed_types = pa.uniqueValuesFor('bed_type')
|
---|
14 | bt_list = []
|
---|
15 | bt_names = context.getBedTypeNames()
|
---|
16 | res = pa.uniqueValuesFor('student')
|
---|
17 | occupied_types = [st for st in res if st and st != 'not_occupied']
|
---|
18 | sum_total = 0
|
---|
19 | sum_occupied = 0
|
---|
20 | info = {}
|
---|
21 | #from Products.zdb import set_trace;set_trace()
|
---|
22 | for 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 | })
|
---|
32 | bt_list.append({'name': "All Categories",
|
---|
33 | 'total': sum_total,
|
---|
34 | 'occupied': sum_occupied,
|
---|
35 | })
|
---|
36 | info['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 |
|
---|
47 | return info |
---|
Note: See
TracBrowser for help on using the repository browser.