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

Last change on this file since 2059 was 1914, checked in by Henrik Bettermann, 17 years ago

ticket #277

  • Property svn:keywords set to Id
File size: 2.1 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 1914 2007-06-17 13:29:34Z henrik $
[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
21
22wf = context.portal_workflow
23path_info = request.get('PATH_INFO').split('/')
24mtool = context.portal_membership
[627]25pa = context.portal_accommodation
[622]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()
[627]32bed_types = pa.uniqueValuesFor('bed_type')
33bt_list = []
34bt_names =  context.getBedTypeNames()
[1301]35res = pa.uniqueValuesFor('student')
36all_booked = [st for st in res if st]
[1297]37booked_list = []
[1445]38#from Products.zdb import set_trace;set_trace()
[627]39for bt in bed_types:
[702]40    total = len(pa(bed_type=bt,hall=context.getId()))
[1269]41    if total <= 1:
42        continue
[1297]43    booked = pa.searchResults({'bed_type': bt,
44                                 'student':all_booked,
45                                 'hall': context.getId()})
[654]46    bt_list.append({'name': bt_names[bt],
47                    'total': total,
[1297]48                    'reserved': len(booked),
[654]49                    })
[1297]50    booked_list.extend(booked)
[627]51info['bed_types'] = bt_list
[654]52res_list = []
[1269]53students_url = "%s/campus/students" % (context.portal_url())
[1297]54for sbrain in booked_list:
55    d = {}
56    st = sbrain.student
57    if not st:
58        continue
59    d['student'] = st
60    d['student_url'] ='%s/%s' % (students_url,st)
[1566]61    bed = context.getFormattedBed(sbrain.bed).split('/')
[1297]62    d['bed'] = " / ".join(bed[1:])
63    erg = context.students_catalog(id = st)
64    if erg:
65        sd = context.getFormattedStudentEntry(erg[0])
66        d.update(sd)
[1914]67    else:
68        #d['student'] = None
69        d['student_url'] = None
70        #d['bed'] = None
71        d['name'] = 'Student record removed'
[1297]72    res_list.append(d)
[1269]73res_list.sort(cmp_bed)
[654]74info['reserved'] = res_list
[627]75
[622]76return info
Note: See TracBrowser for help on using the repository browser.