aboutsummaryrefslogtreecommitdiff
path: root/src/web/views
diff options
context:
space:
mode:
Diffstat (limited to 'src/web/views')
-rw-r--r--src/web/views/article.py22
-rw-r--r--src/web/views/views.py17
2 files changed, 21 insertions, 18 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())
diff --git a/src/web/views/views.py b/src/web/views/views.py
index f543c6fa..4abea96e 100644
--- a/src/web/views/views.py
+++ b/src/web/views/views.py
@@ -416,20 +416,3 @@ def export_opml():
response.headers['Content-Type'] = 'application/xml'
response.headers['Content-Disposition'] = 'attachment; filename=feeds.opml'
return response
-
-
-@app.route('/expire_articles', methods=['GET'])
-@login_required
-def expire_articles():
- """
- Delete articles older than the given number of weeks.
- """
- weeks_ago = datetime.datetime.utcnow() - \
- datetime.timedelta(weeks=int(request.args.get('weeks', 10)))
- Article.query.filter(
- and_(Article.user_id == g.user.id,
- or_(Article.date < weeks_ago,
- Article.retrieved_date < weeks_ago))).delete()
- flash(gettext('Articles deleted.'), 'info')
- db.session.commit()
- return redirect(redirect_url())
bgstack15