def seed_db():
    from models.Recipe import Recipe
    from models.User import User
    from main import bcrypt
    from faker import Faker
    import random

    faker = Faker()
    users = []

    for i in range(5):
        user = User()
        user.email =  f"test{i}@test.com"
        user.password = bcrypt.generate_password_hash("123456").decode("utf-8")
        db.session.add(user)
        users.append(user)
    
    db.session.commit()

    for i in range(10):
        recipe = Recipe()
        recipe.recipe_name = faker.catch_phrase()
        recipe.description = faker.catch_phrase()
        recipe.user_id = random.choice(users).user_id
        db.session.add(recipe)
        print(f"{i + 1} recipe record(s) created")

    db.session.commit()
    print("Tables seeded")
def recipe_create(user=None):
    #Create a new recipe
    recipe_fields = recipe_schema.load(request.json)

    new_recipe = Recipe()
    new_recipe.recipe_name = recipe_fields["recipe_name"]
    new_recipe.description = recipe_fields["description"]

    user.recipes.append(new_recipe)

    db.session.commit()
    
    return jsonify(recipe_schema.dump(new_recipe))
Exemple #3
0
def create(recipe):
    name = recipe.get("name", None)
    nbr_person = recipe.get("nbr_person", None)
    id_src = recipe.get("id_src", None)
    recipe = Recipe(None, name, nbr_person, id_src)
    id_recipe = RecipeDAOimpl.insert(recipe)
    json.dumps(id_recipe)
    return id_recipe
def findBySource(id_source):
    conn = ConnectionDB().getConnection()
    cursor = conn.cursor()

    try:
        recipes = []
        for row in cursor.execute("SELECT * FROM recipes WHERE recipes.id_src = ?", (id_source,)):
            recipes.append(Recipe(row[0], row[1], row[2], row[3]))
        return recipes
    except sqlite3.Error as error:
        print(error.with_traceback())
def findAll():
    conn = ConnectionDB().getConnection()
    cursor = conn.cursor()

    try:
        recipes = []
        for row in cursor.execute("SELECT * FROM recipes"):
            recipes.append(Recipe(row[0], row[1], row[2], row[3]))
        return recipes
    except sqlite3.Error as error:
        print(error.with_traceback())
def findOneByName(name):
    conn = ConnectionDB().getConnection()
    cursor = conn.cursor()

    try:
        cursor.execute('SELECT * FROM recipes WHERE name = ?', (name,))
        row = cursor.fetchone()
        recipe = Recipe(row[0], name, row[2], row[3])
        return recipe
    except sqlite3.Error as error:
        print(error.with_traceback())
Exemple #7
0
def add_recipe():
    db = db_connection()
    recipe_cod = request.form['recipe_cod']
    recipe_name = request.form['recipe_name']
    solid = request.form['solid']
    liquid1 = request.form['liquid1']
    liquid2 = request.form['liquid2']
    powder = request.form['powder']
    blend_time = request.form['blend_time']
    recipe = Recipe(recipe_cod, recipe_name, solid, liquid1, liquid2, powder,
                    blend_time)
    recipeDao = RecipeDao(db)
    recipeDao.addRecipe(recipe)
    return redirect('receitas')
def findByTool(id_tool):
    conn = ConnectionDB().getConnection()
    cursor = conn.cursor()

    try:
        recipes = []
        for row in cursor.execute('''
            SELECT recipes.id, recipes.name, recipes.nbr_person, recipes.id_src FROM recipes
            JOIN map_recipe_tool on recipes.id=map_recipe_tool.id_recipe
            WHERE map_recipe_tool.id_tool = ?
                ''', (id_tool,)):
            recipes.append(Recipe(row[0], row[1], row[2], row[3]))
        return recipes
    except sqlite3.Error as error:
        print(error.with_traceback())
Exemple #9
0
    def _save_recipe(self):
        type = self._type_entry.get()
        code = self._code_entry.get()
        name = self._name_entry.get()
        dosage = self._dosage_entry.get()
        date_from = self._from_entry.get()
        date_to = self._to_entry.get()

        recipe = Recipe(type, code, name, dosage, date_from, date_to)

        PatientRepository.get_instance().remove_recipe(
            self.selected_patient.data['pin'], self._selected_recipe)
        PatientRepository.get_instance().add_recipe(
            self.selected_patient.data['pin'], recipe)

        messagebox.showinfo("Update", "Recipe succesfully updated")
def findByIngredient(id_ingredient):
    conn = ConnectionDB().getConnection()
    cursor = conn.cursor()

    try:
        recipes = []
        for row in cursor.execute('''
            SELECT recipes.id, recipes.name, recipes.nbr_person, recipes.id_src FROM recipes
            JOIN sections ON sections.id_recipe=recipes.id
            JOIN map_section_ingredient ON sections.id=map_section_ingredient.id_section
            WHERE map_section_ingredient.id_ingredient = ?
                ''', (id_ingredient,)):
            recipes.append(Recipe(row[0], row[1], row[2], row[3]))
        return recipes
    except sqlite3.Error as error:
        print(error.with_traceback())
Exemple #11
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)
Exemple #12
0
    def _save_patient(self):
        type = self._type_entry.get()
        code = self._code_entry.get()
        name = self._name_entry.get()
        dosage = self._dosage_entry.get()
        from_date = self._from_entry.get()
        to_date = self._to_entry.get()

        recipe = Recipe(type, code, name, dosage, from_date, to_date)

        PatientRepository.get_instance().add_recipe(
            self._recipe_frame.selected_patient.data['pin'], recipe)

        messagebox.showinfo("Insert", "Recipe succesfully inserted")

        self._recipe_frame.fill_list(self._recipe_frame.selected_patient)

        self._master.destroy()
Exemple #13
0
 def getRecipeById(self, id):
     cursor = self.__db.cursor()
     cursor.execute(SQL_BY_ID, (id, ))
     obj = cursor.fetchone()
     return Recipe(obj[0], obj[1], obj[2], obj[3], obj[4], obj[5], obj[6],
                   id)
Exemple #14
0
def update(id_recipe, recipe):
    name = recipe.get("name", None)
    nbr_person = recipe.get("nbr_person", None)
    id_src = recipe.get("id_src", None)
    recipe = Recipe(id_recipe, name, nbr_person, id_src)
    RecipeDAOimpl.update(recipe)