aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/models.py2
-rw-r--r--pyaggr3g470r/views.py19
2 files changed, 7 insertions, 14 deletions
diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py
index 230d1021..b1cd3448 100644
--- a/pyaggr3g470r/models.py
+++ b/pyaggr3g470r/models.py
@@ -97,7 +97,7 @@ class Feed(db.Model):
email_notification = db.Column(db.Boolean(), default=False)
enabled = db.Column(db.Boolean(), default=True)
created_date = db.Column(db.DateTime(), default=datetime.now)
- articles = db.relationship('Article', backref = 'feed', lazy = 'dynamic', cascade='all,delete-orphan',
+ articles = db.relationship('Article', backref = 'source', lazy = 'dynamic', cascade='all,delete-orphan',
order_by=desc("Article.date"))
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index c2f6b9bf..9be985c9 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -249,27 +249,20 @@ def article(article_id=None):
return render_template('article.html', head_title=utils.clear_string(article.title), article=article)
@app.route('/mark_as_read/', methods=['GET'])
-@app.route('/mark_as_read/<feed_id>', methods=['GET'])
+@app.route('/mark_as_read/<int:feed_id>', methods=['GET'])
@login_required
+@feed_access_required
def mark_as_read(feed_id=None):
"""
Mark all unreaded articles as read.
"""
if feed_id != None:
- user = models.User.objects(email=g.user.email).first()
- for feed in user.feeds:
- if str(feed.oid) == feed_id:
- unread_articles = [article for article in feed.articles if not article.readed]
- for article in unread_articles:
- article.readed = True
- article.save()
- flash('Articles of the feed "' + feed.title + '" marked as read.', 'info')
- break
- else:
- flash("This feed do not exist.", 'warning')
+ articles, feed = Article.query.filter(Article.readed == False).join(Feed).filter(Feed.id == feed_id).update({"readed": True})
+ flash('Articles marked as read.', 'info')
else:
- models.Article.objects(readed=False).update(set__readed=True)
+ Article.query.filter(Article.readed == False).update({"readed": True})
flash("All articles marked as read", 'info')
+ db.session.commit()
return redirect(redirect_url())
@app.route('/like/<article_id>', methods=['GET'])
bgstack15