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

Last change on this file since 1286 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
RevLine 
[845]1## Script (Python) "getAccoHallInfo"
[622]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##
[805]10# $Id: getAccoHallInfo.py 1269 2007-01-11 17:06:34Z joachim $
[622]11"""
[1269]12return Info about a Accommodation Hall
[622]13"""
[1269]14
15def cmp_bed(a,b):
16    if a['bed'] > b['bed']:
17        return 1
18    return -1
19
[622]20request = context.REQUEST
[1269]21#from Products.zdb import set_trace;set_trace()
[622]22
23wf = context.portal_workflow
24path_info = request.get('PATH_INFO').split('/')
25mtool = context.portal_membership
[627]26pa = context.portal_accommodation
[622]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()
[627]33bed_types = pa.uniqueValuesFor('bed_type')
34bt_list = []
35bt_names =  context.getBedTypeNames()
[654]36reserved = pa.uniqueValuesFor('student')
[627]37for bt in bed_types:
[702]38    total = len(pa(bed_type=bt,hall=context.getId()))
[1269]39    if total <= 1:
40        continue
[702]41    free = len(pa.searchResults({'bed_type': bt,
42                                 'student':reserved,
43                                 'hall': context.getId()}))
[654]44    bt_list.append({'name': bt_names[bt],
45                    'total': total,
46                    'reserved': free,
47                    })
[627]48info['bed_types'] = bt_list
[654]49res_list = []
[1269]50students_url = "%s/campus/students" % (context.portal_url())
51if reserved:
[654]52    for st in reserved:
53        if st:
54            res = pa(hall=context.getId(),student=st)
[1269]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)
[654]68info['reserved'] = res_list
[627]69
[622]70return info
Note: See TracBrowser for help on using the repository browser.