Пример #1
0
def delete_full(id_recipe):
    for section in SectionDAOimpl.findByRecipe(id_recipe):
        InstructionDAOimpl.deleteBySection(section.id_sec)
        SectionDAOimpl.eraseAllMappingBySection(section.id_sec)
        SectionDAOimpl.deleteById(section.id_sec)
    for image in ImageDAOImpl.findByRecipe(id_recipe):
        ImageDAOImpl.deleteById(image.id_img)
    RecipeDAOimpl.eraseCategoryMapping(id_recipe)
    RecipeDAOimpl.eraseToolMapping(id_recipe)
    RecipeDAOimpl.deleteById(id_recipe)
def create(image):
    name = image.get("name", None)
    id_recipe = image.get("id_recipe", None)
    image = Image(None, name, id_recipe)
    id_img = ImageDAOImpl.insert(image)
    json.dumps(id_img)
    return id_img
Пример #3
0
def create_recipe(recipe):
    name_recipe = recipe.get("name_recipe", None)
    nbr_person = recipe.get("nbr_person", None)
    id_src = recipe.get("id_src", None)
    if id_src == 0:
        id_src = None

    recipe_to_insert = Recipe(None, name_recipe, nbr_person, id_src)
    id_recipe = RecipeDAOimpl.insert(recipe_to_insert)

    for img in recipe.get("images", None):
        ImageDAOImpl.insert(Image(None, img.get("name", None), id_recipe))
    for id_cat in recipe.get("id_cats", None):
        RecipeDAOimpl.addCategory(id_recipe, id_cat)
    for id_tool in recipe.get("id_tools", None):
        RecipeDAOimpl.addTool(id_recipe, id_tool)
    for section in recipe.get("sections", None):
        SectionsRestController.add_section(id_recipe, section)
def delete(id_img):
    image = ImageDAOImpl.findOneById(id_img)
    if os.path.exists(folder + image.name):
        os.remove(folder + image.name)
    ImageDAOImpl.deleteById(id_img)
def update(id_img, image):
    name = image.get("name", None)
    id_recipe = image.get("id_recipe", None)
    image = Image(id_img, name, id_recipe)
    ImageDAOImpl.update(image)
def read_one(id_img):
    return ImageDAOImpl.findOneById(id_img).to_dict()
def read_by_recipe(id_recipe):
    images = []
    for image in ImageDAOImpl.findByRecipe(id_recipe):
        images.append(image.to_dict())
    json.dumps(images)
    return images
def read_all():
    images = []
    for image in ImageDAOImpl.findAll():
        images.append(image.to_dict())
    json.dumps(images)
    return images