show_book.py

<---Back

Select Code Highlighting Style:

Bright | SEASHELL | Darkness

Select Font Size:

Small | Normal | Large
../www/get_script_html_files/strip/show_book.py
    1 #!/usr/bin/python2
    2 
    3 #######################################
    4 #
    5 # This script displays page with individual product
    6 #
    7 # Version: 1.8
    8 #
    9 #######################################
   10 
   11 #import all functions from lib.py
   12 
   13 from lib import *
   14 
   15 #get dictionary of values from web form
   16 
   17 form = cgi.FieldStorage()
   18 
   19 #shopping_cart_flag is a variable passed by script shopping_cart.py
   20 #When user clicks linked image: "add to cart", variable book_id is passed by this script
   21 #If used is logged in, shopping_cart.py sets cookie on user's hard drive and returnes 1
   22 #If user is not logged in, shopping_cart.py returnes 2
   23 
   24 try:
   25     shopping_cart_flag = int(form['shopping_cart_flag'].value)
   26 except:
   27     shopping_cart_flag = 0
   28 
   29 
   30 try:
   31     book_id = int(form['book_id'].value)
   32 except:
   33     book_id = 0
   34 
   35 
   36 #execute code below if this script is run as standalone script
   37 #don't execute code below if we import functions from this script
   38 
   39 if __name__ == "__main__":
   40 
   41     ############check if user is logged in
   42 
   43     is_logged_in = is_logged_in()
   44 
   45     ############key/value pair 'book_id=<some value>' should always be given as a part of URL leading to this page
   46 
   47     #if not
   48     if book_id == 0:
   49 
   50         body_html = ''
   51         message = "Oops, error. No book id is provided"
   52 
   53     else:
   54 
   55         body_html = show_book(book_id)
   56         message = ''
   57 
   58 
   59     #############generate and print html
   60 
   61     print 'Content-Type: text/html\n\n'
   62 
   63     caption = ''
   64 
   65     html=get_html(is_logged_in,body_html,caption,message)
   66 
   67     print html
   68