コード例 #1
0
def index():
    ingredients = db.get_entities("ingredient", "user_id", flask_login.current_user.id)
    ingredient_map = {int(ingredient["id"]): ingredient for ingredient in ingredients}
    recipes = db.get_entities("recipe", "user_id", flask_login.current_user.id)
    recipe_map = {int(recipe["id"]): recipe for recipe in recipes}
    today_beginning = datetime.combine(date.today(), datetime.min.time()).isoformat()
    today_filter = ("date", ">", today_beginning)
    meals = db.get_entities(
        "meal", "user_id", flask_login.current_user.id, filters=[today_filter]
    )
    food_group_proportions = controller.get_food_group_proportions(meals)
    for recipe in recipes:
        for ingredient in recipe["ingredients"]:
            ingredient["name"] = ingredient_map[int(ingredient["id"])]["name"]
    for meal in meals:
        for portion in meal["portions"]:
            portion["name"] = recipe_map[int(portion["id"])]["name"]
    return render_template(
        "index.html",
        food_groups=food_groups.list_food_groups(),
        ingredients=ingredients,
        recipes=recipes,
        meals=meals,
        food_group_proportions=food_group_proportions,
    )
コード例 #2
0
 def test_get_entities(self, datastore):
     client = MagicMock()
     query = MagicMock()
     client.query.return_value = query
     query.fetch.return_value = [
         MockDict(id=1, name="entity1"),
         MockDict(id=2, name="entity2"),
     ]
     datastore.Client.return_value = client
     entities = db.get_entities("kind1")
     self.assertEqual(2, len(entities))
コード例 #3
0
def list_recipes(user_id):
    return db.get_entities("recipes", "user_id", user_id)
コード例 #4
0
def list_ingredients(user_id):
    return db.get_entities("ingredients", "user_id", user_id)
コード例 #5
0
def list_meals(user_id):
    return db.get_entities("meals", "user_id", user_id)