'Check if the housing unit belongs to the requested shelter'

@staticmethod
def cr_shelter_registration_onvalidation(form):

    request = current.request
    controller = request.controller
    if (controller == 'dvr'):
        return
    unit_id = None
    if (type(form) is Row):
        form_vars = form
    else:
        form_vars = form.vars
    if (controller == 'evr'):
        shelter_id = form_vars.shelter_id
        unit_id = form_vars.shelter_unit_id
    elif (controller == 'cr'):
        shelter_id = (form_vars.shelter_id or (form.record and form.record.shelter_id) or request.args[0])
        unit_id = form_vars.shelter_unit_id
    if (unit_id is None):
        current.response.warning = current.T('Warning:    No    housing    unit    selected')
    else:
        db = current.db
        htable = db.cr_shelter_unit
        record = db((htable.id == unit_id)).select(htable.shelter_id, limitby=(0, 1)).first()
        if (str(record.shelter_id) != str(shelter_id)):
            error = current.T('You    have    to    select    a    housing    unit    belonging    to    the    shelter')
            form.errors['branch_id'] = error
            current.response.error = error
