aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--famille.py18
-rw-r--r--templates/news/list.html25
2 files changed, 40 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']
diff --git a/templates/news/list.html b/templates/news/list.html
index e95abe8..61625c1 100644
--- a/templates/news/list.html
+++ b/templates/news/list.html
@@ -4,6 +4,31 @@
<div class="second_menu">
<a href="/news/add/">Ajouter une actualité</a>
</div>
+<div class="quickview">
+<h2>Dernières visites</h2>
+
+<table>
+ {% for user in users %}
+ <tr>
+ <td><a href="{{url_for('view_user', user_id=user.id)}}">{{user.user_name}}</a></td>
+ <td>{{user.last_seen|format_date}}</td>
+ </tr>
+ {% endfor %}
+</table>
+
+<h2>Derniers commentaires</h2>
+<ul>
+ {% for comment in comments %}
+ <li><a href="{{url_for('view_user', user_id=comment.user_id)}}">{{comment.username}}</a>
+ {{comment.date|format_date}}<br/>
+ {{comment.content_cache|shortify|safe}} <a href="{{url_for('show_news', news_id=comment.news_id)}}#comments">[…]</a>
+ </li>
+ {% else %}
+ Pas de commentaires."
+ {% endfor %}
+</ul>
+</div>
+
<div class="news">
{% for news in news %}
<div class="news_head">