aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/views.py
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-29 23:08:36 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-04-29 23:08:36 +0200
commite762c6b0a257dbbc90f51e069f708bbf037fac57 (patch)
tree6ed6a400d2e359cc97a090b50d7469982da15fed /pyaggr3g470r/views.py
parentadded templates for emails (diff)
downloadnewspipe-e762c6b0a257dbbc90f51e069f708bbf037fac57.tar.gz
newspipe-e762c6b0a257dbbc90f51e069f708bbf037fac57.tar.bz2
newspipe-e762c6b0a257dbbc90f51e069f708bbf037fac57.zip
Added export to JSON.
Diffstat (limited to 'pyaggr3g470r/views.py')
-rw-r--r--pyaggr3g470r/views.py33
1 files changed, 24 insertions, 9 deletions
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index 6d394186..491d44a2 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -401,17 +401,32 @@ def index_database():
@login_required
def export_articles():
"""
- Export all articles.
+ Export all articles to HTML or JSON.
"""
user = User.query.filter(User.id == g.user.id).first()
- try:
- archive_file, archive_file_name = export.export_html(user)
- except:
- flash("Error when exporting articles.", 'danger')
- return redirect(url_for('management'))
- response = make_response(archive_file)
- response.headers['Content-Type'] = 'application/x-compressed'
- response.headers['Content-Disposition'] = 'attachment; filename='+archive_file_name
+ if request.args.get('format') == "HTML":
+ # Export to HTML
+ try:
+ archive_file, archive_file_name = export.export_html(user)
+ except:
+ flash("Error when exporting articles.", 'danger')
+ return redirect(redirect_url())
+ response = make_response(archive_file)
+ response.headers['Content-Type'] = 'application/x-compressed'
+ response.headers['Content-Disposition'] = 'attachment; filename='+archive_file_name
+ elif request.args.get('format') == "JSON":
+ # Export to JSON
+ try:
+ json_result = export.export_json(user)
+ except:
+ flash("Error when exporting articles.", 'danger')
+ return redirect(redirect_url())
+ response = make_response(json_result)
+ response.mimetype = 'application/json'
+ response.headers["Content-Disposition"] = 'attachment; filename=articles.json'
+ else:
+ flash('Export format not supported.', 'warning')
+ return redirect(redirect_url())
return response
@app.route('/export_opml/', methods=['GET'])
bgstack15