Merge branch 'stack_stuff' of git.xpub.nl:/var/www/git.xpub.nl/repos/xpub-lib into xpplannot

This commit is contained in:
ange 2018-06-06 19:36:19 +02:00
commit 24377874fa
3 changed files with 28 additions and 1 deletions

View File

@ -36,3 +36,13 @@ brew install imagemagick@6
Create a symlink to this newly installed dylib file as mentioned in other answer to get things working.
ln -s /usr/local/Cellar/imagemagick@6/<your specific 6 version>/lib/libMagickWand-6.Q16.dylib /usr/local/lib/libMagickWand.dylib
## install pyrqlite
git clone https://github.com/rqlite/pyrqlite.git
pip install ./pyrqlite
## install sqlalchemy-rqlite
git clone https://github.com/rqlite/sqlalchemy-rqlite.git
cd sqlalchemy-rqlite
sudo python3 ./setup.py install

View File

@ -407,6 +407,23 @@ def add_to_stack(id):
db.session.commit()
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
###

View File

@ -39,7 +39,7 @@ with open(args.csv) as f:
if stack:
b = db.session.query(Stack).filter_by(stack_name=stack).first()
if b == None:
b = Stack(stack_name=stack, stack_description=stack_description)
b = Stack(stack_name=stack, stack_description=None)
db.session.add(b)
book.stacks.append(b)