예제 #1
0
def follow(user_id):
    user = get_requested_record(User, user_id)
    current_user = User.get(request.user_id)
    Follower.follow(current_user, user)
    create_follower_notification(user, current_user)
    db.session.commit()
    return jsonify()
예제 #2
0
def follow(user_id):
    user = get_requested_record(User, user_id)
    current_user = User.get(request.user_id)
    Follower.follow(current_user, user)
    create_follower_notification(user, current_user)
    db.session.commit()
    return jsonify()
예제 #3
0
def follow():
    Follower.follow(g.current_user, g.user)
    create_follower_notification(g.user, g.current_user)
    db.session.flush()

    unlock_user_achievements(g.current_user, FOLLOW_ACHIEVEMENTS)
    unlock_user_achievements(g.user, FOLLOWER_ACHIEVEMENTS)
    db.session.commit()
    return redirect(request.referrer or url_for('.index'))
예제 #4
0
파일: user.py 프로젝트: kedder/skylines
def follow():
    Follower.follow(g.current_user, g.user)
    create_follower_notification(g.user, g.current_user)
    db.session.flush()

    unlock_user_achievements(g.current_user, FOLLOW_ACHIEVEMENTS)
    unlock_user_achievements(g.user, FOLLOWER_ACHIEVEMENTS)
    db.session.commit()
    return redirect(request.referrer or url_for('.index'))
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
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)
예제 #8
0
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)
예제 #9
0
def test_following(db_session, client):
    john = users.john()
    jane = users.jane()
    add_fixtures(db_session, john, jane)
    Follower.follow(john, jane)

    res = client.get("/users/{id}".format(id=john.id))
    assert res.status_code == 200
    assert res.json["following"] == 1

    res = client.get("/users/{id}".format(id=jane.id))
    assert res.status_code == 200
    assert res.json["followers"] == 1
    assert "followed" not in res.json

    res = client.get("/users/{id}".format(id=jane.id), headers=auth_for(john))
    assert res.status_code == 200
    assert res.json["followers"] == 1
    assert res.json["followed"] == True
예제 #10
0
파일: user.py 프로젝트: kerel-fs/skylines
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)
예제 #11
0
파일: user.py 프로젝트: Adrien81/skylines
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)
예제 #12
0
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)
예제 #13
0
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
예제 #14
0
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)
예제 #15
0
파일: user.py 프로젝트: kerel-fs/skylines
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)
예제 #16
0
파일: user.py 프로젝트: Adrien81/skylines
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)
예제 #17
0
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
예제 #18
0
파일: users.py 프로젝트: vdrok/skylines
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)
예제 #19
0
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)
예제 #20
0
파일: tracking.py 프로젝트: imclab/skylines
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)
예제 #21
0
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)
예제 #22
0
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)
예제 #23
0
파일: tracking.py 프로젝트: imclab/skylines
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)
예제 #24
0
def unfollow(user_id):
    user = get_requested_record(User, user_id)
    current_user = User.get(request.user_id)
    Follower.unfollow(current_user, user)
    db.session.commit()
    return jsonify()
예제 #25
0
 def unfollow(self):
     Follower.unfollow(request.identity['user'], self.user)
     redirect('.')
예제 #26
0
 def follow(self):
     Follower.follow(request.identity['user'], self.user)
     create_follower_notification(self.user, request.identity['user'])
     redirect('.')
예제 #27
0
def unfollow(user_id):
    user = get_requested_record(User, user_id)
    current_user = User.get(request.user_id)
    Follower.unfollow(current_user, user)
    db.session.commit()
    return jsonify()
예제 #28
0
파일: user.py 프로젝트: imclab/skylines
def unfollow():
    Follower.unfollow(g.current_user, g.user)
    db.session.commit()
    return redirect(url_for('.index'))
예제 #29
0
파일: user.py 프로젝트: imclab/skylines
def follow():
    Follower.follow(g.current_user, g.user)
    create_follower_notification(g.user, g.current_user)
    db.session.commit()
    return redirect(url_for('.index'))