commit e6df7f30af8a97a3cff1db7e10bde7e5af8e24b3
parent ae2e0dec55f8372ad357e48d0ebfbf5b284f6379
Author: parazyd <parazyd@dyne.org>
Date: Wed, 16 Jan 2019 23:13:51 +0100
Add support for basic profiles.
Diffstat:
4 files changed, 104 insertions(+), 4 deletions(-)
diff --git a/diaspora.py b/diaspora.py
@@ -136,14 +136,38 @@ def country():
('embark', ccfrom))
stories = get_multiple_stories('disembark', cc)
- clist = []
- for i in stories:
- clist.append((i['embark'], i['embarkname']))
+
+ clist = [(i['embark'], i['embarkname']) for i in stories]
clist = list(set(clist))
+ profiles = {}
+ for i in stories:
+ if i['email']:
+ uid = sql_select_col_where('id', 'email', i['email'],
+ table='users')
+ profiles['email'] = uid[0][0]
+
return render_template('country.html', country=getcountryname(cc),
cc=cc, stories=stories, filtered_stories=filtered,
- clist=clist)
+ clist=clist, profiles=profiles)
+
+
+@app.route('/profile')
+def profile():
+ """
+ Route for viewing stories by a specific person. The persons
+ are differed by their emails.
+ """
+ uid = request.args.get('id')
+ if uid:
+ email = sql_select_col_where('email', 'id', uid, table='users')
+ if email:
+ email = email[0][0]
+ stories = get_multiple_stories('email', email)
+ name = stories[0]['name']
+ return render_template('profile.html', stories=stories, name=name)
+
+ return render_template('fail_profile.html')
@app.route('/dashboard')
diff --git a/templates/country.html b/templates/country.html
@@ -41,7 +41,11 @@
<img style="height: 1em;" src="/static/img/flags/{{ i['embark'] }}.png" alt="{{ i['embarkname'] }}" title="{{ i['embarkname' ]}}"><span class="fa fa-anchor"></span><img style="height: 1em;" src="/static/img/flags/{{ i['disembark'] }}.png" alt="{{ i['disembarkname'] }}" title="{{ i['disembarkname'] }}">
<small class="text-muted">
+ {% if i['email'] %}
+ <a href="/profile?id={{ profiles['email'] }}">{{ i['name'] }}</a><br>
+ {% else %}
{{ i['name'] }}<br>
+ {% endif %}
{{ i['date'] }}<br>
{{ i['time'] }}
</small>
diff --git a/templates/fail_profile.html b/templates/fail_profile.html
@@ -0,0 +1,17 @@
+{% include 'header.html' %}
+
+ <title>Error | Diaspora Diaries</title>
+
+{% include 'nav.html' %}
+
+ <main role="main" class="container cover">
+
+ <h1 class="cover-heading">Error!</h1>
+
+ <p class="lead">No such profile.</p>
+
+ <p class="lead">You can return to the <a href="/">homepage</a> now.</p>
+
+ </main>
+
+{% include 'footer.html' %}
diff --git a/templates/profile.html b/templates/profile.html
@@ -0,0 +1,55 @@
+{% include 'header.html' %}
+
+ <title>Diaries by {{ name }}| Diaspora Diaries</title>
+
+{% include 'nav.html' %}
+
+ <main role="main" class="container cover">
+
+ <h1 class="cover-heading">Diaries by {{ name }}</h1>
+
+
+ <div class="album py-5 bg-light">
+ <div class="container">
+
+ {% for i in stories %}
+ {% if loop.index % 3 == 1 %}
+ <div class="row">
+ {% endif %}
+
+ <div class="col-md-4">
+ <div class="card-body">
+ <p class="card-text">
+ {{ i['abstract'] }}
+ </p>
+
+ <div class="d-flex justify-content-between align-items-center">
+ <div class="btn-group">
+ <a href="/view?id={{ i['id'] }}" class="btn btn-sm btn-outline-secondary">Read</a>
+ </div>
+
+ <img style="height: 1em;" src="/static/img/flags/{{ i['embark'] }}.png" alt="{{ i['embarkname'] }}" title="{{ i['embarkname' ]}}"><span class="fa fa-anchor"></span><img style="height: 1em;" src="/static/img/flags/{{ i['disembark'] }}.png" alt="{{ i['disembarkname'] }}" title="{{ i['disembarkname'] }}">
+
+ <small class="text-muted">
+ {{ i['name'] }}<br>
+ {{ i['date'] }}<br>
+ {{ i['time'] }}
+ </small>
+ </div>
+ </div>
+ </div>
+
+ {% if loop.index % 3 == 0 or loop.last %}
+ </div>
+ {% if not loop.last %}
+ <hr style="width: 100%; height: 2px;">
+ {% endif %}
+ {% endif %}
+
+ {% endfor %}
+ </div>
+ </div>
+
+ </main>
+
+{% include 'footer.html' %}