import cx_Oracle def generate_html_table(headers, rows): html = [] if headers: html.append("") for header in headers: html.append("%s" % header) html.append("") if rows: for row in rows: html.append("") i = 0 for cell in row: if i == 0: serial = cell i = 1 html.append("%s" % cell) html.append("" % serial) html.append("") if html: html = [""] + html + ["
"] return "\n".join(html) def storeMain(**t): color = "NONE" for p in t.keys(): if p == "COLOR": color = t[p] print "using color=%s" % color connection = cx_Oracle.connect("oracle/oracle") cursor = connection.cursor() headers = [] headers.append("Serial Number") headers.append("Name") headers.append("Price") headers.append("Size") headers.append("Type") headers.append("Color") rows = [] # This query returns all bikes available # Use the 'color' variable to limit the results returned if color == 'NONE': cursor.execute("SELECT serialno, name, price, bikesize, type, color, instock FROM bikes where instock=1") else: parms = {'col':color} cursor.execute("SELECT serialno, name, price, bikesize, type, color, instock FROM bikes where instock=1 AND color=:col", parms) for c1, c2, c3, c4, c5, c6, c7 in cursor.fetchall(): row = []; row.append(c1) row.append(c2) row.append(c3) row.append(c4) if c5 == "R": row.append("") else: row.append("") row.append(c6) rows.append(row); cursor.execute("commit") cursor.close() connection.close() if not rows: html = "

No item matching your query was found." else: html = generate_html_table(headers, rows) s = """\
Narrow down list

Select color
%s
""" % (html) #print "returning %s" % s return s def buy(**t): for p in t.keys(): if p == "SERIAL": serial = t[p] connection = cx_Oracle.connect("oracle/oracle") cursor = connection.cursor() params = {'ser':serial} cursor.execute("SELECT serialno, name, type, price, color, instock FROM bikes where serialno=:ser", params) for c1, c2, c3, c4, c5, c6 in cursor.fetchall(): name = c2 color = c5 type = c3 price = c4 cursor.close() connection.close() if type == 'R': image = '' else: image = '' return """\ Home

Ready to buy a %s '%s'

%s

Your credit card will be charged for %s

Enter your Credit Card information below

Name on card:
Card number:
Expiration:

""" % (color.lower(), name, image, str(price), serial)