## Script (Python) "getBedStatusFromHall"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=code=None
##title=
##
# $Id: change_bed.py 1206 2007-01-05 18:24:56Z joachim $
"""
"""
import logging
logger = logging.getLogger('Student.Accommodation.change_bed')
import re
request = context.REQUEST
redirect = request.RESPONSE.redirect
mtool = context.portal_membership
wf = context.portal_workflow
member = mtool.getAuthenticatedMember()
member_id = str(member)
path_info = request.get('PATH_INFO').split('/')

hall,block,room,bed = code.split('_')
hres = context.portal_catalog(id = hall)
if not hres:
    return None
h = hres[0].getObject().getContent()
sex = 'male'
if block in h.blocks_for_female:
    sex = 'female'
room_nr = int(room)
bt = 're'
reserved = [(r.split('/')[0],int(r.split('/')[1])) for r in re.split(',|\.| ',h.reserved_rooms)
                                     if r]
if (block,room_nr) in reserved:
    bt = "reserved"
elif not h.special_handling.startswith("no"):
    bt = h.special_handling
elif bed in h.beds_for_fresh:
    bt = 'fr'
#elif bed in h.beds_for_returning:
#    bt = 're'
elif bed in h.beds_for_final:
    bt = 'fi'
if h.special_handling.startswith("no_"):
    bt += "_" + h.special_handling[3:]
bt = "%s_%s" % (sex,bt)
uid = '%s_%s_%d_%s' % (hall,block,room_nr,bed)
return bt