

def sites_for_org():
    '\n        Used to provide the list of Sites for an Organisation\n        - used in User Registration & Assets\n    '
    try:
        org = request.args[0]
    except:
        result = current.xml.json_message(False, 400, 'No Org provided!')
    else:
        try:
            org = int(org)
        except:
            result = current.xml.json_message(False, 400, 'Invalid Org provided!')
        else:
            stable = s3db.org_site
            if settings.get_org_branches():
                btable = s3db.org_organisation_branch
                query = ((btable.organisation_id == org) & (btable.deleted != True))
                rows = db(query).select(btable.branch_id)
                org_ids = ([row.branch_id for row in rows] + [org])
                query = (stable.organisation_id.belongs(org_ids) & (stable.deleted != True))
            else:
                query = ((stable.organisation_id == org) & (stable.deleted != True))
            rows = db(query).select(stable.site_id, stable.name, orderby=stable.name)
            result = rows.json()
    finally:
        response.headers['Content-Type'] = 'application/json'
        return result

dataset/ETHPy150Open sahana/eden/controllers/org.py sites_for_org/original