Ejemplo n.º 1
0
def unfollow_user(id):
    followed_user = User.query.filter(User.id == id).first()
    form = FollowForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        follower_id = form.data['follower_id']
        follower = User.query.filter(User.id == follower_id).first()
        followed_user.followers.remove(follower)
        print(followed_user.followers.all())
        db.session.commit()
        return followed_user.to_dict()
def assign():
    form=FollowForm()
    if form.validate_on_submit():
        pat=Patient.query.filter_by(username=form.username.data).first()
        thep=Therapist.query.filter_by(username=current_user.username).first()
        int= Intervention(intervention_name=form.name.data,patient_id=pat.id,therapist_id=thep.id)
        db.session.add(int)
        db.session.commit()
        flash('The patient has successfully been assigned!')
        return redirect(url_for('assign'))
    return render_template('assign.html', title='Assignment', form=form)
Ejemplo n.º 3
0
def follow():
    form = FollowForm()
    if form.validate_on_submit():
        to_follow = Follow(code=form.station_id.data.upper(),
                           text_alert=form.text_alert.data,
                           email_alert=form.email_alert.data,
                           user_id=current_user.id)
        db.session.add(to_follow)
        db.session.commit()
        flash(
            f'Congratulations, you are now following {form.station_id.data}!')
        return redirect(url_for('index'))
    return render_template('follow.html', title='Follow', form=form)
Ejemplo n.º 4
0
def follow_user(followed_user_id):
    followed_user = User.query.filter(User.id == followed_user_id).first()
    form = FollowForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        follower_id = form.data['follower_id']
        new_follower = User.query.filter(User.id == follower_id).first()
        followers = followed_user.followers.all()
        if new_follower in followers:
            return 'User Already Follows'
        followed_user.followers.append(new_follower)
        db.session.commit()
        return {follower.id: {"id": follower.id, "username": follower.username}
                for follower in followed_user.followers.all()}
Ejemplo n.º 5
0
def unfollow(username):
    form = FollowForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if not user:
            flash('User {} not found.'.format(username))
            return redirect(url_for('index'))
        if user == current_user:
            flash('You cannot unfollow yourself!')
            return redirect(url_for('user', username=username))
        current_user.unfollow(user)
        db.session.commit()
        flash('You are now unfollowing {}.'.format(username))
        return redirect(url_for('user', username=username))
    return redirect(url_for('index'))
Ejemplo n.º 6
0
def unfollow(username):
    form = FollowForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash('User {} not found'.format(username))
            return redirect(url_for('index'))
        if user == current_user:
            flash('You cannot unfollow yourself'.format(username))
            return redirect(url_for('user', username=username))
        current_user.unfollow(user)
        db.session.commit()
        flash('You have unfollowed {}!'.format(username))
        return redirect(url_for('user', username=username))
    else:
        return redirect(url_for('index'))
Ejemplo n.º 7
0
def follow(user_id):
    form = FollowForm()
    
    if form.validate_on_submit():
        follower_id = form.follower_id.data
        
        follow = Follow(user_id, follower_id)
        
        try:
            db.session.add(follow)
            db.session.commit()
            response = {'message': 'You are now following that user.'}, 200
        except:
            response = {'errors': ['You are already following that user.']}, 400
    else:
        response = {'errors': form_errors(form)}, 400
        
    return jsonify(response[0]), response[1]
Ejemplo n.º 8
0
def following_new(userid):
    follow_form = FollowForm()
    if follow_form.validate_on_submit():
        add_following(UserInfo.get_current_user_userid(), userid)
        return redirect(url_for("user_page", userid=userid))
    return render_not_following_user_page(userid)