aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2014-04-08 07:48:48 +0200
committerCédric Bonhomme <kimble.mandel@gmail.com>2014-04-08 07:48:48 +0200
commitf7fdfe946180db61802cd8c2cf88392ace1d78e4 (patch)
tree0fe1ed5e1bd10407a58d037088154bae781b0d55 /pyaggr3g470r
parentAdded decorator to check if a user has access to a feed. (diff)
downloadnewspipe-f7fdfe946180db61802cd8c2cf88392ace1d78e4.tar.gz
newspipe-f7fdfe946180db61802cd8c2cf88392ace1d78e4.tar.bz2
newspipe-f7fdfe946180db61802cd8c2cf88392ace1d78e4.zip
Management page near to be OK.
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/models.py2
-rw-r--r--pyaggr3g470r/templates/management.html2
-rw-r--r--pyaggr3g470r/views.py18
3 files changed, 12 insertions, 10 deletions
diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py
index 0fd9eb73..caed0ef2 100644
--- a/pyaggr3g470r/models.py
+++ b/pyaggr3g470r/models.py
@@ -116,7 +116,7 @@ class Article(db.Model):
date = db.Column(db.DateTime(), default=datetime.now)
retrieved_date = db.Column(db.DateTime(), default=datetime.now)
- station_id = db.Column(db.Integer, db.ForeignKey('feed.id'))
+ feed_id = db.Column(db.Integer, db.ForeignKey('feed.id'))
def __repr__(self):
return '<Article %r>' % (self.title)
diff --git a/pyaggr3g470r/templates/management.html b/pyaggr3g470r/templates/management.html
index 41dbd4e9..540cb403 100644
--- a/pyaggr3g470r/templates/management.html
+++ b/pyaggr3g470r/templates/management.html
@@ -3,7 +3,7 @@
<div class="container">
<div class="jumbotron">
<h1>Your subscriptions</h1>
- <p>You are subscribed to {{ nb_feeds }} <a href="/feeds">feeds</a>. Add a <a href="/edit_feed/">feed</a>.</p>
+ <p>You are subscribed to {{ nb_feeds }} <a href="/feeds">feeds</a>. Add a <a href="/create_feed/">feed</a>.</p>
<p>{{ nb_articles }} articles are stored in the database with {{ nb_unread_articles }} <a href="/unread/">unread articles</a>.</p>
<a href="/index_database/" class="btn btn-default">Index database</a>
</div>
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index 3a6f35d9..fb1e6429 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -103,10 +103,11 @@ def feed_access_required(func):
@wraps(func)
def decorated(*args, **kwargs):
#print("Now calling %s with %s,%s" % (func, args, kwargs))
- feed = Feed.query.filter(Feed.id == kwargs['feed_id']).first()
- if feed == None or feed.subscriber.id != g.user.id:
- flash("This feed do not exist.", "danger")
- return redirect(url_for('home'))
+ if kwargs.get('feed_id', None) != None:
+ feed = Feed.query.filter(Feed.id == kwargs.get('feed_id', None)).first()
+ if feed == None or feed.subscriber.id != g.user.id:
+ flash("This feed do not exist.", "danger")
+ return redirect(url_for('home'))
return func(*args, **kwargs)
return decorated
@@ -467,12 +468,13 @@ def management():
form = AddFeedForm()
- user = models.User.objects(email=g.user.email).first()
- nb_feeds = len(user.feeds)
+ user = User.query.filter(User.id == g.user.id).first()
+ nb_feeds = len(user.feeds.all())
#nb_articles = sum([len(feed.articles) for feed in user.feeds])
#nb_unread_articles = sum([len([article for article in feed.articles if not article.readed]) for feed in user.feeds])
- nb_articles = models.Article.objects().count()
- nb_unread_articles = models.Article.objects(readed=False).count()
+ #articles = Article.query.filter(Article.feed.subscriber.id == g.user.id).all()
+ nb_articles = sum([len(feed.articles.all()) for feed in user.feeds])
+ nb_unread_articles = 2
return render_template('management.html', form=form, \
nb_feeds=nb_feeds, nb_articles=nb_articles, nb_unread_articles=nb_unread_articles)
bgstack15