Index: WAeUP_SRP/base/skins/waeup_accommodation/getAccoHallInfo.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_accommodation/getAccoHallInfo.py	(revision 3053)
+++ WAeUP_SRP/base/skins/waeup_accommodation/getAccoHallInfo.py	(revision 3054)
@@ -26,72 +26,48 @@
 
 request = context.REQUEST
-
-wf = context.portal_workflow
-path_info = request.get('PATH_INFO').split('/')
-mtool = context.portal_membership
 portal_accommodation = context.portal_accommodation
 aq_accommodation = portal_accommodation.evalAdvancedQuery
+aq_students = context.students_catalog.evalAdvancedQuery
 info = {}
-#dep_id = request.get('PATH_TRANSLATED').split('/')[-2]
-dep_id = context.aq_parent.getId()
 info['action'] = "%s" % context.absolute_url()
 info['choosen_ids'] = request.get('ids',[])
 info['doc'] = context.getContent()
-bed_types = portal_accommodation.uniqueValuesFor('bed_type')
 bt_list = []
 bt_names =  context.getBedTypeNames()
-res = portal_accommodation.uniqueValuesFor('student')
-all_booked = [st for st in res if st and st != 'not_occupied']
+query = Eq('hall',context.getId()) 
+beds = aq_accommodation(query)
+bed_types = []
+for bed in beds:
+    if bed.bed_type not in bed_types:
+        bed_types += bed.bed_type,
+bed_type_info = []
 booked_list = []
+booked_mapping = {}
 for bt in bed_types:
-    total = len(portal_accommodation(bed_type=bt,hall=context.getId()))
-    if total <= 1:
-        continue
-    booked = portal_accommodation.searchResults({'bed_type': bt,
-                                 'student':all_booked,
-                                 'hall': context.getId()})
-    bt_list.append({'name': bt_names[bt],
-                    'total': total,
-                    'reserved': len(booked),
-                    })
-    booked_list.extend(booked)
-# query = ~Eq('student','not_occupied') 
-# beds = aq_accommodation(query,sortSpecs=('bed_type',))
-# bt_list = []
-# bt_names =  context.getBedTypeNames()
-# bt = 'xxx' 
-# for bed in beds:
-#     if bt != bed.bed_type:
-#         bt = bed.bed_type
-#         total = len(aq_accommodation(Eq('bed_type',bt)))
-#         bt_list.append({'name': bt_names[bt],
-#                         'total': total,
-#                         'reserved': len(booked),
-#                        })
-      
-info['bed_types'] = bt_list
-res_list = []
+    total_beds = [b for b in beds if b.bed_type == bt]
+    booked_beds = 0
+    for b in total_beds:
+        if b.student and b.student != context.portal_accommodation.not_occupied:
+            booked_beds += 1
+            booked_mapping[b.student] = b
+    bed_type_info.append({'name': bt_names[bt],
+                    'total': len(total_beds),
+                    'reserved': booked_beds,
+                   })
+info['bed_types'] = bed_type_info
+reserved_info = []
 students_url = "%s/campus/students" % (context.portal_url())
-for sbrain in booked_list:
+student_records = aq_students(In('id',booked_mapping.keys()))
+for student_record in student_records:
     d = {}
-    st = sbrain.student
-    if not st:
-        continue
-    d['student'] = st
-    d['student_url'] ='%s/%s' % (students_url,st)
-    bed = context.getFormattedBed(sbrain.bed).split('/')
+    student_id = student_record.id 
+    d['student'] = student_id
+    d['student_url'] ='%s/%s' % (students_url,student_id)
+    bed = context.getFormattedBed(booked_mapping[student_id].bed).split('/')
     d['bed'] = " / ".join(bed[1:])
-    erg = context.students_catalog(id = st)
-    if erg:
-        sd = context.getFormattedStudentEntry(erg[0])
-        d.update(sd)
-    else:
-        #d['student'] = None
-        d['student_url'] = None
-        #d['bed'] = None
-        d['name'] = 'Student record removed'
-    res_list.append(d)
-res_list.sort(cmp_bed)
-info['reserved'] = res_list
+    d.update(context.getFormattedStudentEntry(student_record))
+    reserved_info.append(d)
+reserved_info.sort(cmp_bed)
+info['reserved'] = reserved_info
 
 return info
