1 | ## Script (Python) "getAccoFolderInfo" |
---|
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 1138 2006-12-23 12:37:21Z joachim $ |
---|
11 | """ |
---|
12 | return Info about the Faculties |
---|
13 | """ |
---|
14 | request = context.REQUEST |
---|
15 | |
---|
16 | wf = context.portal_workflow |
---|
17 | mtool = context.portal_membership |
---|
18 | path_info = request.get('PATH_INFO').split('/') |
---|
19 | |
---|
20 | info = {} |
---|
21 | info['action'] = "%s" % context.absolute_url() |
---|
22 | info['choosen_ids'] = request.get('ids',[]) |
---|
23 | items = [] |
---|
24 | halls = context.portal_catalog(portal_type='AccoHall') |
---|
25 | for f in halls: |
---|
26 | row = {} |
---|
27 | fo = f.getObject() |
---|
28 | fd = fo.getContent() |
---|
29 | row['id'] = fo.getId() |
---|
30 | row['title'] = fd.Title() |
---|
31 | row['url'] = fo.absolute_url() |
---|
32 | row['is_editable'] = mtool.checkPermission('Modify portal content', fo) |
---|
33 | items.append(row) |
---|
34 | info['items'] = items |
---|
35 | pa = context.portal_accommodation |
---|
36 | bed_types = pa.uniqueValuesFor('bed_type') |
---|
37 | bt_list = [] |
---|
38 | bt_names = context.getBedTypeNames() |
---|
39 | reserved = pa.uniqueValuesFor('student') |
---|
40 | sum_total = 0 |
---|
41 | sum_free = 0 |
---|
42 | for bt in bed_types: |
---|
43 | total = len(pa(bed_type=bt)) |
---|
44 | sum_total += total |
---|
45 | free = len(pa.searchResults({'bed_type': bt,'student':reserved})) |
---|
46 | sum_free += free |
---|
47 | bt_list.append({'name': bt_names[bt], |
---|
48 | 'total': total, |
---|
49 | 'reserved': free, |
---|
50 | }) |
---|
51 | bt_list.append({'name': "Total", |
---|
52 | 'total': sum_total, |
---|
53 | 'reserved': sum_free, |
---|
54 | }) |
---|
55 | info['bed_types'] = bt_list |
---|
56 | reserved = pa.uniqueValuesFor('student') |
---|
57 | res_list = [] |
---|
58 | if reserved > 1: |
---|
59 | for st in reserved: |
---|
60 | if st: |
---|
61 | res = pa(student=st) |
---|
62 | res_list.append({'student': st, 'bed': res[0].bed }) |
---|
63 | info['reserved'] = res_list |
---|
64 | |
---|
65 | return info |
---|