commit 0fbd75ec7e3edbeb4be45993aecc3b400176d3a5
parent 4f88568de443e6e0d1bb64982f0e980a96cfe396
Author: parazyd <parazyd@dyne.org>
Date: Wed, 23 Jan 2019 00:33:35 +0100
Add a route for viewing the users we are following.
Diffstat:
4 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/diaspora.py b/diaspora.py
@@ -36,7 +36,7 @@ from utils import (get_story, makenav, randomstring, getcountryname,
validate_user, get_multiple_users, get_messages,
get_latest_messages, send_message, delete_user,
get_recent_stories, follow_user, unfollow_user,
- is_following)
+ is_following, get_following)
app = Flask(__name__)
@@ -195,6 +195,9 @@ def follow():
elif request.form.get('Act') == 'unfollow':
unfollow_user(current_user.id, request.form.get('Id'))
+ if request.form.get('From') == '/following':
+ return redirect('/following')
+
return redirect('/profile?id=%s' % request.form.get('Id'))
@@ -362,6 +365,21 @@ def profile():
return render_template('fail.html', msg='No such profile.')
+@app.route('/following')
+@login_required
+def following():
+ """
+ Route for listing the users a user is following.
+ """
+ fol = []
+ for i in get_following(current_user.username):
+ j = find_user_by_email(i)
+ if j:
+ fol .append((j['id'], j['name']))
+
+ return render_template('following.html', following=fol)
+
+
@app.route('/dashboard')
@login_required
def dashboard():
diff --git a/templates/following.html b/templates/following.html
@@ -0,0 +1,36 @@
+{% include 'header.html' %}
+
+ <title>Following | Diaspora Diaries</title>
+
+{% include 'nav.html' %}
+
+ <main role="main" class="container cover">
+
+ <h1 class="cover-heading">Users you are following</h1>
+ <hr>
+
+ <div class="container-fluid">
+ {% if following %}
+ {% for i in following %}
+ <div class="row">
+ <div class="col">
+ <form action="/follow" method="POST" id="followform_{{ i[0] }}">
+ <input type="hidden" name="Id" value="{{ i[0] }}">
+ <input type="hidden" name="Act" value="unfollow">
+ <input type="hidden" name="From" value="/following">
+ <h2><a href="/profile?id={{ i[0]}}">{{ i[1] }}</a></h2>
+ </div>
+ <div class="col">
+ <input type="submit" class="btn btn-primary" value="Following" title="Click to unfollow">
+ </form>
+ </div>
+ </div>
+ <hr>
+ {% endfor %}
+ {% else %}
+ <p>You aren't following anyone.</p>
+ {% endif %}
+ </div>
+ </main>
+
+{% include 'footer.html' %}
diff --git a/templates/nav.html b/templates/nav.html
@@ -52,6 +52,9 @@
</li>
{% endif %}
<li class="nav-item">
+ <a class="nav-link {% if request.endpoint == 'following' %}active{% endif %}" href="/following">Following</a>
+ </li>
+ <li class="nav-item">
<a class="nav-link {% if request.endpoint == 'profile' %}active{% endif %}" href="/profile?id={{ current_user.id }}">Profile</a>
</li>
<li class="nav-item">
diff --git a/utils.py b/utils.py
@@ -405,6 +405,9 @@ def unfollow_user(id_us, id_them):
def is_following(email_ours, email_them):
+ """
+ Function to check if we're following a specific user.
+ """
with open(join('follows', email_ours)) as follow_file:
ourdata = json.load(follow_file)
@@ -414,6 +417,14 @@ def is_following(email_ours, email_them):
return False
+def get_following(email):
+ """
+ Gets all the users we are following.
+ """
+ with open(join('follows', email)) as follow_file:
+ return json.load(follow_file)
+
+
def delete_user(user_id):
"""
Deletes a user and their messages directory.