From 4c8bb70e705e3dd5e2bacdd49c97e40bc5396949 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 20 Aug 2014 15:12:51 +0200 Subject: It is now possible to delete articles older than a given number of weeks. --- pyaggr3g470r/templates/management.html | 1 + pyaggr3g470r/views.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/pyaggr3g470r/templates/management.html b/pyaggr3g470r/templates/management.html index 4375ebdd..f8b7b8a0 100644 --- a/pyaggr3g470r/templates/management.html +++ b/pyaggr3g470r/templates/management.html @@ -8,6 +8,7 @@ {% if not_on_heroku %} {{ _('Index database') }} {% endif %} + {{ _('Delete articles older than 10 weeks') }}

{{ _('Your Profile') }}

diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index c8a7c7c6..3033f4c0 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -742,6 +742,19 @@ def delete_account(): flash(gettext('This user does not exist.'), 'danger') return redirect(url_for('login')) +@app.route('/expire_articles', methods=['GET']) +@login_required +def expire_articles(): + """ + Delete articles older than the given number of weeks. + """ + current_time = datetime.datetime.utcnow() + weeks_ago = current_time - datetime.timedelta(weeks=int(request.args.get('weeks', 10))) + for article in Article.query.filter(User.email == g.user.email, Article.date < weeks_ago).all(): + db.session.delete(article) + db.session.commit() + return redirect(redirect_url()) + @app.route('/confirm_account/', methods=['GET']) def confirm_account(activation_key=None): """ -- cgit