diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-04-08 19:41:49 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-04-08 19:41:49 +0200 |
commit | d67f2dc496fc9b072b1fe26fdc3ec7b926efbbd7 (patch) | |
tree | 9a75b04374a5cbeab1fa94c95eb9fb32162989a8 | |
parent | Improved articles loading for the home page. (diff) | |
download | newspipe-d67f2dc496fc9b072b1fe26fdc3ec7b926efbbd7.tar.gz newspipe-d67f2dc496fc9b072b1fe26fdc3ec7b926efbbd7.tar.bz2 newspipe-d67f2dc496fc9b072b1fe26fdc3ec7b926efbbd7.zip |
Mark all articles (or all articles from a feed) as read.
-rw-r--r-- | pyaggr3g470r/models.py | 2 | ||||
-rw-r--r-- | pyaggr3g470r/views.py | 19 |
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']) |