source: WAeUP_SRP/branches/srpp_on_branch/skins/waeup_accommodation/getAccoHallInfo.py @ 14281

Last change on this file since 14281 was 1269, checked in by joachim, 18 years ago

new acco_hall_view with csv-download

  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1## Script (Python) "getAccoHallInfo"
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: getAccoHallInfo.py 1269 2007-01-11 17:06:34Z joachim $
11"""
12return Info about a Accommodation Hall
13"""
14
15def cmp_bed(a,b):
16    if a['bed'] > b['bed']:
17        return 1
18    return -1
19
20request = context.REQUEST
21#from Products.zdb import set_trace;set_trace()
22
23wf = context.portal_workflow
24path_info = request.get('PATH_INFO').split('/')
25mtool = context.portal_membership
26pa = context.portal_accommodation
27info = {}
28#dep_id = request.get('PATH_TRANSLATED').split('/')[-2]
29dep_id = context.aq_parent.getId()
30info['action'] = "%s" % context.absolute_url()
31info['choosen_ids'] = request.get('ids',[])
32info['doc'] = context.getContent()
33bed_types = pa.uniqueValuesFor('bed_type')
34bt_list = []
35bt_names =  context.getBedTypeNames()
36reserved = pa.uniqueValuesFor('student')
37for bt in bed_types:
38    total = len(pa(bed_type=bt,hall=context.getId()))
39    if total <= 1:
40        continue
41    free = len(pa.searchResults({'bed_type': bt,
42                                 'student':reserved,
43                                 'hall': context.getId()}))
44    bt_list.append({'name': bt_names[bt],
45                    'total': total,
46                    'reserved': free,
47                    })
48info['bed_types'] = bt_list
49res_list = []
50students_url = "%s/campus/students" % (context.portal_url())
51if reserved:
52    for st in reserved:
53        if st:
54            res = pa(hall=context.getId(),student=st)
55            if not res:
56                continue
57            d = {}
58            d['student'] = st
59            d['student_url'] ='%s/%s' % (students_url,st)
60            bed = context.formatBed(res[0].bed).split('/')
61            d['bed'] = " / ".join(bed[1:])
62            erg = context.students_catalog(id = st)
63            if erg:
64                sd = context.getFormattedStudentEntry(erg[0])
65                d.update(sd)
66            res_list.append(d)
67res_list.sort(cmp_bed)
68info['reserved'] = res_list
69
70return info
Note: See TracBrowser for help on using the repository browser.