Esempio n. 1
0
	def need_ingredients(self):
		i = 0
		#get the types from the database

		for val in db.get_all_recipes():
			while i < len(db.get_all_recipes().values()):
				print "Liqour values", db.get_all_recipes().values()[i][3]
				types =  db.get_Type(db.get_all_recipes().values()[i][0][0])
				#print "Types of liquor", types
				amt = db.get_liquor_amount(types[0], types[1])
				print amt[0]
				recipe_Amounts = db.get_all_recipes().values()[i][0][1].split(' ')
				print recipe_Amounts

				conversion = db.convert_ml(int(recipe_Amounts[0]), recipe_Amounts[1])

				print "The conversion is ", conversion
	
				if float(amt[0]) < conversion:
					req = conversion - amt[0]
					req_type = db.get_all_recipes().values()[i][0][0], req
					replenish.append(req_type)
					repl[db.get_all_recipes().keys()[i]] = "Yes"
				else:
					msg = "we enough of that type"
					repl[db.get_all_recipes().keys()[i]] = "No"



				i = i + 1

		return repl
Esempio n. 2
0
    def rpc_recipes_names(self):
        recp = []
        recipes = db.get_all_recipes()
        for k in recipes:
            recp.append(k.name)

        return recp
Esempio n. 3
0
    def rpc_get_recipe_names(self):
        recipeList = db.get_all_recipes()
        nameList = list()

        for recipe in recipeList:
            nameList.append(recipe._recipeName)
        return nameList
Esempio n. 4
0
    def recipes(self, environ, start_response):
        content_type = 'text/html'
        data = """

        <table border=\"1\" cellpadding =\"5\">
        <tr><th>Name</th><th>Ingredients</th><th>Are we missing anything?</tr>
        """
        for recipe in db.get_all_recipes():
            data = data + "<tr><td> "+ recipe.name +"</td><td><table cellpadding =\"5\">"
            for item in recipe.ingredients:
                data = data + "<tr><td>"+ item[0] +"</td><td> " + item[1] +" </td></tr>"
            data = data + "</table></td><td>"
            
            missing = recipe.need_ingredients()
            if(missing):
                data = data + "we're missing some stuff, call Mikey"
            else:
                data = data + "nope, we're good to go, call Mikey"
            
            print data + "</td></tr>"
        data = data + "</table>"

        menu = printMenu()
        
        #data = data + menu
        data = self.buildHtmlPage("Recipes","",data)
        start_response('200 OK', list(html_headers))
        return [data]
Esempio n. 5
0
def recipes():

    #this sets up jinja2
    loader = jinja2.FileSystemLoader('../drinkz/templates')
    env = jinja2.Environment(loader=loader)

    #pick filename to render
    filename = "jinja_recipes.html"

    recipeList = []
    for recipe in db.get_all_recipes():
        if len(recipe.need_ingredients()) > 0:
            result = "No :("
        else:
            result = "Yup :D"

        recipeList.append(list([recipe.get_name(), result]))

    vars = dict(title = 'Recipes Here!', title2 = 'Recipes', addtitle = "Submit Recipe",
                form = """ <form action='recv_recipe_add'>
Recipe to add? (Format: recipeName,ingrName::ingrAmt ml,ingrName2::ingrAmt2 gallon)<br><input type='text' name='recipe' size'20'>
<input type='submit'>
</form> """, names = recipeList, bodyFormat = bodyText)

    #Since Nosetests will fail since it isn't run in the drinkz directory, but in the home dir :( 
    try:
        template = env.get_template(filename)
    except:
        loader = jinja2.FileSystemLoader('./drinkz/templates')
        env = jinja2.Environment(loader=loader)
        template = env.get_template(filename)
        
    result = template.render(vars).encode('ascii','ignore')
    return result
Esempio n. 6
0
    def rpc_GetRecipes(self):
        recipes = list(db.get_all_recipes());
        recipeNames = list()

        for r in recipes:
            recipeNames.append(r._name)

        return recipeNames
