Ejemplo n.º 1
0
def more():
    start = request.args.get('start', 0, type=int)
    end = request.args.get('end', 0, type=int)

    stream = current_user.stream(start, end)

    target_image_dict = {}
    for target in current_user.targets():
        image_url = sch.get_user_image(target.sc_id)
        target_image_dict[target.sc_id] = image_url

    return jsonify(tracks=[track.serialize() for track in stream],
                   images=target_image_dict)
Ejemplo n.º 2
0
def more():
    start = request.args.get('start', 0, type=int)
    end = request.args.get('end', 0, type=int)
    
    stream = current_user.stream(start,end)
    
    target_image_dict = {}
    for target in current_user.targets():
        image_url = sch.get_user_image(target.sc_id)
        target_image_dict[target.sc_id] = image_url

    return jsonify(tracks=[track.serialize() for track in stream],
                   images=target_image_dict
                   )
Ejemplo n.º 3
0
def profile():
    targets = current_user.targets()
    new_target_form = forms.TargetForm()
    if new_target_form.validate_on_submit():

        # Try to resolve the username
        try:
            user_id, permalink=sch.resolve_user_id(new_target_form.sc_user_profile.data)
        except ValueError:
            flash("This user doesn't seem to exist. Try a different name.", "error")
            return render_template('profile.html',
                                   new_target_form=new_target_form,
                                   targets=targets)

        # Create a target from that id if it doesn't already exist
        try:
            new_target = models.Target.create_target(
                sc_id=user_id,
                permalink=permalink
            )
            worker.update_target_in_db(new_target)
            flash("This user is now being tracked.", "success")
        except ValueError:
            flash("This user is already being tracked.", "message")
            pass

        # Map the current user to that target
        try:
            models.UserTarget.create_usertarget(
                user=g.user._get_current_object(),
                target=models.Target.get(
                    models.Target.sc_id == user_id
                )
            )
            flash("You are now following them.", "success")
        except ValueError:
            flash("You are already following this user.", "error")

    return render_template('profile.html', 
                           new_target_form=new_target_form, 
                           targets=targets)
Ejemplo n.º 4
0
def profile():
    targets = current_user.targets()
    new_target_form = forms.TargetForm()
    if new_target_form.validate_on_submit():

        # Try to resolve the username
        try:
            user_id, permalink = sch.resolve_user_id(
                new_target_form.sc_user_profile.data)
        except ValueError:
            flash("This user doesn't seem to exist. Try a different name.",
                  "error")
            return render_template('profile.html',
                                   new_target_form=new_target_form,
                                   targets=targets)

        # Create a target from that id if it doesn't already exist
        try:
            new_target = models.Target.create_target(sc_id=user_id,
                                                     permalink=permalink)
            worker.update_target_in_db(new_target)
            flash("This user is now being tracked.", "success")
        except ValueError:
            flash("This user is already being tracked.", "message")
            pass

        # Map the current user to that target
        try:
            models.UserTarget.create_usertarget(
                user=g.user._get_current_object(),
                target=models.Target.get(models.Target.sc_id == user_id))
            flash("You are now following them.", "success")
        except ValueError:
            flash("You are already following this user.", "error")

    return render_template('profile.html',
                           new_target_form=new_target_form,
                           targets=targets)