def shelter_unit():
    """
        REST controller to
            retrieve options for shelter unit selection
            show layer on Map
            imports
    """

    # [Geo]JSON & Map Popups or Imports only
    def prep(r):
        if r.representation == "plain":
            # Have the 'Open' button open in the context of the Shelter
            record_id = r.id
            table = s3db.cr_shelter_unit
            row = db(table.id == record_id).select(table.shelter_id,
                                                   limitby=(0, 1)
                                                   ).first()
            shelter_id = row.shelter_id
            s3db.configure("cr_shelter_unit",
                           popup_url = URL(c="cr", f="shelter",
                                           args=[shelter_id, "shelter_unit",
                                                 record_id]),
                        )
            return True
        elif r.representation in ("json", "geojson", "plain") or \
             r.method == "import":
            return True
        return False

    s3.prep = prep

    return s3_rest_controller()

# -----------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/controllers/cr.py/shelter_unit/original