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

Last change on this file since 6192 was 3054, checked in by joachim, 17 years ago

improve and sanitize code.

  • 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 3054 2008-01-28 13:13:11Z joachim $
[622]11"""
[1269]12return Info about a Accommodation Hall
[622]13"""
[2845]14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19   
20from Products.AdvancedQuery import Eq, Between, Le,In
[1269]21
22def cmp_bed(a,b):
23    if a['bed'] > b['bed']:
24        return 1
25    return -1
26
[622]27request = context.REQUEST
[2845]28portal_accommodation = context.portal_accommodation
29aq_accommodation = portal_accommodation.evalAdvancedQuery
[3054]30aq_students = context.students_catalog.evalAdvancedQuery
[622]31info = {}
32info['action'] = "%s" % context.absolute_url()
33info['choosen_ids'] = request.get('ids',[])
34info['doc'] = context.getContent()
[627]35bt_list = []
36bt_names =  context.getBedTypeNames()
[3054]37query = Eq('hall',context.getId())
38beds = aq_accommodation(query)
39bed_types = []
40for bed in beds:
41    if bed.bed_type not in bed_types:
42        bed_types += bed.bed_type,
43bed_type_info = []
[1297]44booked_list = []
[3054]45booked_mapping = {}
[627]46for bt in bed_types:
[3054]47    total_beds = [b for b in beds if b.bed_type == bt]
48    booked_beds = 0
49    for b in total_beds:
50        if b.student and b.student != context.portal_accommodation.not_occupied:
51            booked_beds += 1
52            booked_mapping[b.student] = b
53    bed_type_info.append({'name': bt_names[bt],
54                    'total': len(total_beds),
55                    'reserved': booked_beds,
56                   })
57info['bed_types'] = bed_type_info
58reserved_info = []
[1269]59students_url = "%s/campus/students" % (context.portal_url())
[3054]60student_records = aq_students(In('id',booked_mapping.keys()))
61for student_record in student_records:
[1297]62    d = {}
[3054]63    student_id = student_record.id
64    d['student'] = student_id
65    d['student_url'] ='%s/%s' % (students_url,student_id)
66    bed = context.getFormattedBed(booked_mapping[student_id].bed).split('/')
[1297]67    d['bed'] = " / ".join(bed[1:])
[3054]68    d.update(context.getFormattedStudentEntry(student_record))
69    reserved_info.append(d)
70reserved_info.sort(cmp_bed)
71info['reserved'] = reserved_info
[627]72
[622]73return info
Note: See TracBrowser for help on using the repository browser.