Esempio n. 7
0
    def recipes(self, environ, start_response):
        start_response("200 OK", list(html_headers))

        title = "recipes"
        recipes = [ r for r in db.get_all_recipes() ]

        template = env.get_template("recipes.html")
        return str(template.render(locals()))
Esempio n. 8
0
def recipes_list():
	tcontent = []
	for r in db.get_all_recipes():
		tup = (r.Name,r.Ingredients,r.need_ingredients())
		tcontent.append(tup)

	vars = dict(title = 'Recipe Inventory', theaders=["Recipe Name","Ingredients","Missing Ingredients"],tcontent = tcontent)

	return JinjaLoader('bottle_type_pages.html', vars)
Esempio n. 9
0
    def recipes(self, environ, start_response):
		if self.get_name(environ) != False:
			namenow = self.get_name(environ)
			allrecipes = db.get_all_recipes()
			canmake = ""
			addin=""
			for recipe in allrecipes:
				if(recipe.need_ingredients() == []):
					lacking = "Yes, drink!"
					canmake = canmake + " " + str(recipe.recipename) 
				else:
					lacking = "Needs more:"
					temp = recipe.need_ingredients()
					lacking += str(temp[0]) + " " 

				addin += "<li><div class=\"ui-grid-c\"><div class=\"ui-block-a\" style=\"width:25%\">" + recipe.recipename + "</div><div class=\"ui-block-b\" style=\"width:25%\">" + lacking +"</div>"
				addin += "<div class=\"ui-block-c\" style=\"width:25%\">" + str(db.get_recipe_rating(recipe)) + "</div>"
				addin += "<div class=\"ui-block-d\" style=\"width:25%\">"
				addin += "<button onclick=\"upvote('" 
				addin += recipe.recipename
				addin += "');\">"
				addin += "Like</button></div></div></li>"
				addin += """\
			<script>
			function upvote(recipe_name){
                 	$.ajax({
                        	url: '/rpc',
                        	data: JSON.stringify ({method:'upvote_recipe', params:[recipe_name,], id:"0"} ),
                        	type: "POST",
                        	dataType: "json",
                        	success: function (data) { success(data)},
                        	error: function (err)  { erroring(err) }
                	});
                }
		function success(data){
			alert('Thanks for your vote!');
			location.reload();
			}
		function erroring(err){
			alert("Something went wrong server side, try again.");
			}
		</script>
"""
			vars = dict(title="Recipes",name=namenow, recipess=addin, canmakee = canmake)
			template = env.get_template("recipes.html")
			data = template.render(vars)
			content_type = 'text/html'
			start_response('200 OK', list(html_headers))
			print str(data)
			return [str(data)]
		else:
			headers = list(html_headers)
			headers.append(('Location', '/login'))
			start_response('302 Found', headers)
			return ["Redirect to /login..."]
Esempio n. 10
0
def test_get_all_recipes():
    db._reset_db()
    r = recipes.Recipe('vodka martini', [('vodka', '6 oz'), ('vermouth', '1 oz')])
    db.add_recipe(r)
    r2 = recipes.Recipe('screwdriver', [('orange juice', '6 oz'), ('vodka', '1 oz')])
    db.add_recipe(r2)
    x = db.get_all_recipes()

    assert len(x) == 2
    for rec in x:
        print rec.name, rec.ingredients
Esempio n. 11
0
	def rpc_get_recipe_names(self):
		basepath = os.path.dirname(__file__)
		filepath = os.path.abspath(os.path.join(basepath, "..","db.txt"))
		db.load_dumped_db(filepath)

		recipes = ""
		for r in db.get_all_recipes():
			recipes += r.Name
			recipes += "\n"

		return recipes
Esempio n. 12
0
    def rpc_add_recipe(self, name, Ingredients):
        r = recipes.Recipe(name, Ingredients)
        db.add_recipe(r)

        recipeSet = db.get_all_recipes()

        for rec in recipeSet:
            if rec.name == name:
                return True

        return False
