Beispiel #1
0
    def preload_functions(self, data, **kwargs):
        recipe_schema = RecipeSchema(exclude=("recipe_lines", "_links"))

        if data.get("recipes"):
            self.add_loaded_recipes(data, recipe_schema)
        else:
            data["recipes"] = []
        self.create_additional_ingredients(data, recipe_schema)

        return data
Beispiel #2
0
from grocerylistapp.errors.exceptions import NotFoundException, InvalidUsage
from grocerylistapp.ingredient.schemas import IngredientSchema
from grocerylistapp.line.schemas import RecipeLineSchema
from grocerylistapp.recipe.schemas import RecipeSchema
from grocerylistapp.grocerylist.schemas import GroceryListSchema
from grocerylistapp.user.schemas import PostUserSchema
from grocerylistapp import db

from marshmallow import ValidationError
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import FlushError

ingredient_schema = IngredientSchema()
recipeline_schema = RecipeLineSchema()
recipe_schema = RecipeSchema()
grocerylist_schema = GroceryListSchema()
user_schema = PostUserSchema()

base_schemas_to_models = {
    "ingredient": ingredient_schema,
    "recipe_line": recipeline_schema,
    "recipe": recipe_schema,
    "grocery_list": grocerylist_schema,
    "user": user_schema
}


def get_resource_or_404(resource_type, identifier):
    if type(identifier) == str:  # only used for ingredients
        resource = resource_type.query.filter_by(name=identifier).first()
Beispiel #3
0
from marshmallow import ValidationError

from grocerylistapp import db
from grocerylistapp.models import Recipe
from grocerylistapp.utils import get_resource_or_404, post_new_resource, put_resource
from grocerylistapp.errors.exceptions import InvalidUsage
from grocerylistapp.recipe.utils import get_recipe_by_params
from grocerylistapp.recipe.schemas import RecipeSchema
from grocerylistapp.line.schemas import RecipeLineSchema
from grocerylistapp.ingredient.schemas import IngredientSchema
from grocerylistapp.user.schemas import UserSchema

recipe = Blueprint('recipe', __name__)
ingredient_schema = IngredientSchema()
ingredients_schema = IngredientSchema(many=True)
recipe_schema = RecipeSchema()
recipes_schema = RecipeSchema(many=True)
recipeline_schema = RecipeLineSchema()
recipelines_schema = RecipeLineSchema(many=True)
user_schema = UserSchema()


@recipe.route("/api/recipes", methods=["GET"])
def get_recipes():
    recipes = get_recipe_by_params(request.args)
    print("loaded recipes")
    print(recipes)
    print(recipes_schema.dump(recipes))
    return jsonify(recipes_schema.dump(recipes))

Beispiel #4
0
def get_additional_ingredients(id_):
    list_to_get = get_resource_or_404(GroceryList, id_)
    recipe_schema = RecipeSchema()
    return jsonify(recipe_schema.dump(list_to_get.additional_ingredients))