|
|
@ -394,6 +394,23 @@ def add_to_stack(id):
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
return render_template('show_stack_detail.html', stack=stack)
|
|
|
|
return render_template('show_stack_detail.html', stack=stack)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from csv import DictWriter
|
|
|
|
|
|
|
|
import io
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/export/csv', methods=['GET'])
|
|
|
|
|
|
|
|
def export_csv ():
|
|
|
|
|
|
|
|
output = io.StringIO()
|
|
|
|
|
|
|
|
fieldnames = ['title', 'authors']
|
|
|
|
|
|
|
|
csv = DictWriter(output,fieldnames)
|
|
|
|
|
|
|
|
csv.writeheader()
|
|
|
|
|
|
|
|
# for i in range(10):
|
|
|
|
|
|
|
|
# csv.writerow({'ID': i, 'fruit': "Tomato"})
|
|
|
|
|
|
|
|
for book in Book.query.order_by("title"):
|
|
|
|
|
|
|
|
authors = ", ".join([x.author_name for x in book.authors])
|
|
|
|
|
|
|
|
csv.writerow({"title": book.title, "authors": authors})
|
|
|
|
|
|
|
|
resp = Response(output.getvalue(), mimetype="text/plain")
|
|
|
|
|
|
|
|
# resp.headers["Content-Disposition"] = "attachment;filename=export.csv"
|
|
|
|
|
|
|
|
return resp
|
|
|
|
###
|
|
|
|
###
|
|
|
|
# The API
|
|
|
|
# The API
|
|
|
|
###
|
|
|
|
###
|
|
|
|