aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/views.py
diff options
context:
space:
mode:
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