def index(): fix_schema = TrackingFixSchema(only=('time', 'location', 'altitude', 'elevation', 'pilot')) airport_schema = AirportSchema(only=('id', 'name', 'countryCode')) @cache.memoize(timeout=(60 * 60)) def get_nearest_airport(track): airport = Airport.by_location(track.location, None) if not airport: return None return dict(airport=airport_schema.dump(airport).data, distance=airport.distance(track.location)) tracks = [] for t in TrackingFix.get_latest(): nearest_airport = get_nearest_airport(t) track = fix_schema.dump(t).data if nearest_airport: track['nearestAirport'] = nearest_airport['airport'] track['nearestAirportDistance'] = nearest_airport['distance'] tracks.append(track) if request.user_id: followers = [ f.destination_id for f in Follower.query(source_id=request.user_id) ] else: followers = [] return jsonify(friends=followers, tracks=tracks)
def index(): fix_schema = TrackingFixSchema(only=('time', 'location', 'altitude', 'elevation', 'pilot')) airport_schema = AirportSchema(only=('id', 'name', 'countryCode')) @cache.memoize(timeout=(60 * 60)) def get_nearest_airport(track): airport = Airport.by_location(track.location, None) if not airport: return None return dict(airport=airport_schema.dump(airport).data, distance=airport.distance(track.location)) tracks = [] for t in TrackingFix.get_latest(): nearest_airport = get_nearest_airport(t) track = fix_schema.dump(t).data if nearest_airport: track['nearestAirport'] = nearest_airport['airport'] track['nearestAirportDistance'] = nearest_airport['distance'] tracks.append(track) if request.user_id: followers = [f.destination_id for f in Follower.query(source_id=request.user_id)] else: followers = [] return jsonify(friends=followers, tracks=tracks)
def index(): if 'application/json' not in request.headers.get('Accept', ''): return render_template('ember-page.jinja', active_page='tracking') fix_schema = TrackingFixSchema(only=('time', 'location', 'altitude', 'elevation', 'pilot')) airport_schema = AirportSchema(only=('id', 'name', 'countryCode')) @current_app.cache.memoize(timeout=(60 * 60)) def get_nearest_airport(track): airport = Airport.by_location(track.location, None) if not airport: return None return dict(airport=airport_schema.dump(airport).data, distance=airport.distance(track.location)) tracks = [] for t in TrackingFix.get_latest(): nearest_airport = get_nearest_airport(t) track = fix_schema.dump(t).data if nearest_airport: track['nearestAirport'] = nearest_airport['airport'] track['nearestAirportDistance'] = nearest_airport['distance'] tracks.append(track) if g.current_user: followers = [f.destination_id for f in Follower.query(source=g.current_user)] else: followers = [] return jsonify(friends=followers, tracks=tracks)
def index(): fix_schema = TrackingFixSchema(only=("time", "location", "altitude", "elevation", "pilot")) airport_schema = AirportSchema(only=("id", "name", "countryCode")) @cache.memoize(timeout=(60 * 60)) def get_nearest_airport(track): airport = Airport.by_location(track.location, None) if not airport: return None return dict( airport=airport_schema.dump(airport).data, distance=airport.distance(track.location), ) tracks = [] for t in TrackingFix.get_latest(): nearest_airport = get_nearest_airport(t) track = fix_schema.dump(t).data if nearest_airport: track["nearestAirport"] = nearest_airport["airport"] track["nearestAirportDistance"] = nearest_airport["distance"] tracks.append(track) if request.user_id: followers = [ f.destination_id for f in Follower.query(source_id=request.user_id) ] else: followers = [] return jsonify(friends=followers, tracks=tracks)
def following(): # Query list of pilots that are following the selected user query = Follower.query(source=g.user) \ .join('destination') \ .options(contains_eager('destination')) \ .options(subqueryload('destination.club')) \ .order_by(User.name) followers = [follower.destination for follower in query] add_current_user_follows(followers) return render_template('users/following.jinja', followers=followers)
def followers(user_id): user = get_requested_record(User, user_id) # Query list of pilots that are following the selected user query = (Follower.query(destination=user).join("source").options( contains_eager("source")).options( subqueryload("source.club")).order_by(User.name)) user_schema = UserSchema(only=("id", "name", "club")) followers = user_schema.dump([follower.source for follower in query], many=True).data add_current_user_follows(followers) return jsonify(followers=followers)
def add_current_user_follows(followers): """ If the user if signed in the followers will get an additional `current_user_follows` attribute, that shows if the signed in user is following the pilot """ if not request.user_id: return # Query list of people that the current user is following query = Follower.query(source_id=request.user_id) current_user_follows = [follower.destination_id for follower in query] for follower in followers: follower["currentUserFollows"] = follower["id"] in current_user_follows
def add_current_user_follows(followers): """ If the user if signed in the followers will get an additional `current_user_follows` attribute, that shows if the signed in user is following the pilot """ if not g.current_user: return # Query list of people that the current user is following query = Follower.query(source=g.current_user) current_user_follows = [follower.destination_id for follower in query] for follower in followers: follower.current_user_follows = (follower.id in current_user_follows)
def followers(user_id): user = get_requested_record(User, user_id) # Query list of pilots that are following the selected user query = Follower.query(destination=user) \ .join('source') \ .options(contains_eager('source')) \ .options(subqueryload('source.club')) \ .order_by(User.name) user_schema = UserSchema(only=('id', 'name', 'club')) followers = user_schema.dump([follower.source for follower in query], many=True).data add_current_user_follows(followers) return jsonify(followers=followers)
def following(user_id): user = get_requested_record(User, user_id) # Query list of pilots that are following the selected user query = Follower.query(source=user) \ .join('destination') \ .options(contains_eager('destination')) \ .options(subqueryload('destination.club')) \ .order_by(User.name) user_schema = UserSchema(only=('id', 'name', 'club')) following = user_schema.dump([follower.destination for follower in query], many=True).data add_current_user_follows(following) return jsonify(following=following)
def following(user_id): user = get_requested_record(User, user_id) # Query list of pilots that are following the selected user query = ( Follower.query(source=user) .join("destination") .options(contains_eager("destination")) .options(subqueryload("destination.club")) .order_by(User.name) ) user_schema = UserSchema(only=("id", "name", "club")) following = user_schema.dump( [follower.destination for follower in query], many=True ).data add_current_user_follows(following) return jsonify(following=following)
def index(): tracks = TrackingFix.get_latest() @current_app.cache.memoize(timeout=(60 * 60)) def get_nearest_airport(track): airport = Airport.by_location(track.location, None) if not airport: return None distance = airport.distance(track.location) return { 'name': airport.name, 'country_code': airport.country_code, 'distance': distance, } tracks = [(track, get_nearest_airport(track)) for track in tracks] if g.current_user: followers = [ f.destination_id for f in Follower.query(source=g.current_user) ] def is_self_or_follower(track): pilot_id = track[0].pilot_id return pilot_id == g.current_user.id or pilot_id in followers friend_tracks = [t for t in tracks if is_self_or_follower(t)] other_tracks = [t for t in tracks if t not in friend_tracks] else: friend_tracks = [] other_tracks = tracks return render_template('tracking/list.jinja', friend_tracks=friend_tracks, other_tracks=other_tracks)
def index(): tracks = TrackingFix.get_latest() @current_app.cache.memoize(timeout=(60 * 60)) def get_nearest_airport(track): airport = Airport.by_location(track.location, None) if not airport: return None distance = airport.distance(track.location) return { 'name': airport.name, 'country_code': airport.country_code, 'distance': distance, } tracks = [(track, get_nearest_airport(track)) for track in tracks] if g.current_user: followers = [f.destination_id for f in Follower.query(source=g.current_user)] def is_self_or_follower(track): pilot_id = track[0].pilot_id return pilot_id == g.current_user.id or pilot_id in followers friend_tracks = [t for t in tracks if is_self_or_follower(t)] other_tracks = [t for t in tracks if t not in friend_tracks] else: friend_tracks = [] other_tracks = tracks return render_template('tracking/list.jinja', friend_tracks=friend_tracks, other_tracks=other_tracks)
def index(): if 'application/json' not in request.headers.get('Accept', ''): return render_template('ember-page.jinja', active_page='tracking') fix_schema = TrackingFixSchema(only=('time', 'location', 'altitude', 'elevation', 'pilot')) airport_schema = AirportSchema(only=('id', 'name', 'countryCode')) @current_app.cache.memoize(timeout=(60 * 60)) def get_nearest_airport(track): airport = Airport.by_location(track.location, None) if not airport: return None return dict(airport=airport_schema.dump(airport).data, distance=airport.distance(track.location)) tracks = [] for t in TrackingFix.get_latest(): nearest_airport = get_nearest_airport(t) track = fix_schema.dump(t).data if nearest_airport: track['nearestAirport'] = nearest_airport['airport'] track['nearestAirportDistance'] = nearest_airport['distance'] tracks.append(track) if g.current_user: followers = [ f.destination_id for f in Follower.query(source=g.current_user) ] else: followers = [] return jsonify(friends=followers, tracks=tracks)
def index(): fix_schema = TrackingFixSchema( only=("time", "location", "altitude", "elevation", "pilot") ) airport_schema = AirportSchema(only=("id", "name", "countryCode")) @cache.memoize(timeout=(60 * 60)) def get_nearest_airport(track): airport = Airport.by_location(track.location, None) if not airport: return None return dict( airport=airport_schema.dump(airport).data, distance=airport.distance(track.location), ) tracks = [] for t in TrackingFix.get_latest(): nearest_airport = get_nearest_airport(t) track = fix_schema.dump(t).data if nearest_airport: track["nearestAirport"] = nearest_airport["airport"] track["nearestAirportDistance"] = nearest_airport["distance"] tracks.append(track) if request.user_id: followers = [ f.destination_id for f in Follower.query(source_id=request.user_id) ] else: followers = [] return jsonify(friends=followers, tracks=tracks)