Exemplo n.º 1
0
def follow_user():

    follower_username = request.form['follower_username']
    idol_username = request.form['idol_username']

    # Get ID and add to DB

    follower_id = User.get_or_none(User.username == follower_username)
    idol_id = User.get_or_none(User.username == idol_username)

    # If user profile = Public, then add follower and approve
    if idol_id.private == False:
        add_follower = Relationship(follower_id=follower_id,
                                    idol_id=idol_id,
                                    approve=True)
        flash(f'You have followed {idol_username}')
    # If user profile = Private, then add follower but don't approve
    elif idol_id.private == True:
        add_follower = Relationship(follower_id=follower_id,
                                    idol_id=idol_id,
                                    approve=False)
        flash(f'A friend request has been sent to {idol_username}')

    add_follower.save()

    return render_template('home.html')
Exemplo n.º 2
0
def follow(id):
    user = User.select().where(User.id == id).get()

    fan_id = current_user.id
    idol_id = request.form.get('idol_id')
    idol = User.get_by_id(idol_id)

    follower = Relationship(fan=fan_id, idol=idol_id)
    follower.save()

    flash("Successfully followed", 'success')
    return render_template('users/profile.html', user=user)
Exemplo n.º 3
0
def new(following_id):
    follower = User.get_by_id(current_user.id)
    following = User.get_by_id(following_id)

    if following.is_public:
        r = Relationship(follower=follower,
                         following=following,
                         is_approved=True)
    else:
        r = Relationship(follower=follower,
                         following=following,
                         is_approved=False)

    if r.save():
        if following.is_public:
            flash(f"You are now following {following.name}.")
            return redirect(url_for('users.show', username=following.username))
        else:
            flash(f"A follow request has been sent to {following.name}.")
            rq_job = app.task_queue.enqueue(
                'tasks.' + 'send_follow_request_email', following, follower,
                url_for('relationships.index'))
            task = Task(redis_job_id=rq_job.get_id(),
                        name='send_follow_request_email',
                        description='Send user a follow request email.',
                        relationship=r)
            task.save()
            return redirect(url_for('users.show', username=following.username))
    else:
        return render_template(
            'users/show.html',
            user=following,
            photos=Image.select().where(Image.user_id == following.id),
            errors=r.errors)
def create():
    fan_id = current_user.id
    idol_id = request.form.get('idol_id')
    idol = User.get_by_id(idol_id)

    #Check if fan has previously requested to follow this idol.
    follower = Relationship.get_or_none(Relationship.idol == idol_id,
                                        Relationship.fan == fan_id)

    #if they have, flash a message letting them know they have submitteed a request and redirect them to user proifle. Otherwise create a database entry.
    if follower:
        flash(
            f" You've already submitted a follow request to {idol.username} ")
        return redirect(url_for('users.show', username=idol.username))
    else:
        follower = Relationship(fan=fan_id, idol=idol_id)

    if follower.save():
        flash(f"You have submitted a request to follow {idol.username}")
        status = approval_email(fan=current_user, idol=idol)
        print(f'Email request sent:{status}')
        return redirect(url_for('users.show', username=idol.username))

    else:
        flash(f"Something went wrong")
Exemplo n.º 5
0
def create(id):
    idol = User.get_by_id(id)
    if idol.private == True:
        relationship = Relationship(fan=current_user.id,
                                    idol=idol.id,
                                    approved=False)
        if relationship.save():
            flash(
                f"Request is sent to {idol.username}. Please wait for approval.",
                "primary")
            return redirect(url_for('users.show', username=idol.username))
    else:
        relationship = Relationship(fan=current_user.id,
                                    idol=idol.id,
                                    approved=True)
        if relationship.save():
            flash(f"Successfully followed {idol.username}.", "primary")
            return redirect(url_for('users.show', username=idol.username))
 def follow(self, target_user):
     from models.relationship import Relationship
     if target_user.private:
         new_r = Relationship(following_id=self.id,
                              followed_id=target_user.id,
                              pending=True)
     else:
         new_r = Relationship(following_id=self.id,
                              followed_id=target_user.id,
                              pending=False)
     return new_r.save()
def follow(idol_id):
    if current_user.is_authenticated:
        fan = User.get_or_none(User.id == current_user.id)
        idol = User.get_or_none(User.id == idol_id)
        if fan and idol:
            relationship = Relationship(fan=fan, idol=idol)
            if not relationship.is_exist():
                if idol.private:
                    # send_email(f"{fan.username} has followed you on nextagram! Approve follow request to allow profile view.")
                    pass
                else:
                    relationship.status = "approve"
                if relationship.save():
                    flash('Follow profile successful', 'alert alert-success')
                    return redirect(
                        url_for('users.show', id_or_username=idol.username))
            else:
                flash('Profile has been followed', 'alert alert-danger')
        else:
            flash('Follow profile failed', 'alert alert-danger')
        return redirect(url_for('users.show', id_or_username=idol.username))
    else:
        flash('Log in required', 'alert alert-danger')
        return redirect(url_for('home'))