def show(username): user = User.get_or_none(User.username == username) followercount = Following.select().where(Following.user_id == user.id, Following.approved).count() followingcount = Following.select().where(Following.follower_id == user.id, Following.approved).count() is_following = False if current_user.is_authenticated: find_follow = Following.get_or_none((Following.user_id == user.id) & ( Following.follower_id == current_user.id) & (Following.approved)) if find_follow != None: is_following = True # if planning to show follower and following list, should change the above query and pass the results into template as lists # whiteboard note: User.select().join(Following, on=(User.id == Following.follower_id).where(Following.user_id==user.id)) return render_template('users/profile.html', user=user, is_following=is_following, followingcount=followingcount, followercount=followercount)
def accept_request(id): user = User.get_or_none(id=id) followings = Following.update(is_approved = True).where(Following.id == id) following = Following.get_by_id(id) fan_name = following.fan.user_name if followings.execute(): flash(f"You have approved {fan_name}", "success") followings = Following.select().where((Following.idol_id == current_user.id) & (Following.is_approved == False)) return redirect(url_for('users.request', id=current_user.id, user=user, followings=followings)) else: # Can't think of a scenario where this may happen but handle the scenario anyway. flash(f"Could not accept. Please try again.", "danger")
def show(username): follow = Following.select().where( Following.user_id == current_user.id).where( Following.approved == False) print( "************************************************************************************" ) for f in follow: print(f.follower_id) print( "************************************************************************************" ) check = User.get_or_none(User.username == username) if check is not None: return render_template("users/profile.html", username=username, picture=check.profile_pic, user=check, current_user=current_user, follow=follow) else: flash("User does not exist.") return redirect(url_for("home"))
def followings(self): from models.following import Following return [ x.idol for x in Following.select().where(Following.fan_id == self.id) ]
def show(id): user = User.get_or_none(id=id) followers = Following.select().where((id==Following.idol_id) & (Following.is_approved == True)) following = Following.select().where((id==Following.fan_id) & (Following.is_approved == True)) current_user_follow = Following.get_or_none((current_user.id == Following.fan_id) & (id == Following.idol_id)) return render_template('images/userprofile.html', user=user, Image=Image, followers=followers, following=following, current_user_follow=current_user_follow)
def request(id): user = User.get_or_none(id=id) if current_user == user: followings = Following.select().where((Following.idol_id == current_user.id) & (Following.is_approved == False)) return render_template('request.html', user=user, followings=followings)