diff options
-rw-r--r-- | pyaggr3g470r/templates/management.html | 1 | ||||
-rw-r--r-- | pyaggr3g470r/views.py | 13 |
2 files changed, 14 insertions, 0 deletions
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 %} <a href="/index_database" class="btn btn-default">{{ _('Index database') }}</a> {% endif %} + <a href="/expire_articles?weeks=10" class="btn btn-default">{{ _('Delete articles older than 10 weeks') }}</a> </div> <div class="jumbotron"> <h1>{{ _('Your Profile') }}</h1> 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/<string:activation_key>', methods=['GET']) def confirm_account(activation_key=None): """ |