diasporadiaries

a platform for writing stories with personal accounts and messages
git clone git://parazyd.org/diasporadiaries.git
Log | Files | Refs | Submodules | README | LICENSE

commit 21cbe8177396649744d1cb3d6fb268d82577cbf4
parent 30dae4aaa5008bde9c307431bfe0d5cb9d0e55db
Author: parazyd <parazyd@dyne.org>
Date:   Tue, 22 Jan 2019 01:08:02 +0100

List recent stories on index.

Diffstat:
Mdiaspora.py | 6++++--
Dstatic/css/.diaspora.css.swp | 0
Mtemplates/index.html | 5+++++
Mutils.py | 19++++++++++++++++++-
4 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/diaspora.py b/diaspora.py @@ -33,7 +33,8 @@ from utils import (get_story, makenav, randomstring, getcountryname, get_multiple_stories, get_multiple_stories_filtered, make_profile, find_user_by_id, find_user_by_email, validate_user, get_multiple_users, get_messages, - get_latest_messages, send_message, delete_user) + get_latest_messages, send_message, delete_user, + get_recent_stories) app = Flask(__name__) @@ -422,7 +423,8 @@ def main(): """ Main route, the homepage. """ - return render_template('index.html') + stories = get_recent_stories() + return render_template('index.html', stories=stories, profiles={}) if __name__ == '__main__': diff --git a/static/css/.diaspora.css.swp b/static/css/.diaspora.css.swp Binary files differ. diff --git a/templates/index.html b/templates/index.html @@ -53,6 +53,11 @@ useful.</p> </div> + + <hr> + <h4>Recent stories</h4> + {% include 'gallery.html' %} + </main> {% include 'footer.html' %} diff --git a/utils.py b/utils.py @@ -28,7 +28,8 @@ from time import gmtime, strftime, time from bcrypt import gensalt, hashpw from flask import Markup -from db import sql_select_col_where, sql_insert, sql_delete_row_where +from db import (sql_select_col_where, sql_insert, sql_delete_row_where, + sql_select_col) COUNTRYMAP = {} @@ -89,6 +90,22 @@ def get_story(story_id): return fill_story(res[0]) +def get_recent_stories(): + """ + Returns a list of the 3 most recent stories in the database. + """ + rows = sql_select_col('*') + if len(rows) > 3: + rows = rows[-3:] + + stories = [] + for i in rows: + j = fill_story(i) + stories.append(j) + + return stories[::-1] + + def get_multiple_stories(col, val, reverse=True): """ Returns a list of stories where col=val.