Esempio n. 13
0
def recipes():
    html = ""
    for r in db.get_all_recipes():
            html += '<li>%s<ul>' % r.name
            for name, amount in r.ingredients:
                html+= '<li>%s'% name  
                html+= ' - %s'% amount
            html+= '</ul>'
    html += """</ul>"""
    
    recipes =  env.get_template('recipes.html')
    return recipes.render(recipes=html).encode('ascii', 'ignore')
Esempio n. 14
0
    def recipe(self,environ, start_response):
	data = direction
	lack = db.get_all_recipes()
	recipes = "<ol>"
	for r in lack:
		if(db.need_ingredients(r) ==[]):
			lacks = "Yes"
		else:
			lacks = "No"
		
		recipes += "<li>" + r.name +": " + lacks+"</li>\n"
	data = css_html.cssgen('green','30','Recipe')+data + recipes + css_html.htmlgen()
	start_response('200 OK', list(html_headers))
	return [data]	
Esempio n. 15
0
def  CheckRecipesAvailable():
    # Check all of the recipes and return which ones we can make with the inventory
    # recipes.Recipe('vodka martini', [('unflavored vodka', '6 oz'), ('vermouth', '1.5 oz')])

    global _recipe_db, _inventory_db

    recipes = list(db.get_all_recipes())
    recipesAvailable = set()

    for recipe in recipes:
            ingredientsNeeded = recipe.need_ingredients();
            if(len(ingredientsNeeded) == 0):
                recipesAvailable.add(recipe._name)

    return recipesAvailable;
Esempio n. 16
0
def Recipes():

    
    fp =  """<table border="1"><tr><th>Cocktail</th><th>Can We Make It?</th></tr>"""

    for r in db.get_all_recipes():
        a = r.need_ingredients()
        if( a != [] ):
            fp += "<tr><td>%s</td><td align=center>&#x2717;</td></tr>" % (r.name,)
        else:
            fp += "<tr><td>%s</td><td align=center>&#x2713;</td></tr>" % (r.name,)

    fp += "</table>" 

    fp += """<p><a href='/'>Index</a></p><p><a href='inventory'>Inventory</a></p><p><a href='liquor_types'>Liquor Types</a></p>"""

    return fp
Esempio n. 17
0
    def recipes(self, environ, start_response):
        content_type = 'text/html'
        data = """\
<html>
<head>
<title>Recipes</title>
<style type='text/css'>
h1 {color:red;}
hody {
font-size: 14px;
}
</style>
</head>
<body>
<h1>Recipes:</h1>
<table>
  <tr>
    <td>Name:</td>
    <td>Ingredients Needed(ml):</td>
  </tr>
"""
        recipe_list = list(db.get_all_recipes())
        for r in recipe_list:
           data += '<tr>'
           strhtml = '<td>'+r.name+'</td>'
           data += strhtml
           ing = r.need_ingredients()
           if len(ing) == 0:
               strhtml = '<td>HAVE ALL INGREDIENTS</td>'
           else:
               strhtml = '<td>missing: '
               for i in ing:
                   strhtml += str(i)
               strhtml += '</td>'
           data += strhtml
           data += '</tr>'
        data += """\
</table>
<a href='./'>Back To Index</a>
</body>
</html>
"""

        start_response('200 OK', list(html_headers))
        return [data]
Esempio n. 18
0
    def show_can_make(self, environ, start_response):
        can_make = []
        for rec in db.get_all_recipes():
            missing = rec.need_ingredients()
            if len(missing) == 0:
                can_make.append(rec)

        recipes = []
        for rec in can_make:
            ingredients = []
            for liquor, amount in rec.ingredients:
                ingredients.append("%s %s" % (amount, liquor))
            ingredients = ', '.join(ingredients)
            recipes.append((rec.name, ingredients))

        vars = {'recipes': recipes}
        data = self._render('canmake.html', 'Recipes you can make', vars)
        start_response('200 OK', list(html_headers))
        return [data]
