def unfollow(username): user = User.query.filter_by(username=username).first() if user is None: flash('Invalid user.') return redirect(url_for('.index')) if not current_user.is_following(user): flash('You are not following this user.') return redirect(url_for('.user', username=username)) current_user.unfollow(user) flash('You are not following %s anymore.' % username) return redirect(url_for('.user', username=username))
def unfollow(username): 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!') return redirect(url_for('user', username=username)) current_user.unfollow(user) db.session.commit() flash('You are not following {}.'.format(username)) return redirect(url_for('users.user', username=username))
def unfollow(): username = request.form.get('username') if username and username != current_user.username: user = User.query.filter_by(username=username).first() if user: try: current_user.unfollow(user) db.session.commit() return jsonify(username=user.username) except Exception as e: # todo -> add logging db.session.rollback() return jsonify(message='error while unfollowing'), 500 else: return jsonify(message='user not found'), 404 else: return jsonify(message='Bad parameter'), 400