aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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