| 1 | ## Script (Python) "getBedStatusFromHall"
|
|---|
| 2 | ##bind container=container
|
|---|
| 3 | ##bind context=context
|
|---|
| 4 | ##bind namespace=
|
|---|
| 5 | ##bind script=script
|
|---|
| 6 | ##bind subpath=traverse_subpath
|
|---|
| 7 | ##parameters=code=None
|
|---|
| 8 | ##title=
|
|---|
| 9 | ##
|
|---|
| 10 | # $Id: change_bed.py 1206 2007-01-05 18:24:56Z joachim $
|
|---|
| 11 | """
|
|---|
| 12 | """
|
|---|
| 13 | import logging
|
|---|
| 14 | logger = logging.getLogger('Student.Accommodation.change_bed')
|
|---|
| 15 | import re
|
|---|
| 16 | request = context.REQUEST
|
|---|
| 17 | redirect = request.RESPONSE.redirect
|
|---|
| 18 | mtool = context.portal_membership
|
|---|
| 19 | wf = context.portal_workflow
|
|---|
| 20 | member = mtool.getAuthenticatedMember()
|
|---|
| 21 | member_id = str(member)
|
|---|
| 22 | path_info = request.get('PATH_INFO').split('/')
|
|---|
| 23 |
|
|---|
| 24 | hall,block,room,bed = code.split('_')
|
|---|
| 25 | hres = context.portal_catalog(id = hall)
|
|---|
| 26 | if not hres:
|
|---|
| 27 | return None
|
|---|
| 28 | h = hres[0].getObject().getContent()
|
|---|
| 29 | sex = 'male'
|
|---|
| 30 | if block in h.blocks_for_female:
|
|---|
| 31 | sex = 'female'
|
|---|
| 32 | room_nr = int(room)
|
|---|
| 33 | bt = 're'
|
|---|
| 34 | reserved = [(r.split('/')[0],int(r.split('/')[1])) for r in re.split(',|\.| ',h.reserved_rooms)
|
|---|
| 35 | if r]
|
|---|
| 36 | if (block,room_nr) in reserved:
|
|---|
| 37 | bt = "reserved"
|
|---|
| 38 | elif not h.special_handling.startswith("no"):
|
|---|
| 39 | bt = h.special_handling
|
|---|
| 40 | elif bed in h.beds_for_fresh:
|
|---|
| 41 | bt = 'fr'
|
|---|
| 42 | #elif bed in h.beds_for_returning:
|
|---|
| 43 | # bt = 're'
|
|---|
| 44 | elif bed in h.beds_for_final:
|
|---|
| 45 | bt = 'fi'
|
|---|
| 46 | if h.special_handling.startswith("no_"):
|
|---|
| 47 | bt += "_" + h.special_handling[3:]
|
|---|
| 48 | bt = "%s_%s" % (sex,bt)
|
|---|
| 49 | uid = '%s_%s_%d_%s' % (hall,block,room_nr,bed)
|
|---|
| 50 | return bt |
|---|