def approve(user_id): follower = User.get_by_id(user_id) r = Relationship.get(Relationship.follower_id == user_id, Relationship.following_id == current_user.id) r.is_approved = True if r.save(): flash(f"You have approved {follower.name}'s follow request.") return redirect(url_for('users.show', username=follower.username)) else: return render_template( 'users/show.html', user=current_user, photos=Image.select().where(Image.user_id == current_user.id), errors=r.errors)
def reject(user_id): follower = User.get_by_id(user_id) r = Relationship.get(Relationship.follower_id == user_id, Relationship.following_id == current_user.id) try: if Task.get(Task.relationship_id == r.id): t = Task.get(Task.relationship_id == r.id) t.delete_instance() except: pass r.delete_instance() flash(f"You have rejected {follower.name}'s follow request.") return redirect(url_for('users.show', username=current_user.username))
def destroy(following_id): following = User.get_by_id(following_id) r = Relationship.get(Relationship.follower_id == current_user.id, Relationship.following_id == following_id) try: if Task.get(Task.relationship_id == r.id): t = Task.get(Task.relationship_id == r.id) t.delete_instance() except: pass r.delete_instance() flash(f"You have unfollowed {following.name}.") return render_template( 'users/show.html', user=following, photos=Image.select().where(Image.user_id == following.id))