|
|
@ -276,19 +276,6 @@ def add_stack(): |
|
|
|
stack = Stack(stack_name, stack_description) |
|
|
|
db.session.add(stack) |
|
|
|
stacks = db.session.query(Stack).all() |
|
|
|
#this potentially deals with the connection between books and stacks |
|
|
|
#book = Book(title, filename, cover, file_extension, category,year_published) |
|
|
|
|
|
|
|
#for book in books: |
|
|
|
# book_title = book.get("title") |
|
|
|
|
|
|
|
# if book_title: |
|
|
|
# a = db.session.query(Book).filter_by(book_title=book_title).first() |
|
|
|
# if a == None: |
|
|
|
# a = Book(book_title=book_title) |
|
|
|
# db.session.add(a) |
|
|
|
# stacks.book.append(a) |
|
|
|
#db.session.commit() |
|
|
|
|
|
|
|
flash("%s stack created" % (stack_name)) |
|
|
|
return render_template('add_stack.html', stacks=stacks, form=form) |
|
|
@ -371,14 +358,20 @@ def test1(): |
|
|
|
|
|
|
|
return Response(json.dumps(autocomplete_suggestions), mimetype='application/json') |
|
|
|
|
|
|
|
@app.route('/add_to_stack/<int:id>') |
|
|
|
|
|
|
|
@app.route('/add_to_stack/<int:id>', methods=['GET', 'POST']) |
|
|
|
def add_to_stack(id): |
|
|
|
stacks = db.session.query(Stack).all() |
|
|
|
book = Book.query.get(id) |
|
|
|
add = AddtoStackForm(request.form) |
|
|
|
|
|
|
|
return render_template('add_to_stacks.html', id=id, stacks=stacks, book=book, add=add) |
|
|
|
add_form = AddtoStackForm(request.form) |
|
|
|
add_form.select_stack.choices = [(stack.id, stack.stack_name) for stack in stacks] |
|
|
|
if request.method == 'GET': |
|
|
|
book = Book.query.get(id) |
|
|
|
return render_template('add_to_stacks.html', id=id, stacks=stacks, book=book, add_form=add_form) |
|
|
|
else: |
|
|
|
stack = Stack.query.get(int(add_form.select_stack.data)) |
|
|
|
book = Book.query.get(id) |
|
|
|
stack.books.append(book) |
|
|
|
db.session.commit() |
|
|
|
return render_template('show_stack_detail.html', stack=stack) |
|
|
|
|
|
|
|
### |
|
|
|
# The API |
|
|
|