[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 2845 2007-12-03 21:14:20Z joachim $ |
---|
[622] | 11 | """ |
---|
[1269] | 12 | return Info about a Accommodation Hall |
---|
[622] | 13 | """ |
---|
[2845] | 14 | try: |
---|
| 15 | from Products.zdb import set_trace |
---|
| 16 | except: |
---|
| 17 | def set_trace(): |
---|
| 18 | pass |
---|
| 19 | |
---|
| 20 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
[1269] | 21 | |
---|
| 22 | def cmp_bed(a,b): |
---|
| 23 | if a['bed'] > b['bed']: |
---|
| 24 | return 1 |
---|
| 25 | return -1 |
---|
| 26 | |
---|
[622] | 27 | request = context.REQUEST |
---|
| 28 | |
---|
| 29 | wf = context.portal_workflow |
---|
| 30 | path_info = request.get('PATH_INFO').split('/') |
---|
| 31 | mtool = context.portal_membership |
---|
[2845] | 32 | portal_accommodation = context.portal_accommodation |
---|
| 33 | aq_accommodation = portal_accommodation.evalAdvancedQuery |
---|
[622] | 34 | info = {} |
---|
| 35 | #dep_id = request.get('PATH_TRANSLATED').split('/')[-2] |
---|
| 36 | dep_id = context.aq_parent.getId() |
---|
| 37 | info['action'] = "%s" % context.absolute_url() |
---|
| 38 | info['choosen_ids'] = request.get('ids',[]) |
---|
| 39 | info['doc'] = context.getContent() |
---|
[2845] | 40 | bed_types = portal_accommodation.uniqueValuesFor('bed_type') |
---|
[627] | 41 | bt_list = [] |
---|
| 42 | bt_names = context.getBedTypeNames() |
---|
[2845] | 43 | res = portal_accommodation.uniqueValuesFor('student') |
---|
| 44 | all_booked = [st for st in res if st and st != 'not_occupied'] |
---|
[1297] | 45 | booked_list = [] |
---|
[627] | 46 | for bt in bed_types: |
---|
[2845] | 47 | total = len(portal_accommodation(bed_type=bt,hall=context.getId())) |
---|
[1269] | 48 | if total <= 1: |
---|
| 49 | continue |
---|
[2845] | 50 | booked = portal_accommodation.searchResults({'bed_type': bt, |
---|
[1297] | 51 | 'student':all_booked, |
---|
| 52 | 'hall': context.getId()}) |
---|
[654] | 53 | bt_list.append({'name': bt_names[bt], |
---|
| 54 | 'total': total, |
---|
[1297] | 55 | 'reserved': len(booked), |
---|
[654] | 56 | }) |
---|
[1297] | 57 | booked_list.extend(booked) |
---|
[2845] | 58 | # query = ~Eq('student','not_occupied') |
---|
| 59 | # beds = aq_accommodation(query,sortSpecs=('bed_type',)) |
---|
| 60 | # bt_list = [] |
---|
| 61 | # bt_names = context.getBedTypeNames() |
---|
| 62 | # bt = 'xxx' |
---|
| 63 | # for bed in beds: |
---|
| 64 | # if bt != bed.bed_type: |
---|
| 65 | # bt = bed.bed_type |
---|
| 66 | # total = len(aq_accommodation(Eq('bed_type',bt))) |
---|
| 67 | # bt_list.append({'name': bt_names[bt], |
---|
| 68 | # 'total': total, |
---|
| 69 | # 'reserved': len(booked), |
---|
| 70 | # }) |
---|
| 71 | |
---|
[627] | 72 | info['bed_types'] = bt_list |
---|
[654] | 73 | res_list = [] |
---|
[1269] | 74 | students_url = "%s/campus/students" % (context.portal_url()) |
---|
[1297] | 75 | for sbrain in booked_list: |
---|
| 76 | d = {} |
---|
| 77 | st = sbrain.student |
---|
| 78 | if not st: |
---|
| 79 | continue |
---|
| 80 | d['student'] = st |
---|
| 81 | d['student_url'] ='%s/%s' % (students_url,st) |
---|
[1566] | 82 | bed = context.getFormattedBed(sbrain.bed).split('/') |
---|
[1297] | 83 | d['bed'] = " / ".join(bed[1:]) |
---|
| 84 | erg = context.students_catalog(id = st) |
---|
| 85 | if erg: |
---|
| 86 | sd = context.getFormattedStudentEntry(erg[0]) |
---|
| 87 | d.update(sd) |
---|
[1914] | 88 | else: |
---|
| 89 | #d['student'] = None |
---|
| 90 | d['student_url'] = None |
---|
| 91 | #d['bed'] = None |
---|
| 92 | d['name'] = 'Student record removed' |
---|
[1297] | 93 | res_list.append(d) |
---|
[1269] | 94 | res_list.sort(cmp_bed) |
---|
[654] | 95 | info['reserved'] = res_list |
---|
[627] | 96 | |
---|
[622] | 97 | return info |
---|