def application(environ, start_response): global messages status = '200 OK' response_headers = [('Content_type', 'text/HTML')] start_response(status, response_headers) # send different page depending on URL path path = environ['PATH_INFO'] db = BookDB() if path == '/index.html': book_list = db.titles() strings = [] for book in book_list: book_id = book['id'] book_title = book['title'] strings.append(book_id) strings.append(book_title) page = index_template % (strings[0],strings[1],strings[2], strings[3],strings[4],strings[5], strings[6],strings[7],strings[8], strings[9]) elif path == '/detail.html/': book_id = \ urlparse.parse_qs(environ['QUERY_STRING'])['book_id'][0] book_info = db.title_info(book_id) page = detail_template % (book_info['title'], book_info['title'], book_info['isbn'], \ book_info['publisher'], book_info['author']) else: page = notfound_template % path return [ page ] # list of strings - must return iterable, not just a string
def application(environ, start_response): global messages status = '200 OK' response_headers = [('Content_type', 'text/HTML')] start_response(status, response_headers) # send different page depending on URL path path = environ['PATH_INFO'] db = BookDB() if path == '/index.html': book_list = db.titles() strings = [] for book in book_list: book_id = book['id'] book_title = book['title'] strings.append(book_id) strings.append(book_title) page = index_template % ( strings[0], strings[1], strings[2], strings[3], strings[4], strings[5], strings[6], strings[7], strings[8], strings[9]) elif path == '/detail.html/': book_id = \ urlparse.parse_qs(environ['QUERY_STRING'])['book_id'][0] book_info = db.title_info(book_id) page = detail_template % (book_info['title'], book_info['title'], book_info['isbn'], \ book_info['publisher'], book_info['author']) else: page = notfound_template % path return [page] # list of strings - must return iterable, not just a string
def my_admin_load_BooksDB(): my_books=BookDB() book_count=-1 for my_book in my_books.titles(): save_book( my_book['id'], my_books.title_info(my_book['id'])['isbn'].replace('-',''),my_books.title_info(my_book['id'])['title'], my_books.title_info(my_book['id'])['author'], my_books.title_info(my_book['id'])['publisher'] )
def index(environ, start_response): """ This function will be mounted on "/" and display a link to the hello world page.""" bob = BookDB() books = bob.titles() str = "" for i in books: str += '<p>%s <a href ="/info/%s/">info</a><p/>' %(i['title'], i['id']) start_response('200 OK', [('Content-Type', 'text/html')]) return [str]
def my_admin_load_BooksDB(): my_books = BookDB() book_count = -1 for my_book in my_books.titles(): save_book(my_book['id'], my_books.title_info(my_book['id'])['isbn'].replace('-', ''), my_books.title_info(my_book['id'])['title'], my_books.title_info(my_book['id'])['author'], my_books.title_info(my_book['id'])['publisher'])
def index(): db = BookDB() book_dict = db.titles() import pdb; pdb.set_trace() return index_template % book_dict
from bookdb import BookDB from pprint import pprint bob = BookDB() books = bob.titles() str = "" for i in books: str += i['title'] + '\n' print str hmm = books[1]['id'] steve = bob.title_info(hmm) pprint(steve)
def index(): db = BookDB() book_dict = db.titles() import pdb pdb.set_trace() return index_template % book_dict
__author__ = 'matt' """ Testing methods in the books class, from books_test.py. """ if __name__ == '__main__': from bookdb import BookDB books = BookDB() print books.titles() print books.title_info('id1')
def index(self): books = BookDB() env = Environment(loader=FileSystemLoader('templates')) tmpl = env.get_template('booklist.html') return tmpl.render(books=books.titles())