aboutsummaryrefslogtreecommitdiffstats
path: root/famille.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2012-11-08 23:16:46 +0100
committerThibaut Horel <thibaut.horel@gmail.com>2012-11-08 23:16:46 +0100
commit18afe971d1e4db12c0e0d7d68937775d4f35d6a6 (patch)
treea7589e4f6cccc40e2490b86ec071a34ba3752dec /famille.py
parentea39366c947bcc2e9234a50d79e13e472abd9736 (diff)
downloadfamille-flask-18afe971d1e4db12c0e0d7d68937775d4f35d6a6.tar.gz
Add info boxes on home page.
The choice of BeautifulSoup to shorten comments is open to discussion. It is a bit overkill.
Diffstat (limited to 'famille.py')
-rw-r--r--famille.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/famille.py b/famille.py
index 88d6459..fece79c 100644
--- a/famille.py
+++ b/famille.py
@@ -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']