Example #1
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 #2
0
 def __init__(self):
     self.reader = CodeReader()
     self.db = BookDB(RegisterBooks.LIBRARIAN_DB_NAME)
     self.db.create_table()
     outdir = pathlib.Path(RegisterBooks.BOOKS_QRCODE_DIR)
     if not outdir.exists():
         outdir.mkdir()
Example #3
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 #4
0
 def __init__(self):
     self.bookdb = BookDB()
     self.book = Book()
Example #5
0
import re

from bookdb import BookDB

DB = BookDB()


def book(book_id):
    page = """
<h1>%(title)s</h1>
<table>
    <tr><th>Author</th><td>%(author)s</td></tr>
    <tr><th>Publisher</th><td>%(publisher)s</td></tr>
    <tr><th>ISBN</th><td>%(isbn)s</td></tr>
</table>
<a href="/">Back to the list</a>
"""
    book = DB.title_info(book_id)
    if book is None:
        raise NameError
    return page % book


def books():
    all_books = DB.titles()
    body = ['<h1>My Bookshelf</h1>', '<ul>']
    item_template = '<li><a href="/book/%(id)s">%(title)s</a></li>'
    for book in all_books:
        body.append(item_template % book)
    body.append('</ul>')
    return '\n'.join(body)
Example #6
0
 def makeOne(self):
     from bookdb import BookDB
     return BookDB()
Example #7
0
 def __init__(self):
     self.bookdb = BookDB()
     self.safaribook = None
Example #8
0
def detail(book_id=None):
    db = BookDB()
    return detail_template % (db.title_info(book_id))
Example #9
0
def index():
    db = BookDB()
    book_dict = db.titles()
    import pdb
    pdb.set_trace()
    return index_template % book_dict
Example #10
0
def my_admin_load_BooksDB(request):
    my_books=BookDB()
Example #11
0
def database():
    from bookdb import BookDB
    return BookDB()
Example #12
0
Send HTML page that echoes message from HTTP request
To get started, point browser at echo_flask.html
"""

from flask import Flask, render_template, request
from bookdb import BookDB



app = Flask(__name__)

app.debug = True # development only - remove on production machines

# View functions generate HTTP responses including HTML pages and headers
db = BookDB()

''' This function gets a dict of the ids and titles from the database and
passes it to the template.
'''
@app.route('/index.html/')
def index():
    return render_template('index.html', titles=db.titles())

''' This function takes a book id and gets the title info from the database as
a dict. This dict is passed to the template.
'''
@app.route('/book_details/<book_id>')
def detail(book_id=None):
    return render_template('detail.html', details=db.title_info(book_id))
Example #13
0
"""
My book navigator
"""

from flask import Flask, render_template, request
from bookdb import BookDB

app = Flask(__name__)

app.debug = True  # development only - remove on production machines

# View functions generate HTTP responses including HTML pages and headers
all_books = BookDB()


#Show the welcome page
@app.route('/welcome.html')
def welcome():
    return render_template('welcome.html')


#Show the index page
@app.route('/index.html')
def index():
    return render_template('index.html', books=all_books)


#Show details page
@app.route('/book.html')
def book_info():
    #render the template for the selected book based on the id tag