def create(idol_id): new_idol = FollowerFollowing(fan_id=current_user.id, idol_id=idol_id) idol_info = User.get_by_id(idol_id) if new_idol.save(): flash(f"You Just followed {idol_info.name}") return redirect(url_for('users.feed')) else: flash("Oops Something went wrong while following") return redirect(url_for('users.feed'))
def accept(fan_id): fan = User.get_or_none(User.id == fan_id) follow = FollowerFollowing(idol_id=current_user.id, fan_id=fan.id) if follow.save(): flash(f"Accepted {fan.username}. They can now see all your posts.") return redirect(url_for('users.profile', id=fan.id)) else: flash("Unsuccessful, guess they're too creepy to accept.") return redirect(url_for('home'))
def create(idol_id): idol = User.get_or_none(User.id == idol_id) follow = FollowerFollowing(fan_id=current_user.id, idol_id=idol.id) if follow.save(): flash(f"Following {idol.username} successful") return redirect(url_for('users.profile', id=idol.id)) else: flash("Follow unsuccessful, guess you shouldn't after all") return redirect(url_for('home'))
def create(idol_id): idol = User.get_or_none(User.id == idol_id) if not idol: flash(f'No user found with this id', 'error') return redirect(url_for('users.index')) new_follow = FollowerFollowing(fan_id=current_user.id, idol_id=idol.id) if not new_follow.save(): flash(f"Unable to save this follow", "error") return redirect(url_for('users.show', username=idol.name)) flash('Follow request sent, please wait for approval') return redirect(url_for('users.show', username=idol.name))
def approve_user(fan_id, idol_id): approve = FollowerFollowing.update( approved=True).where((FollowerFollowing.fan_id == fan_id) & (FollowerFollowing.idol_id == idol_id)) approve.execute() flash(f"You Just Approved Someone {fan_id} {idol_id}") return redirect(url_for('users.show', id=current_user.id))
def delete(idol_id): follow = FollowerFollowing.get_or_none((FollowerFollowing.idol_id == idol_id) and ( FollowerFollowing.fan_id == current_user.id)) flash(f"You have unfollowed {follow.idol.name}") return redirect(url_for('users_show', username=follow.idol.name))
def create(idol_id): idol = User.get_or_none(User.id == idol_id) if not idol: flash("User does not exist") return redirect(url_for('users.index')) f = FollowerFollowing(idol_id=idol.id, fan_id=current_user.id) if f.save(): flash("Successfully followed your idol!") return redirect(request.referrer) else: flash("Go Away!") return redirect(url_for('users.index'))
def delete(idol_id): follow = FollowerFollowing.get_or_none((FollowerFollowing.idols_id == idols_id) and ( FollowerFollowing.fan_id == current_user.id)) if follow.delete_instance(): flash(f'You have unfollowed{follow.idol.username}') return redirect(url_for('users.show_feed', username=follow.idol.username))
def requesting_follower(self): from models.follower_following import FollowerFollowing if self.private == True: requesting_follower = FollowerFollowing.select().where( (FollowerFollowing.idol_id == self.id) & (FollowerFollowing.approved == False)) return len(requesting_follower) else: return 0
def is_following(self, user): from models.follower_following import FollowerFollowing check_following = FollowerFollowing.get_or_none( (FollowerFollowing.fan_id == current_user.id) & (FollowerFollowing.idol_id == user.id)) if check_following == None: return False else: return True
def delete(idol_id): idol = User.get_or_none(User.id == idol_id) unfollow = FollowerFollowing.get_or_none(fan_id=current_user.id, idol_id=idol.id) if unfollow.delete_instance(): flash(f"Unfollowed {idol.username}") return redirect(url_for('home')) else: flash("Unfollow unsuccessful, guess you're forced to be a good person") return redirect(url_for('users.profile', id=idol.id))
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('users.index')) new_follow = FollowerFollowing(fan_id=current_user.id, idol_id=idol.id) if not new_follow.save(): flash('Unable to follow this user!') return redirect(url_for('users.show', username=idol.name)) else: flash(f'You are now following{idol.name}') return redirect(url_for('users.show', username=idol.name)) flash('Follow request sent! Please wait for approval') return redirect(url_for('users.show', username=idol.name))
def delete(id): unfollow = FollowerFollowing.get_or_none( idol_id=id, fan_id=current_user.id) if unfollow.delete_instance(): flash("Bye bye ") return redirect(request.referrer) else: flash("you will be a follower forever") return render_template("users/index.html")
def delete(idol_id): idol = FollowerFollowing.get_or_none( (FollowerFollowing.idol_id == idol_id) & (FollowerFollowing.fan_id == current_user.id)) idol_info = User.get_by_id(idol_id) if idol.delete_instance(): flash(f"You Just Unfollow {idol_info.name}") else: flash("Ops, Something Went Wrong.. ") return redirect(url_for('users.feed'))
def is_approved(self, user): from models.follower_following import FollowerFollowing # user = FollowerFollowing.get_or_none( # FollowerFollowing.idol_id == user.id) # fan = FollowerFollowing.get_or_none( # FollowerFollowing.fan_id == self.id) x = FollowerFollowing.get_or_none( (FollowerFollowing.fan_id == self.id) & (FollowerFollowing.idol_id == user.id)) # return True # return False return True if (x.approved == True) else False
def create(idols_id): idol = User.get_or_none(User.id == idols_id) if not idol: flash('No user found with this id!') return redirect(url_for('users.show_feed')) new_follow = FollowerFollowing( fans_id=current_user.id, idols_id=idol.id ) if not new_follow.save(): flash('Unable to follow this user!') return render_template('followers/new.html', user=idols_id) else: flash(f'You are now following {idol.username}') return redirect(url_for('users.show_feed', username=idol.username)) flash('Follow request send! Please wait for approval!') return redirect(url_for('users.show_feed', username=idol.username))
def review(user_id): user = User.get_or_none(User.id == user_id) # PEEWEEE AND SQL HAVE DIFFERNT COMMNDS. & and and, lookup later requests = FollowerFollowing.select().where( FollowerFollowing.idol_id == current_user.id) # requests = FollowerFollowing.select().where( # (FollowerFollowing.idol_id == current_user.id) & (FollowerFollowing.approved == False)) if current_user.id == user.id: return render_template("follows/requestreview.html", user=user, requests=requests) else: return abort(401)
def approve(fan_id): # ------GET THE INSTANCE AND SET APPROVED TO TRUE --------------- approved_follow = FollowerFollowing.get_or_none( (FollowerFollowing.idol_id == current_user.id) & (FollowerFollowing.fan_id == fan_id)) if not approved_follow: flash(f"No relationship found", "error") return redirect(url_for('follows.review', user_id=current_user.id)) if approved_follow.approved == False: approved_follow.approved = True else: approved_follow.approved = False if not approved_follow.save(): flash(f"Could not approve follower", "error") return redirect(url_for('follows.review', user_id=current_user.id)) else: flash(f"Sucessfully approved follower", "sucess") return redirect(url_for('follows.review', user_id=current_user.id))
def is_following(self, user): from models.follower_following import FollowerFollowing return True if FollowerFollowing.get_or_none((FollowerFollowing.idol_id == user.id) & (FollowerFollowing.fan_id == self.id)) else False
def following(self): from models.follower_following import FollowerFollowing return [ user.fan for user in FollowerFollowing.select().where( FollowerFollowing.idol_id == self.id) ]