Example #1
0
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'])
Example #2
0
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
Example #3
0
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
Example #4
0
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']  )
Example #5
0
 def detail(self, id):
     books = BookDB()
     bookdet = books.title_info(id)
     template = Template('''
         <h1>Book Details</h1><hr>
            <h2>Title: $bookdet['title']</h2><br> 
            <b>ISBN:</b> $bookdet['isbn']<br>
            <b>Publisher:</b> $bookdet['publisher']<br>
            <b>Author:</b> $bookdet['author']<br><br>
         <a href="./">Return to List</a>
     ''', [locals(), globals()])
     return template.respond()
def info(environ, start_response):
    """ This function displays a page for each of the books in the database."""
    parameters = environ.get('PATH_INFO', "").split('/')
    subject = str(parameters[2])
    if "" == subject:
        start_response('400 No Content', [('Content-Type', 'text/html')])
    else:
        bob = BookDB()
        steve = bob.title_info(subject)
        stri = ""
        start_response('200 OK', [('Content-Type', 'text/html')])
        for i in steve.keys():
            stri += '<p>%s : %s<p/>' %(i, steve[i])
        stri +=  '<p><a href ="/">BACK</a><p/>'
        return [stri]
    print '---->' + str(parameters[2])
Example #7
0
def detail(book_id=None):
    db = BookDB()
    return detail_template % (db.title_info(book_id))
Example #8
0
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)
Example #9
0
def detail(book_id=None):
    db = BookDB()
    return detail_template % (db.title_info(book_id))
__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 BookDetail(self, id):
        books = BookDB()
        env = Environment(loader=FileSystemLoader('templates'))
        tmpl = env.get_template('bookdetail.html')

        return tmpl.render(detail=books.title_info(id))