Ejemplo n.º 1
0
 def post(self):
   print "New drink handler."
   try:
     drink_name = self.request.get('drink_name')
     user_name = self.request.get('user_name')
     ingredient_list = []
     if drink_name == "Random Sour":
       recipe = RandomSourDrink()
     elif drink_name == "Random Bitter":
       recipe = RandomSpirituousDrink()
     else:
       for arg in self.request.arguments():
         print "%s -> %s" % (arg, self.request.get(arg))
         if "ingredient=" in arg:
           parts = float(self.request.get(arg))
           ingredient = arg.replace("ingredient=", "")
           ingredient_list.append(manual_db.Ingredient(manual_db.Oz(parts), ingredient))
       ingredients.ScaleDrinkSize(ingredient_list)
       recipe = manual_db.Recipe(drink_name, ingredient_list, user_name=user_name)
     recipe.user_name = user_name
     controller.EnqueueGroup(actions_for_recipe(recipe))
     self.response.status = 200
     self.response.write("ok")
   except ValueError:
     self.response.status = 400
     self.response.write("valve and oz arguments are required.")
Ejemplo n.º 2
0
 def post(self):
     name = self.request.get('name')
     if name:
         for drink in manual_db.db:
             if drink.name.lower() == name.lower():
                 self.response.write("Making drink %s" % drink)
                 controller.EnqueueGroup(actions_for_recipe(drink))
                 return
     elif self.request.get('random') == 'sour':
         controller.EnqueueGroup(actions_for_recipe(RandomSourDrink()))
     elif self.request.get('random') == 'spirituous':
         controller.EnqueueGroup(actions_for_recipe(
             RandomSpirituousDrink()))
     self.response.status = 400
Ejemplo n.º 3
0
def recipe_from_json_object(recipe_obj):
  """Takes a dict decoded from a JSON recipe and returns a Recipe object."""
  recipe = Recipe.from_json(recipe_obj)
  if not recipe.ingredients:
    if recipe_obj['drink_name'] == "Random Sour":
      recipe = RandomSourDrink()
      recipe.user_name = recipe_obj['user_name']
    elif recipe_obj['drink_name'] == "Random Boozy":
      recipe = RandomSpirituousDrink()
      recipe.user_name = recipe_obj['user_name']
    elif recipe_obj['drink_name'] == "Random Bubbly Boozy":
      recipe = RandomBubblySpirituousDrink()
      recipe.user_name = recipe_obj['user_name']
    elif recipe_obj['drink_name'] == "Random Bubbly Sour":
      recipe = RandomBubblySourDrink()
      recipe.user_name = recipe_obj['user_name']
  recipe = water_down_recipe(recipe)
  return recipe