Esempio n. 19
0
 def recipes(self, environ, start_response):
     title = "recipes"
     content = """<table border='1' margin='50px'>
     <tr>
     <td><strong>Recipes</strong></td>
     <td><strong>Available?</strong></td>
     </tr>
     """
     recipes = db.get_all_recipes()
     for r in recipes:
         content += "<tr><td>%s</td><td> "%(r.name)
         if (r.need_ingredients):
             content += "no"
         else:
             content += "ya"
     content +=  "</td></tr>"
     content += "</table>"
     data = begining % (title,title) + content + end 
     start_response('200 OK', list(html_headers))
     return [data]
Esempio n. 20
0
    def recipes(self, environ, start_response):
        content_type = 'text/html'
        text = """

<!DOCTYPE HTML>
<html>
<head>
<title>Recipe List</title>
<style type='text/css'>
h1 {text-decoration:underline; text-align:center; color:red;}
body { font-size:14px; }
</style>
</head>
<body>
<h1>List of Recipes</h1>
<ul>
    <li><a href='/'>Home</a></li>
    <li><a href='/recipes'>List Recipes</a></li>
    <li><a href='/inventory'>List Inventory</a></li>
    <li><a href='/liquor_types'>List Liquor Types</a></li>
</ul>
<hr />
<ul>
"""
        recipes = list(db.get_all_recipes())
        for r in recipes:
            missing_ingredients = r.need_ingredients()
            if len(missing_ingredients) == 0:
                haveIngredients = "Yes"
            else:
                haveIngredients = "No"

            text += "\t<li>" + r._name + " - " + haveIngredients + "</li>\n"
        text += '</ul>'

        text += '</body></html>'

        data = text
        start_response('200 OK', list(html_headers))
        return [data]
Esempio n. 21
0
    def recipes(self, environ, start_response):
        content_type = 'text/html'
        data = """

        <table border=\"1\" cellpadding =\"5\">
        <tr><th>Name</th><th>Ingredients</th><th>Check Those Ingredients!</tr>
        """
        for recipe in db.get_all_recipes():
            data = data + "<tr><td> "+ recipe.name +"</td><td><table cellpadding =\"5\">"
            for item in recipe.ingredients:
                data = data + "<tr><td>"+ item[0] +"</td><td> " + item[1] +" </td></tr>"
            data = data + "</table></td><td>"
            
            missing = recipe.need_ingredients()
            if(missing):
                data = data + "Hell Nah, You are missing: <br>"
            else:
                data = data + "Hell Yeah, We Can Do That!"
            
            for tup in missing:
                data = data + tup[0] + ' ' + str(tup[1]) + ' ml' + '<br>' 

        data = data + "</table>"
     
        data = data + """</br>
    </br>
    <h2> Menu </h2>
    <a href='/'>Home</a></br>
    <a href='recipes'>Recipes</a></br>
    <a href='inventory'>Inventory</a></br>
    <a href='liquor_types'>Liquor Types</a></br>
    <a href='convert_to_ml'>Convert Amount</a></br>
    <a href='recipe_input'>Add Recipe</a></br>
    <a href='type_form'>Add Bottle Type</a></br>
    <a href='inv_form'>Add to Inventory</a></br>
    """
        data = self.buildHtmlPage("Recipes","",data)
        start_response('200 OK', list(html_headers))
        return [data]
Esempio n. 22
0
def generate_recipes_html():
	data = """
		<html>
	<head>
	<title>Recipes</title>
		<style type ="text/css">
		h1{color:red;}
	</style>
	</head>
	<body><h1> Recipes</h1>"""
	x = list(db.get_all_recipes())
	for recipe in x:
		data += "<h2>%s</h2>" % (recipe.getName())
		data += "<ul>"
		for ing in recipe.getIngredients():
			data += "<li>%s -- %s</li>" % (ing[0], ing[1])
		data += "</ul>"
	data += generate_menu()
	data += """</body>
</html>
"""
	return data
