aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-12 12:12:52 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-12 12:12:52 +0200
commita019e8901b30526b9d7a5443c9355fe87ce620bf (patch)
tree3ad3128de9116c7e9ed9a891529c2f6f2e8af8ec /pyaggr3g470r
parentBetter use of the decorator 'feed_access_required'. (diff)
downloadnewspipe-a019e8901b30526b9d7a5443c9355fe87ce620bf.tar.gz
newspipe-a019e8901b30526b9d7a5443c9355fe87ce620bf.tar.bz2
newspipe-a019e8901b30526b9d7a5443c9355fe87ce620bf.zip
New ForeignKey between Article and User.
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/feedgetter.py5
-rw-r--r--pyaggr3g470r/models.py1
-rw-r--r--pyaggr3g470r/views.py7
3 files changed, 7 insertions, 6 deletions
diff --git a/pyaggr3g470r/feedgetter.py b/pyaggr3g470r/feedgetter.py
index c503d17c..8cf71255 100644
--- a/pyaggr3g470r/feedgetter.py
+++ b/pyaggr3g470r/feedgetter.py
@@ -177,8 +177,9 @@ class FeedGetter(object):
post_date = datetime(*article.updated_parsed[:6])
# save the article
- article = Article(link=nice_url, title=article_title,
- content=description, readed=False, like=False, date=post_date)
+ article = Article(link=nice_url, title=article_title, \
+ content=description, readed=False, like=False, date=post_date, \
+ user_id=self.user.id, feed_id=feed.id)
articles.append(article)
# add the article to the Whoosh index
diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py
index da9c2e25..a21cfbfb 100644
--- a/pyaggr3g470r/models.py
+++ b/pyaggr3g470r/models.py
@@ -118,6 +118,7 @@ class Article(db.Model):
date = db.Column(db.DateTime(), default=datetime.now)
retrieved_date = db.Column(db.DateTime(), default=datetime.now)
+ user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
feed_id = db.Column(db.Integer, db.ForeignKey('feed.id'))
def __repr__(self):
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index 4f6a452c..d7263cdd 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -166,8 +166,8 @@ def home():
The home page lists most recent articles of all feeds.
"""
user = User.query.filter(User.email == g.user.email).first()
- #return render_template('home.html', user=user, head_title="nb unread")
- return render_template('home.html', user=user)
+ unread_articles = len(Article.query.filter(Article.user_id == g.user.id, Article.readed == False).all())
+ return render_template('home.html', user=user, head_title=unread_articles)
@app.route('/fetch/', methods=['GET'])
@app.route('/fetch/<feed_id>', methods=['GET'])
@@ -205,12 +205,11 @@ def feeds():
def feed(feed_id=None):
"""
Presents detailed information about a feed.
- The administrator of the platform is able to access to this view for every users.
"""
feed = Feed.query.filter(Feed.id == feed_id).first()
word_size = 6
articles = feed.articles.all()
- nb_articles = len(articles)
+ nb_articles = len(Article.query.filter(Article.user_id == g.user.id).all())
top_words = utils.top_words(articles, n=50, size=int(word_size))
tag_cloud = utils.tag_cloud(top_words)
bgstack15