def get(self, org_id, location_id):
response = {
API_ENVELOPE: {},
"resources": [
"attendance", "managers", "shifts", "timeclocks",
"timeoffrequests", "roles"
],
}
parser = reqparse.RequestParser()
parser.add_argument("recurse", type=inputs.boolean, default=False)
parser.add_argument("archived", type=inputs.boolean)
args = parser.parse_args()
args = dict((k, v) for k, v in args.iteritems() if v is not None)
location = Location.query.get_or_404(location_id)
response[API_ENVELOPE] = marshal(location, location_fields)
if args["recurse"]:
roles_query = Role.query.filter_by(location_id=location_id)
if "archived" in args:
roles_query = roles_query.filter_by(archived=args["archived"])
roles = roles_query.all()
response[API_ENVELOPE].update({
"roles":
map(lambda role: marshal(role, role_fields), roles)
})
# also include managers for the location
managers = User.query.join(User.manager_of).filter(
Location.id == location_id).all()
response[API_ENVELOPE].update({
"managers":
map(lambda manager: marshal(manager, user_fields), managers)
})
return response
评论列表
文章目录