aboutsummaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
Diffstat (limited to 'src/web')
-rw-r--r--src/web/templates/management.html2
-rw-r--r--src/web/views/article.py22
-rw-r--r--src/web/views/views.py17
3 files changed, 22 insertions, 19 deletions
diff --git a/src/web/templates/management.html b/src/web/templates/management.html
index ac4f3a4a..01179b5e 100644
--- a/src/web/templates/management.html
+++ b/src/web/templates/management.html
@@ -5,7 +5,7 @@
<h1>{{ _('Your subscriptions') }}</h1>
<p>{{ _('You are subscribed to') }} {{ nb_feeds }} <a href="/feeds">{{ _('feeds') }}</a>. <a href="{{ url_for("feed.form") }}">{{ _('Add') }}</a> {{ _('a feed') }}.</p>
<p>{{ nb_articles }} {{ _('articles are stored in the database with') }} {{ nb_unread_articles }} {{ _('unread articles') }}.</p>
- <a href="/expire_articles?weeks=10" class="btn btn-default" onclick="return confirm('{{ _('You are going to delete old articles.') }}');">{{ _('Delete articles older than 10 weeks') }}</a>
+ <a href="{{ url_for("articles.expire", weeks=10) }}" class="btn btn-default" onclick="return confirm('{{ _('You are going to delete old articles.') }}');">{{ _('Delete articles older than 10 weeks') }}</a>
</div>
<div class="well">
<h1 id="import">{{ _('OPML import/export') }}</h1>
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