aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-30 10:58:54 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-30 10:58:54 +0200
commitf03a9825fc047e2371356d7b1784c65835756c55 (patch)
treedefe05beca3b794e1988787586a584e131689b4c
parentAdded comments. (diff)
downloadnewspipe-f03a9825fc047e2371356d7b1784c65835756c55.tar.gz
newspipe-f03a9825fc047e2371356d7b1784c65835756c55.tar.bz2
newspipe-f03a9825fc047e2371356d7b1784c65835756c55.zip
Link between next and previous articles.
-rw-r--r--pyaggr3g470r/models.py14
-rw-r--r--pyaggr3g470r/templates/article.html10
-rw-r--r--pyaggr3g470r/views.py12
3 files changed, 34 insertions, 2 deletions
diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py
index f4aa0521..6c6df180 100644
--- a/pyaggr3g470r/models.py
+++ b/pyaggr3g470r/models.py
@@ -28,7 +28,7 @@ __license__ = "GPLv3"
import json
from datetime import datetime
-from sqlalchemy import desc
+from sqlalchemy import asc, desc
from werkzeug import generate_password_hash, check_password_hash
from flask.ext.login import UserMixin
@@ -123,6 +123,18 @@ class Article(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
feed_id = db.Column(db.Integer, db.ForeignKey('feed.id'))
+ def previous_article(self):
+ """
+ Returns the previous article (older).
+ """
+ return Article.query.filter(Article.date < self.date, Article.feed_id == self.feed_id).order_by(desc("Article.date")).first()
+
+ def next_article(self):
+ """
+ Returns the next article (newer).
+ """
+ return Article.query.filter(Article.date > self.date, Article.feed_id == self.feed_id).order_by(asc("Article.date")).first()
+
def __repr__(self):
return json.dumps({
"title": self.title,
diff --git a/pyaggr3g470r/templates/article.html b/pyaggr3g470r/templates/article.html
index 7cbee48a..1ca1ce49 100644
--- a/pyaggr3g470r/templates/article.html
+++ b/pyaggr3g470r/templates/article.html
@@ -20,6 +20,16 @@
{{ article.content|safe }}
</div>
<div class="jumbotron">
+ <div class="row">
+ <div class="col-md-6">
+ Next post: <a href="/article/{{ next_article.id }}">{{ next_article.title }}</a>
+ </div>
+ <div class="col-md-6 text-right">
+ Previous post: <a href="/article/{{ previous_article.id }}">{{ previous_article.title }}</a>
+ </div>
+ </div>
+ </div>
+ <div class="jumbotron">
<a href="https://api.pinboard.in/v1/posts/add?url={{ article.link }}&description={{ article.title }}" rel="noreferrer" target="_blank">
<img src="/static/img/pinboard.png" title="Share on Pinboard" />
</a>
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index 491d44a2..6d2a3b99 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -243,7 +243,17 @@ def article(article_id=None):
if not article.readed:
article.readed = True
db.session.commit()
- return render_template('article.html', head_title=utils.clear_string(article.title), article=article)
+
+ previous_article = article.previous_article()
+ if previous_article is None:
+ previous_article = article.source.articles[0]
+ next_article = article.next_article()
+ if next_article is None:
+ next_article = article.source.articles[-1]
+
+ return render_template('article.html', head_title=utils.clear_string(article.title),
+ article=article,
+ previous_article=previous_article, next_article=next_article)
flash("This article do not exist.", 'warning')
return redirect(redirect_url())
bgstack15