Ejemplo n.º 1
0
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))
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
 def follow(self, idol_id):
     idol = User.get(id=idol_id)
     Following.create(fan_id=self.id, idol_id=idol_id)
     if not idol.is_private:
         Following.update(is_approved=True).where(
             Following.fan_id == self.id,
             Following.idol_id == idol_id).execute()
         flash(f'Successfully followed {idol.username}', 'success')
     else:
         flash(f'follow request sent to {idol.username}. Pending approval',
               'info')
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
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")
Ejemplo n.º 6
0
def follow(id):
    user = User.get_or_none(id=id)
    fan_id = current_user.id
    idol_id = user.id
    if user.profile_privacy:
        Following.create(fan_id=fan_id, idol_id=idol_id, is_approved=False)
        flash(f"You have sent a request to follow { user.user_name }. Please wait for their approval.", "success")
        return redirect(url_for('users.show', id=user.id))
    else:
        Following.create(fan_id=fan_id, idol_id=idol_id, is_approved=True)
        flash(f"You are now following { user.user_name }", "success")
        return redirect(url_for('users.show', id=user.id))
Ejemplo n.º 7
0
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
Ejemplo n.º 8
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))
Ejemplo n.º 9
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")
Ejemplo n.º 10
0
def approve(id):
    approval_user = Following.get((Following.follower_id == id)
                                  & (Following.idol_id == current_user.id))
    approval_user.approved = True
    approval_user.save()
    return redirect(
        url_for('users.show',
                username=current_user.name))  #user stays at his profile page
Ejemplo n.º 11
0
def unfollow(id):
    unfollow = Following.delete().where(Following.fan_id==current_user.id, Following.idol_id==id)
    user = User.get_by_id(id)
    if unfollow.execute():
        flash(f"You have unfollowed { user.user_name }", "info")
        return redirect(url_for('users.show', id=id))
    else:
        flash("Could not unfollow. Please try again.", "danger")
        return redirect(url_for('users.show', id=id))
Ejemplo n.º 12
0
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.')
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
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))
Ejemplo n.º 15
0
def create(id):
    user = User.get_or_none(User.id == id)
    follow = Following.get_or_create(
        user_id=id,
        follower_id=current_user.id
        )
    follow[0].approved = True
    follow[0].save()
    # follow is a tuple of (Following object, boolean if a new Following object is created)
    # More info here http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.get_or_create 
    return redirect(url_for('users.show', username = user.username))
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"))
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
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 accept(user_id):
    follow = Following.get(Following.id == user_id)
    follow.approved = True
    follow.save()
    return redirect(url_for("users.show", username=current_user.username))
Ejemplo n.º 20
0
 def approve(self, fan_id):
     Following.update(is_approved=True).where(
         Following.fan_id == fan_id,
         Following.idol_id == self.id).execute()
Ejemplo n.º 21
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)
Ejemplo n.º 22
0
 def unfollow(self, idol_id):
     Following.delete().where(Following.fan_id == self.id,
                              Following.idol_id == idol_id).execute()
Ejemplo n.º 23
0
 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
Ejemplo n.º 24
0
 def followings(self):
     from models.following import Following
     return [
         x.idol
         for x in Following.select().where(Following.fan_id == self.id)
     ]
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))