def get(self, id): buses_in_group = Bus.query.filter(and_(Bus.user_id == g.user.id, Bus.group_id == id)).all() buses_in_group_res = [] for bus in buses_in_group: b = dict() b['route_id'] = bus.route_id b['bus_name'] = bus.plate_number b['bus_id'] = bus.id b['bus_eui'] = bus.eui buses_in_group_res.append(b) routes = Route.get_routes() buses_all = Bus.get_all() res = [] for route in routes: data = {} data['route_id'] = route.id data['route_name'] = route.route_name buses = [] for bus in buses_all: if bus.route_id == route.id: in_group = bus.group_id == id buses.append({'route_id': bus.route_id, 'bus_name': bus.plate_number, 'bus_id': bus.id, 'in_group': in_group, 'bus_eui': bus.eui}) data['buses'] = buses res.append(data) return jsonify({'buses_all': res, 'in_group': buses_in_group_res})
def get(self): routes = Route.get_routes() # if not routes: # abort(404) return routes