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)
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)
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()}
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'))
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'))
def render_not_following_user_page(userid): follow_form = FollowForm() return render_over_base_template("user_page.html", userid=userid, current_user_page=False, is_following=False, follow_form=follow_form)
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]
def user(username): form = FollowForm() user = User.query.filter_by(username=username).first_or_404() page = request.args.get('page', 1, type=int) posts = user.posts.order_by(Post.timestamp.desc()).paginate( page, app.config['POSTS_PER_PAGE'], False) prev_url = url_for('index', username=user.username, page=posts.prev_num) if posts.has_prev else None next_url = url_for('index', username=user.username, page=posts.next_num) if posts.has_next else None return render_template('user.html', user=user, posts=posts.items, next_url=next_url, prev_url=prev_url, form=form)
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)