11
22from flask import request , render_template , make_response
33
4- from server .webapp import flaskapp , db
4+ from server .webapp import flaskapp , cursor
55from server .models import Book
66
77
@@ -12,20 +12,23 @@ def index():
1212 read = bool (request .args .get ('read' ))
1313
1414 if name :
15- result = db . engine .execute (
16- "SELECT * FROM Book WHERE name LIKE '%" + name + "%'"
15+ cursor .execute (
16+ "SELECT * FROM books WHERE name LIKE '%" + name + "%'"
1717 )
18- books = [row for row in result ]
18+ books = [Book ( * row ) for row in cursor ]
1919 if len (books ) == 0 :
2020 return make_response (f"Search Result not found: { name } " , 404 )
21+
2122 elif author :
22- result = db . engine .execute (
23- "SELECT * FROM Book WHERE author LIKE '%" + author + "%'"
23+ cursor .execute (
24+ "SELECT * FROM books WHERE author LIKE '%" + author + "%'"
2425 )
25- books = [row for row in result ]
26+ books = [Book ( * row ) for row in cursor ]
2627 if len (books ) == 0 :
2728 return make_response (f"Search Result not found: { author } " , 404 )
29+
2830 else :
29- books = Book .query .all ()
30-
31+ cursor .execute ("SELECT name, author, read FROM books" )
32+ books = [Book (* row ) for row in cursor ]
33+
3134 return render_template ('books.html' , books = books )
0 commit comments