Esempio n. 23
0
    def show_recipes(self, environ, start_response):
        vars = {}
        recipes = []
        if environ['REQUEST_METHOD'].endswith('POST'):
            vars['error'] = self.do_add_recipe(environ)

        for rec in db.get_all_recipes():
            ingredients = []
            for liquor, amount in rec.ingredients:
                ingredients.append("%s %s" % (amount, liquor))
            ingredients = ', '.join(ingredients)

            missing_ingredients = []
            for liquor, amount in rec.need_ingredients():
                missing_ingredients.append("%.2fml %s" % (amount, liquor))
            missing_ingredients = ', '.join(missing_ingredients)

            recipes.append((rec.name, ingredients, missing_ingredients))
        vars['recipes'] = recipes
        data = self._render('recipes.html', 'Show Recipes', vars)
        start_response('200 OK', list(html_headers))
        return [data]
Esempio n. 24
0
def recipesList():
    # this sets up jinja2 to load templates from the 'templates' directory
    loader = jinja2.FileSystemLoader("../drinkz/templates")
    env = jinja2.Environment(loader=loader)

    # pick up a filename to render
    filename = "pages.html"  # recipe nonsense
    recipeList = db.get_all_recipes()
    recipeNameList = list()
    for recipe in recipeList:
        if recipe.need_ingredients():
            val = "no"
        else:
            val = "yes"
        recipeNameList.append(recipe._recipeName + " " + val)

    # variables for the template rendering engine
    vars = dict(
        title="Recipe List",
        addtitle="Add Recipe",
        form="""<form action='addRecipe'>
Name<input type='text' name='name' size'20'><p>
Ingredients (eg.'vodka,5 oz,grape juice,10 oz')<input type='text' name='ing' size'20'><p>
<input type='submit'>
</form>""",
        names=recipeNameList,
    )

    try:
        template = env.get_template(filename)
    except Exception:  # for nosetests
        loader = jinja2.FileSystemLoader("./drinkz/templates")
        env = jinja2.Environment(loader=loader)
        template = env.get_template(filename)

    x = template.render(vars).encode("ascii", "ignore")
    return x
Esempio n. 25
0
    def recipes(self, environ, start_response):
        content_type = 'text/html'
        data = """\
        <html><head><title>Recipes - Drinkz - Alex Lockwood</title>
        <style type="text/css">
        h1 {color:red;}
        p {color:black;}
        </style></head><body>
        <h1>Recipe List</h1>
        <a href='/'>Return to Index</a><p>
        """

        for recipe in db.get_all_recipes():
            data += "<li> %s: " % recipe.name
            if not recipe.need_ingredients():
                data += "AVAILABLE"
            else:
                data += "NEED "
                for (l, a) in recipe.need_ingredients():
                    data += "%s - %sml, " % (l, a)

        data += "</p></body></html>"
        start_response('200 OK', list(html_headers))
        return [data]
Esempio n. 26
0
 def rpc_get_recipe_names(self):
     return [ r.name for r in db.get_all_recipes() ]
def getRecipeData():
    conn, cur = connect()
    recipes = get_all_recipes(conn)
    disconnect(conn, cur)
    return json.loads((json.dumps(recipes, indent=2)))
Esempio n. 28
0
 def rpc_get_recipe_names(self):
     recipe_list = []
     for r in db.get_all_recipes():
         recipe_list.append(r.name)
     return recipe_list
Esempio n. 29
0
    def rpc_get_recipe_names(self):
        lack = db.get_all_recipes()
        recipe = []
	for r in db.get_all_recipes():
		recipe.append(r.name)
	return recipe
Esempio n. 30
0
 def rpc_getrecipenames(self):
     return db.get_all_recipes()
Esempio n. 31
0
 def rpc_get_recipe_names(self):
     names = [] 
     for r in db.get_all_recipes():
         names.append(r.name)
     return names