aboutsummaryrefslogtreecommitdiff
path: root/src/web/views/article.py
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-10-11 23:50:23 +0200
committerFrançois Schmidts <francois.schmidts@gmail.com>2016-01-26 23:46:31 +0100
commit600391ac74a2ab29bd5c1f1433c14dae9ce6ea9b (patch)
tree58fb642ce53ef837411d6abf32d8caa5a62e9c06 /src/web/views/article.py
parentremoving misplaced stuffs from views, more controllers use (diff)
downloadnewspipe-600391ac74a2ab29bd5c1f1433c14dae9ce6ea9b.tar.gz
newspipe-600391ac74a2ab29bd5c1f1433c14dae9ce6ea9b.tar.bz2
newspipe-600391ac74a2ab29bd5c1f1433c14dae9ce6ea9b.zip
moving 'expire_article' and improving its perf
Diffstat (limited to 'src/web/views/article.py')
-rw-r--r--src/web/views/article.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/web/views/article.py b/src/web/views/article.py
index d308d37e..664b66c8 100644
--- a/src/web/views/article.py
+++ b/src/web/views/article.py
@@ -1,6 +1,8 @@
#! /usr/bin/env python
# -*- coding: utf-8 -
-from flask import Blueprint, g, render_template, redirect, flash, url_for
+from datetime import datetime, timedelta
+from flask import (Blueprint, g, render_template, redirect,
+ flash, url_for, request)
from flask.ext.babel import gettext
from flask.ext.login import login_required
@@ -101,3 +103,21 @@ def mark_as(new_value='read', feed_id=None, article_id=None):
if readed:
return redirect(redirect_url())
return redirect('home')
+
+
+@articles_bp.route('/expire_articles', methods=['GET'])
+@login_required
+def expire():
+ """
+ Delete articles older than the given number of weeks.
+ """
+ current_time = datetime.utcnow()
+ weeks_ago = current_time - timedelta(int(request.args.get('weeks', 10)))
+ art_contr = ArticleController(g.user.id)
+
+ query = art_contr.read(__or__={'date__lt': weeks_ago,
+ 'retrieved_date__lt': weeks_ago})
+ count = query.count()
+ query.delete()
+ flash(gettext('%(count)d articles deleted', count=count), 'info')
+ return redirect(redirect_url())
bgstack15