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 1596 2007-03-19 21:45:44Z joachim $ |
---|
11 | """ |
---|
12 | return Info about a Accommodation Hall |
---|
13 | """ |
---|
14 | |
---|
15 | def cmp_bed(a,b): |
---|
16 | if a['bed'] > b['bed']: |
---|
17 | return 1 |
---|
18 | return -1 |
---|
19 | |
---|
20 | request = context.REQUEST |
---|
21 | |
---|
22 | wf = context.portal_workflow |
---|
23 | path_info = request.get('PATH_INFO').split('/') |
---|
24 | mtool = context.portal_membership |
---|
25 | pa = context.portal_accommodation |
---|
26 | info = {} |
---|
27 | #dep_id = request.get('PATH_TRANSLATED').split('/')[-2] |
---|
28 | dep_id = context.aq_parent.getId() |
---|
29 | info['action'] = "%s" % context.absolute_url() |
---|
30 | info['choosen_ids'] = request.get('ids',[]) |
---|
31 | info['doc'] = context.getContent() |
---|
32 | bed_types = pa.uniqueValuesFor('bed_type') |
---|
33 | bt_list = [] |
---|
34 | bt_names = context.getBedTypeNames() |
---|
35 | res = pa.uniqueValuesFor('student') |
---|
36 | all_booked = [st for st in res if st] |
---|
37 | booked_list = [] |
---|
38 | #from Products.zdb import set_trace;set_trace() |
---|
39 | for bt in bed_types: |
---|
40 | total = len(pa(bed_type=bt,hall=context.getId())) |
---|
41 | if total <= 1: |
---|
42 | continue |
---|
43 | booked = pa.searchResults({'bed_type': bt, |
---|
44 | 'student':all_booked, |
---|
45 | 'hall': context.getId()}) |
---|
46 | bt_list.append({'name': bt_names[bt], |
---|
47 | 'total': total, |
---|
48 | 'reserved': len(booked), |
---|
49 | }) |
---|
50 | booked_list.extend(booked) |
---|
51 | info['bed_types'] = bt_list |
---|
52 | res_list = [] |
---|
53 | students_url = "%s/campus/students" % (context.portal_url()) |
---|
54 | for 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) |
---|
61 | bed = context.getFormattedBed(sbrain.bed).split('/') |
---|
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) |
---|
67 | res_list.append(d) |
---|
68 | res_list.sort(cmp_bed) |
---|
69 | info['reserved'] = res_list |
---|
70 | |
---|
71 | return info |
---|