[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 1269 2007-01-11 17:06:34Z joachim $ |
---|
[622] | 11 | """ |
---|
[1269] | 12 | return Info about a Accommodation Hall |
---|
[622] | 13 | """ |
---|
[1269] | 14 | |
---|
| 15 | def cmp_bed(a,b): |
---|
| 16 | if a['bed'] > b['bed']: |
---|
| 17 | return 1 |
---|
| 18 | return -1 |
---|
| 19 | |
---|
[622] | 20 | request = context.REQUEST |
---|
[1269] | 21 | #from Products.zdb import set_trace;set_trace() |
---|
[622] | 22 | |
---|
| 23 | wf = context.portal_workflow |
---|
| 24 | path_info = request.get('PATH_INFO').split('/') |
---|
| 25 | mtool = context.portal_membership |
---|
[627] | 26 | pa = context.portal_accommodation |
---|
[622] | 27 | info = {} |
---|
| 28 | #dep_id = request.get('PATH_TRANSLATED').split('/')[-2] |
---|
| 29 | dep_id = context.aq_parent.getId() |
---|
| 30 | info['action'] = "%s" % context.absolute_url() |
---|
| 31 | info['choosen_ids'] = request.get('ids',[]) |
---|
| 32 | info['doc'] = context.getContent() |
---|
[627] | 33 | bed_types = pa.uniqueValuesFor('bed_type') |
---|
| 34 | bt_list = [] |
---|
| 35 | bt_names = context.getBedTypeNames() |
---|
[654] | 36 | reserved = pa.uniqueValuesFor('student') |
---|
[627] | 37 | for bt in bed_types: |
---|
[702] | 38 | total = len(pa(bed_type=bt,hall=context.getId())) |
---|
[1269] | 39 | if total <= 1: |
---|
| 40 | continue |
---|
[702] | 41 | free = len(pa.searchResults({'bed_type': bt, |
---|
| 42 | 'student':reserved, |
---|
| 43 | 'hall': context.getId()})) |
---|
[654] | 44 | bt_list.append({'name': bt_names[bt], |
---|
| 45 | 'total': total, |
---|
| 46 | 'reserved': free, |
---|
| 47 | }) |
---|
[627] | 48 | info['bed_types'] = bt_list |
---|
[654] | 49 | res_list = [] |
---|
[1269] | 50 | students_url = "%s/campus/students" % (context.portal_url()) |
---|
| 51 | if reserved: |
---|
[654] | 52 | for st in reserved: |
---|
| 53 | if st: |
---|
| 54 | res = pa(hall=context.getId(),student=st) |
---|
[1269] | 55 | if not res: |
---|
| 56 | continue |
---|
| 57 | d = {} |
---|
| 58 | d['student'] = st |
---|
| 59 | d['student_url'] ='%s/%s' % (students_url,st) |
---|
| 60 | bed = context.formatBed(res[0].bed).split('/') |
---|
| 61 | d['bed'] = " / ".join(bed[1:]) |
---|
| 62 | erg = context.students_catalog(id = st) |
---|
| 63 | if erg: |
---|
| 64 | sd = context.getFormattedStudentEntry(erg[0]) |
---|
| 65 | d.update(sd) |
---|
| 66 | res_list.append(d) |
---|
| 67 | res_list.sort(cmp_bed) |
---|
[654] | 68 | info['reserved'] = res_list |
---|
[627] | 69 | |
---|
[622] | 70 | return info |
---|