Created un/follow buttons
This commit is contained in:
parent
a07df6d023
commit
22c3193f12
3 changed files with 33 additions and 8 deletions
22
Tweeder.py
22
Tweeder.py
|
@ -66,7 +66,7 @@ def profile(name=None):
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
logged_in = accounts.get_display_name(session['username']) if 'username' in session.keys() else False
|
logged_in = accounts.get_display_name(session['username']) if 'username' in session.keys() else False
|
||||||
posts = list(timeline.user_posts_by_username(name))
|
posts = list(timeline.user_posts_by_username(name))
|
||||||
return render_template('profile.html', user=accounts.account_details(name), logged_in=logged_in, posts=posts)
|
return render_template('profile.html', user=accounts.account_details(name), logged_in=logged_in, following=accounts.is_following(logged_in, name), posts=posts)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
|
@ -140,6 +140,26 @@ def reply_to_post(post_id):
|
||||||
timeline.post_status(logged_in, request.form['status'], replyTo=post_id)
|
timeline.post_status(logged_in, request.form['status'], replyTo=post_id)
|
||||||
return redirect(url_for('profile'))
|
return redirect(url_for('profile'))
|
||||||
|
|
||||||
|
@app.route("/follow/<user>", methods=["GET", "POST"])
|
||||||
|
def follow(user):
|
||||||
|
if 'username' not in session.keys(): return redirect(url_for('login'))
|
||||||
|
logged_in = session['username']
|
||||||
|
if request.method == "POST":
|
||||||
|
accounts.follow(logged_in, user)
|
||||||
|
return redirect(str("/profile/" + user))
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@app.route("/unfollow/<user>", methods=["GET", "POST"])
|
||||||
|
def unfollow(user):
|
||||||
|
if 'username' not in session.keys(): return redirect(url_for('login'))
|
||||||
|
logged_in = session['username']
|
||||||
|
if request.method == "POST":
|
||||||
|
accounts.unfollow(logged_in, user)
|
||||||
|
return redirect(str("/profile/" + user))
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
|
@ -12,6 +12,8 @@ def get_display_name(username):
|
||||||
def is_verified(username):
|
def is_verified(username):
|
||||||
return accounts_db.find_one({'username': username})['verified']
|
return accounts_db.find_one({'username': username})['verified']
|
||||||
|
|
||||||
|
def is_following(follower, following):
|
||||||
|
return bool( accounts_db.find_one({'username': following.lower()})['_id'] in accounts_db.find_one({'username': follower.lower()})['following'] )
|
||||||
|
|
||||||
def account_exists(username):
|
def account_exists(username):
|
||||||
return bool(accounts_db.find_one({'username': username}))
|
return bool(accounts_db.find_one({'username': username}))
|
||||||
|
|
|
@ -15,13 +15,16 @@
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-6 col-md-4">
|
<div class="col-xs-6 col-md-4">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h4 class="card-header">{{ user.displayname }}'s profile</h4>
|
<div class="card-header">
|
||||||
<div class="card-body">
|
<h4 style="display: inline">{{ user.displayname }}' Profile</h4>
|
||||||
{% if user.profile.location %} <i class="far fa-fw fa-map-marker"></i> {{ user.profile.location }} <br>{% endif %}
|
{% if following %}<form action="/unfollow/{{ user.displayname }}" method="POST" style="display: inline; float: right;"><input type="submit" value="Unfollow" class="btn btn-outline-danger btn-sm"/></form> {% else %}<form action="/follow/{{ user.displayname }}" method="POST" style="display:inline; float: right;"><input type="submit" value="Follow" class="btn btn-outline-primary btn-sm"/></form>{% endif %}
|
||||||
{% if user.profile.gender %} <i class="far fa-fw fa-transgender-alt"></i> {{ user.profile.gender }} {% endif %}
|
</div>
|
||||||
</div>
|
<div class="card-body">
|
||||||
|
{% if user.profile.location %} <i class="far fa-fw fa-map-marker"></i> {{ user.profile.location }} <br>{% endif %}
|
||||||
|
{% if user.profile.gender %} <i class="far fa-fw fa-transgender-alt"></i> {{ user.profile.gender }} {% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-12 col-sm-6 col-md-8" style="float: right;">
|
<div class="col-xs-12 col-sm-6 col-md-8" style="float: right;">
|
||||||
{% if posts %}
|
{% if posts %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue