Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

from flask import request, render_template, make_response

from webapp import flaskapp, cursor
from models import Book


@flaskapp.route('/')
def index():
name = request.args.get('name')
author = request.args.get('author')
read = bool(request.args.get('read'))

# ana testing
if name:

cursor.execute(
"SELECT * FROM books WHERE name LIKE '%" + name + "%'"
)
books = [Book(*row) for row in cursor]

elif author:
cursor.execute(
"SELECT * FROM books WHERE author LIKE '%" + author + "%'"
)
books = [Book(*row) for row in cursor]

else:
cursor.execute("SELECT name, author, read FROM books")
books = [Book(*row) for row in cursor]

return render_template('books.html', books=books)

@flaskapp.route('/books')
def books():
name = request.args.get('name')
if name:
cursor.execute(
"SELECT * FROM books WHERE name LIKE '%" + name + "%'"
)
books = [Book(*row) for row in cursor]

else:
cursor.execute("SELECT name, author, read FROM books")
books = [Book(*row) for row in cursor]

return render_template('books.html', books=books)