def add_liquor_type_recv(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) mfg = results['mfg'][0] liquor = results['liquor'][0] typ = results['typ'][0] db.add_bottle_type(mfg, liquor, typ) db.save_db('bin/sample_database') taste_of_success = db._check_bottle_type_exists(mfg, liquor) if taste_of_success == True: data = generate_html.generate_liquor_types_html() else: content_type = 'text/html' data = """ <html> <head> <title>Failure to Add Liquor!</title> <style type ="text/css"> h1{color:red;} </style> </head> <body>""" data += """Failed to add Liquor type, please try again!""" data += generate_html.generate_menu() data += """ </body> </html> """ start_response('200 OK', list(html_headers)) return [data]
def add_a_new_recipe_recv(self, environ, start_response): print "in add_a_new_recipe_recv" formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) name = results['name'][0] ings = results['ings'][0] indv_ings = ings.split(',') ind_list =[] for item in indv_ings: myTup = tuple(item.split(':')) ind_list.append(myTup) recipe = recipes.Recipe(name,ind_list) db.add_recipe(recipe) db.save_db('bin/sample_database') taste_of_success = db.get_recipe(name) if taste_of_success == recipe: data = generate_html.generate_recipes_html() else: content_type = 'text/html' data = """ <html> <head> <title>Failure to add recipe!</title> <style type ="text/css"> h1{color:red;} </style> </head> <body>""" data += """Failed to add Recipe, please try again!""" data += generate_html.generate_menu() data += """ </body> </html> """ start_response('200 OK', list(html_headers)) return [data]
def add_to_inventory_recv(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) mfg = results['mfg'][0] liquor = results['liquor'][0] amount = results['amount'][0] myBool = db.check_inventory(mfg,liquor) if myBool == True: intial_amt = db.get_liquor_amount(mfg,liquor) else: intial_amt = 0 db.add_to_inventory(mfg, liquor, amount) db.save_db('bin/sample_database') taste_of_success = db.check_inventory(mfg, liquor) amt_success = db.get_liquor_amount(mfg,liquor) if taste_of_success == True and amt_success > intial_amt: data = generate_html.generate_liquor_types_html() else: content_type = 'text/html' data = """ <html> <head> <title>Failure to Add Liquor!</title> <style type ="text/css"> h1{color:red;} </style> </head> <body>""" data += """Failed to add Liquor type, please try again!""" data += generate_html.generate_menu() data += """ </body> </html> """ start_response('200 OK', list(html_headers)) return [data]
def convert_all_the_things_recv(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) amount_to_convert = results['InputAmt'][0] converted_amt = db.convert_to_ml(amount_to_convert) content_type = 'text/html' data = """ <html> <head> <title>Converted!</title> <style type ="text/css"> h1{color:red;} </style> </head> <body>""" data += """<h1> Converted! </h1> <p>Amount to Convert: %s; Converted volume: %s mL. </p>""" % (amount_to_convert, converted_amt) data += generate_html.generate_menu() data += """ </body> </html> """ start_response('200 OK', list(html_headers)) return [data]