diff options
Diffstat (limited to 'famille.py')
| -rw-r--r-- | famille.py | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -8,6 +8,7 @@ import hashlib from docutils import core from docutils.writers.html4css1 import Writer from datetime import datetime +from bs4 import BeautifulSoup def rstify(string): w = Writer() @@ -18,6 +19,11 @@ def rstify(string): app = Flask(__name__) app.config.from_envvar('CONF') +@app.template_filter('shortify') +def shortify(string): + soup = BeautifulSoup(string) + return soup("p")[0].get_text()[:50] + @app.template_filter('format_date') def format_date(datetime_string, format=u"%a %d %b %Y à %Hh%M".encode("utf8")): if not datetime_string: @@ -67,8 +73,13 @@ def login_required(f): def list_news(): news = query_db("SELECT news.*, users.user_name, count(comments.id) as ncomments FROM news " "LEFT JOIN users ON news.user_id = users.id " - "LEFT JOIN comments ON news.id=comments.news_id GROUP BY news.id") - return render_template("news/list.html", news=news) + "LEFT JOIN comments ON news.id=comments.news_id GROUP BY news.id " + "ORDER BY news.date DESC") + comments = query_db("SELECT * from comments LEFT JOIN users " + "ON comments.user_id = users.id ORDER BY date DESC LIMIT 5") + users = query_db("SELECT * from users ORDER BY last_seen DESC") + return render_template("news/list.html", news=news, comments=comments, + users=users) @app.route('/news/add/', methods=['GET', 'POST']) @login_required @@ -95,7 +106,8 @@ def show_news(news_id): if request.method == 'GET': comments = query_db("SELECT * FROM comments LEFT JOIN users " "ON comments.user_id = users.id " - "WHERE comments.news_id = ?", (news_id,)) + "WHERE comments.news_id = ? " + "ORDER BY date DESC", (news_id,)) return render_template("news/show.html", news=news, comments=comments) elif request.method == 'POST': user_id = session['user_id'] |
