Beispiel #1
0
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))
Beispiel #2
0
def profile_page(username):
    user = User.get_or_none(User.username == username)
    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))
    if user:
        return render_template("users/profile_page.html",
                               user=user,
                               is_following=is_following,
                               is_waiting_to_approve=is_waiting_to_approve)
    else:
        return render_template("404.html")
Beispiel #3
0
def delete(idol_id):
    follow = Following.get_or_none(
        Following.idol_id == idol.id) and (Following.fan_id == current_user.id)

    if follow.delete_instance():
        flash(f'You have unfollowed {follow.idol.username}')
        return redirect(url_for('users.show', username=follow.idol.username))
Beispiel #4
0
def accept_follower_request():
    follower_id = request.form.get("follower_id")
    followed_id = request.form.get("followed_id")
    following_instance = Following.get_or_none(
        (Following.followed == followed_id) &
        (Following.follower == follower_id))  # gets the instance
    # edits the is_approved from False to True
    following_instance.is_approved = True
    following_instance.save()
    return redirect(
        url_for('users.profile_page', username=current_user.username))
Beispiel #5
0
def decline_request(id):
#   following = Following.get_or_none(Following.id == id)
    user = User.get_or_none(id=id)
    following = Following.get_or_none(Following.id == id)
    fan_name = following.fan.user_name
    following = Following.delete().where(Following.id == id)
    if following.execute():
        flash(f"You have declined {fan_name}'s request to follow you.", "info")
        return redirect(url_for('users.request', id=current_user.id, user=user, following=following))
    else:
        flash("Something went wrong. Please try again.")
        return redirect(url_for('users.request', id=current_user.id, user=user, following=following))
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 destroy(id):
    user = User.get_or_none(User.id == id)
    f = Following.get_or_none((Following.user_id==id) & (Following.follower_id==current_user.id))
    f.delete_instance()
    return redirect(url_for('users.show', username = user.username))
 def is_following(self, user):
     from models.following import Following
     return True if Following.get_or_none((Following.idol_id == user.id) and (Following.fan_id == self.id)) else False
Beispiel #9
0
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)