source: WAeUP_SRP/trunk/skins/waeup_accommodation/getAccoHallInfo.py @ 1297

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

correct Hall Statistic

  • Property svn:keywords set to Id
File size: 1.9 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 1297 2007-01-15 09:57:20Z 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
22wf = context.portal_workflow
23path_info = request.get('PATH_INFO').split('/')
24mtool = context.portal_membership
25pa = context.portal_accommodation
26info = {}
27#dep_id = request.get('PATH_TRANSLATED').split('/')[-2]
28dep_id = context.aq_parent.getId()
29info['action'] = "%s" % context.absolute_url()
30info['choosen_ids'] = request.get('ids',[])
31info['doc'] = context.getContent()
32bed_types = pa.uniqueValuesFor('bed_type')
33bt_list = []
34bt_names =  context.getBedTypeNames()
35all_booked = pa.uniqueValuesFor('student')
36booked_list = []
37#from Products.zdb import set_trace;set_trace()
38for bt in bed_types:
39    total = len(pa(bed_type=bt,hall=context.getId()))
40    if total <= 1:
41        continue
42    booked = pa.searchResults({'bed_type': bt,
43                                 'student':all_booked,
44                                 'hall': context.getId()})
45    bt_list.append({'name': bt_names[bt],
46                    'total': total,
47                    'reserved': len(booked),
48                    })
49    booked_list.extend(booked)
50info['bed_types'] = bt_list
51res_list = []
52students_url = "%s/campus/students" % (context.portal_url())
53for sbrain in booked_list:
54    d = {}
55    st = sbrain.student
56    if not st:
57        continue
58    d['student'] = st
59    d['student_url'] ='%s/%s' % (students_url,st)
60    bed = context.formatBed(sbrain.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.