def profile_page_followed(username): user = User.get_or_none(User.username == username) if user.is_public: # if public # will accept all followers following = Following(followed=user.id, follower=current_user.id, is_approved=True) if following.save(): flash("followed succesful") return redirect( url_for('users.profile_page', username=user.username)) # url_for()/render_template() 1) When using redirect(url_for()), it will rerun the function so you generally do not need to pass in any values else: # to handle errors is_following = Following.get_or_none( (Following.followed_id == user.id) & (Following.follower_id == current_user.id) & (Following.is_approved == True)) is_waiting_to_approve = Following.get_or_none( (Following.followed_id == user.id) & (Following.follower_id == current_user.id) & (Following.is_approved == False)) return render_template("users/profile_page.html", errors=following.errors, user=user, is_following=is_following, is_waiting_to_approve=is_waiting_to_approve) # url_for()/render_template() 2) When using render_template(), it will render the html directly without running the function so you need to pass in all the variables required to properly run the html else: # if private # will make an instance but will need to be approved following = Following(followed=user.id, follower=current_user.id, is_approved=False) following.save() return redirect(url_for('users.profile_page', username=user.username))
def follow(id): idol_id = id print(f"idol id : {idol_id}") follower_id = current_user.id print(f"follower id : {follower_id}") following_record = Following(idol = int(idol_id), follower = follower_id) following_record.save() print("successfully created a record") print(User.get(User.id == idol_id).name) return redirect(url_for('users.show', username = User.get(User.id == idol_id).name))
def follow(id): # idol_id = request.form.get('profile_user_id') idol_id = id print(f"idol id : {idol_id}") follower_id = current_user.id print(f"follower id : {follower_id}") following_record = Following(idol=int(idol_id), follower=follower_id) following_record.save() # Following.create(idol = idol_id, follower = follower_id, approved = False) print("successfully created a record") print(User.get(User.id == idol_id).name) return redirect( url_for('users.show', username=User.get( User.id == idol_id).name)) #user stays at idol's profile page
def create(idol_id): idol = User.get_or_none(User.id == idol_id) if not idol: flash('No user found with this id') return redirect(url_for('sessions.index')) # modify this to show homepage HOME in sessions new_follow = Following(fan_id=current_user.id, idol_id=idol.id) if not new_follow.save(): flash('Error in following this user', 'warning') return redirect(url_for('users.show', username=idol.username)) else: flash(f'You are now following {idol.username}') return redirect(url_for('users.show', username=idol.username)) flash('Following request has sent ! Please wait for approval.')
def follow(user_id): follow = Following(user_id=user_id, follower_id=current_user.id) follow.save() flash("Request sent for approval") user_prof = User.get_or_none(User.id == user_id) return redirect(url_for("users.show", username=user_prof.username))