def recv_add_liquor_inventory(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) msg = "" status = "No values were modified\n" #Check if values have data if ( ('mfg' in results) and ('liquor' in results) and ('amt' in results)): #Get manufacturer mfg = results['mfg'][0] #Get liquor name liquor = results['liquor'][0] #Get amount amt = results['amt'][0] #Check if bottle type information is there if not (db._check_bottle_type_exists(mfg,liquor)): message = "Ooops Please add manufacturer and liquor information to bottle types first" else: #check if amount unit is correct if not (amt.endswith('ml') or amt.endswith('oz') or amt.endswith('gallon') or amt.endswith('liter')): message = "Ooops unit amount is not correct. " msg = "Valid units: 'ml','oz','gallon','liter'" else: #Add to inventory db.add_to_inventory(mfg,liquor, amt) dynamic_web.save_database('/../bin/drinkz_database') message = "Added to inventory successfully" status = "Updated inventory\n" else: message = "Ooops at least one of the fields was empty" #Generate results in html format content_type = 'text/html' data= """ <html> <head> <title>Updated inventory</title> <style type='text/css'> h1 {color:red;} body{ font-size:14px; } </style> </head> <body> """ data = data + "<h1>" + message + "</h1>" tmp = dynamic_web.generate_inventory_table() data = data + msg + "<p>" + status + "</p>" + tmp data = data + "<p><a href='./add_liquor_inventory.html'>add another liquor to inventory</a></p>" data = data + "<p><a href='./'>return to index</a></p>" data = data + """ </body> <html> """ start_response('200 OK', list(html_headers)) return [data]
def recv_add_liquor_types(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) msg = "No values were modified" #Check if values have data if ( ('mfg' in results) and ('liquor' in results) and ('typ' in results)): #Get manufacturer mfg = results['mfg'][0] #Get liquor name liquor = results['liquor'][0] #Get type typ = results['typ'][0] if (db._check_bottle_type_exists(mfg,liquor)): message = "Ooops Manufacturer and Liquor information was already there" else: #Add bottle type db.add_bottle_type(mfg,liquor,typ) dynamic_web.save_database('/../bin/drinkz_database') message = "Liquor type has been added successfully" msg = "Liquor type has been added" #At least one of the fields is empty else: message = "Ooops at least one of the fields was empty" #Generate results in html format content_type = 'text/html' data= """ <html> <head> <title>Updated Liquor Type</title> <style type='text/css'> h1 {color:red;} body{ font-size:14px; } </style> </head> <body> """ data = data + "<h1>" + message + "</h1>" data = data + msg tmp = dynamic_web.generate_liquor_type_table() data = data + tmp data = data + "<p><a href='./add_liquor_types.html'>add another liquor type</a></p>" data = data + "<p><a href='./'>return to index</a></p>" data = data + """ </body> <html> """ start_response('200 OK', list(html_headers)) return [data]
def recv_add_recipe(self, environ, start_response): formdata = environ['QUERY_STRING'] results = urlparse.parse_qs(formdata) msg = "No values were modified" is_duplicate = False #Check if values have data if ( ('name' in results) and ('ingredients' in results) ): #Get recipe name name = results['name'][0] #Get ingredients ingredients = results['ingredients'][0] for r in db._recipe_db: if name.lower() ==r.Name.lower(): #Recipe already exists is_duplicate =True if (is_duplicate): message = "Ooops recipe name is already in in database" else: print "Ingredients: " + ingredients + " \n" #Add recipe ingredient_list = [] #Separate ingredient name and ingredient amount split_ingredients = ingredients.split(';') #For each ingredient for i in split_ingredients: #Add tuple to ingredient list ingredient_list.append(tuple(i.split(','))) #create a recipe object r = recipes.Recipe(name,ingredient_list) #add recipe db.add_recipe(r) dynamic_web.save_database('/../bin/drinkz_database') message = "Recipe type has been added successfully" msg = "Updated recipe list" #At least one of the fields is empty else: message = "Ooops at least one of the fields was empty" #Generate results in html format content_type = 'text/html' data= """ <html> <head> <title>Updated Recipe</title> <style type='text/css'> h1 {color:red;} body{ font-size:14px; } </style> </head> <body> """ data = data + "<h1>" + message + "</h1>" data = data + msg tmp = dynamic_web.generate_recipe_table() data = data + tmp data = data + "<p><a href='./add_recipe.html'>add another recipe</a></p>" data = data + "<p><a href='./'>return to index</a></p>" data = data + """ </body> <html> """ start_response('200 OK', list(html_headers)) return [data]