Ejemplo n.º 1
0
 def add_recipes(self):
     self.register_user()
     self.register_user2()
     user1 = User.query.filter_by(email='*****@*****.**').first()
     user2 = User.query.filter_by(
         email='*****@*****.**').first()
     recipe1 = Recipe('Hamburgers',
                      'Classic dish elevated with pretzel buns.', user1.id,
                      True)
     recipe2 = Recipe(
         'Mediterranean Chicken',
         'Grilled chicken served with pitas, hummus, and sauted vegetables.',
         user1.id, True)
     recipe3 = Recipe('Tacos', 'Ground beef tacos with grilled peppers.',
                      user1.id, False)
     recipe4 = Recipe('Homemade Pizza',
                      'Homemade pizza made using pizza oven', user1.id,
                      False)
     recipe5 = Recipe('Chicken Nuggets',
                      'Classic dish served with honey mustard', user2.id,
                      True)
     db.session.add(recipe1)
     db.session.add(recipe2)
     db.session.add(recipe3)
     db.session.add(recipe4)
     db.session.add(recipe5)
     db.session.commit()
Ejemplo n.º 2
0
 def create_recipes(self):
     user1 = User.query.filter_by(email=self.admin_email).first()
     recipe1 = Recipe('blah', 'boogie boogie', user1.id, True)
     recipe2 = Recipe(
         'Local Dev',
         'Pre-conditions: vbox+python+nginx+postgres are running.',
         user1.id, True)
     recipe3 = Recipe('Ops', 'TBD.', user1.id, False)
     db.session.add(recipe1)
     db.session.add(recipe2)
     db.session.add(recipe3)
     db.session.commit()
Ejemplo n.º 3
0
 def add_recipes(self):
     self.register_user()
     self.register_user2()
     user1 = User.query.filter_by(email='*****@*****.**').first()
     user2 = User.query.filter_by(email='*****@*****.**').first()
     recipe1 = Recipe('Local Dev', 'Pre-conditions: vbox+python+nginx+postgres are running.', user1.id, True)
     recipe2 = Recipe('QA', 'Pre-conditions: ecs+python+nginx+postgres are running.', user1.id, True)
     recipe3 = Recipe('Ops', 'TBD', user1.id, False)
     db.session.add(recipe1)
     db.session.add(recipe2)
     db.session.add(recipe3)
     db.session.add(recipe4)
     db.session.add(recipe5)
     db.session.commit()
Ejemplo n.º 4
0
def add_recipe():
    form = AddRecipeForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            filename = images.save(request.files['recipe_image'])
            url = images.url(filename)
            new_recipe = Recipe(form.recipe_title.data,
                                form.recipe_description.data, current_user.id,
                                form.is_public.data, filename, url)
            db.session.add(new_recipe)
            db.session.commit()

            # Lägg in varje ingrediens för recepete genom att loopa igenom det som skickades från formuläret
            for ingredient in request.form.getlist("ingredient[]"):
                ing = ingredient.split("-")
                ingredient_id = ing[0]
                quantity = ing[1]
                new_recipe_ingredient = RecipeHasIngredient(
                    new_recipe.id, ingredient_id, quantity)
                db.session.add(new_recipe_ingredient)
                db.session.commit()

            flash('New recipe, {}, added!'.format(new_recipe.recipe_title),
                  'success')
            return redirect(url_for('recipes.user_recipes'))
        else:
            #flash_errors(form)
            flash('ERROR! Recipe was not added.', 'error')
    else:

        return render_template('add_recipe.html', form=form)
Ejemplo n.º 5
0
def add_recipe():
    print( 'BEG add_recipe', flush=True )
    # Cannot pass in 'request.form' to AddRecipeForm constructor, as this will cause 'request.files' to not be
    # sent to the form.  This will cause AddRecipeForm to not see the file data.
    # Flask-WTF handles passing form data to the form, so not parameters need to be included.
    form = AddRecipeForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            # check if the post request has the recipe_image part
            if 'recipe_image' not in request.files:
                flash('No recipe image provided!')
                return redirect(request.url)

            file = request.files['recipe_image']

            if file.filename == '':
                flash('No selected file')
                return redirect(request.url)

            if not file:
                flash('File is empty!')
                return redirect(request.url)

            if file and allowed_file(file.filename):
                filename = secure_filename(file.filename)
                file.save(os.path.join(app.config['IMAGE_FOLDER'], filename))
                url = os.path.join(app.config['IMAGE_URL'], filename)
            else:
                filename = ''
                url = ''

            new_recipe = Recipe(form.recipe_title.data,
                                form.recipe_description.data,
                                current_user.id,
                                form.recipe_public.data,
                                filename,
                                url,
                                form.recipe_type.data,
                                form.recipe_rating.data,#  or None,
                                form.recipe_ingredients.data,
                                form.recipe_steps.data,
                                form.recipe_inspiration.data,
                                form.recipe_dairy_free.data,
                                form.recipe_soy_free.data)
            db.session.add(new_recipe)
            db.session.commit()
            if 'ACCOUNT_SID' in app.config and not app.config['TESTING'] and not app.config['DEBUG']:
                new_user = User.query.filter_by(id=new_recipe.user_id).first()
                send_new_recipe_text_message(new_user.email, new_recipe.recipe_title)
            flash('New recipe, {}, added!'.format(new_recipe.recipe_title), 'success')
            return redirect(url_for('recipes.user_recipes', recipe_type='All'))
        else:
            flash_errors(form)
            flash('ERROR! Recipe was not added.', 'error')

    return render_template('add_recipe.html', form=form)
Ejemplo n.º 6
0
 def create_recipes(self):
     user1 = User.query.filter_by(email=self.admin_email).first()
     recipe1 = Recipe('Hamburgers',
                      'Classic dish elevated with pretzel buns.', user1.id,
                      True)
     recipe2 = Recipe(
         'Mediterranean Chicken',
         'Grilled chicken served with pitas, hummus, and sauted vegetables.',
         user1.id, True)
     recipe3 = Recipe('Tacos', 'Ground beef tacos with grilled peppers.',
                      user1.id, False)
     recipe4 = Recipe('Homemade Pizza',
                      'Homemade pizza made using pizza oven', user1.id,
                      False)
     db.session.add(recipe1)
     db.session.add(recipe2)
     db.session.add(recipe3)
     db.session.add(recipe4)
     db.session.commit()
Ejemplo n.º 7
0
def add_recipe():
    form = AddRecipeForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            new_recipe = Recipe(form.recipe_title.data, form.recipe_description.data)
            db.session.add(new_recipe)
            db.session.commit()
            flash('New recipe, {}, added!'.format(new_recipe.recipe_title), 'success')
            return redirect(url_for('recipes.index'))
        else:
            flash_errors(form)
            flash('ERROR! Recipe was not added.', 'error')
    return render_template('add_recipe.html', form=form)
Ejemplo n.º 8
0
    def test_create_new_recipe_required_parameters(self):
        newTitle = 'bolo2'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'

        with self.client:
            test_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_data)

            recipe = Recipe(titulo=newTitle,
                            ingredientes=newIngredients,
                            modo_preparo=newDirections,
                            latest_change_date=datetime.now(),
                            autor=newAuthor)

            self.assertEqual(recipe.titulo, newTitle)
            self.assertEqual(recipe.ingredientes, newIngredients)
            self.assertEqual(recipe.modo_preparo, newDirections)
Ejemplo n.º 9
0
def save_new_recipe(title,
                    ingredients,
                    directions,
                    author,
                    time=None,
                    text=None,
                    image=None):
    recipe = Recipe(titulo=title,
                    ingredientes=ingredients,
                    modo_preparo=directions,
                    latest_change_date=datetime.now(),
                    autor=author,
                    tempo_preparo=time,
                    texto=text,
                    imagem=upload_file(image) if image != None else image,
                    reviews=0,
                    stars=0)

    db.session.add(recipe)
    db.session.commit()
    return recipe
Ejemplo n.º 10
0
def add_recipe():
    # Cannot pass in 'request.form' to AddRecipeForm constructor, as this will cause 'request.files' to not be
    # sent to the form.  This will cause AddRecipeForm to not see the file data.
    # Flask-WTF handles passing form data to the form, so not parameters need to be included.
    form = AddRecipeForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            filename = images.save(request.files['recipe_image'])
            url = images.url(filename)
            new_recipe = Recipe(form.recipe_title.data,
                                form.recipe_description.data, current_user.id,
                                True, filename, url)
            db.session.add(new_recipe)
            db.session.commit()
            flash("New Recipe, {}, added!".format(new_recipe.recipe_title),
                  'success')
            return redirect(url_for('recipes.user_recipes'))
        else:
            flash_errors(form)
            flash("ERROR! Recipe was not added.", 'error')
    return render_template('add_recipe.html', form=form)
Ejemplo n.º 11
0
def add_recipe():
    # Cannot pass in 'request.form' to AddRecipeForm constructor, as this will cause 'request.files' to not be
    # sent to the form.  This will cause AddRecipeForm to not see the file data.
    # Flask-WTF handles passing form data to the form, so not parameters need to be included.
    form = AddRecipeForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            filename = images.save(request.files['recipe_image'])
            url = images.url(filename)
            new_recipe = Recipe(
                form.recipe_title.data,
                form.recipe_description.data,
                current_user.id,
                form.recipe_public.data,
                filename,
                url,
                form.recipe_type.data,
                form.recipe_rating.data,  #  or None,
                form.recipe_ingredients.data,
                form.recipe_steps.data,
                form.recipe_inspiration.data,
                form.recipe_tested.data,
                form.recipe_verified_free.data)
            db.session.add(new_recipe)
            db.session.commit()
            if 'ACCOUNT_SID' in app.config and not app.config['TESTING']:
                new_user = User.query.filter_by(id=new_recipe.user_id).first()
                send_new_recipe_text_message(new_user.email,
                                             new_recipe.recipe_title)
            flash('New recipe, {}, added!'.format(new_recipe.recipe_title),
                  'success')
            return redirect(url_for('recipes.user_recipes', recipe_type='All'))
        else:
            flash_errors(form)
            flash('ERROR! Recipe was not added.', 'error')

    return render_template('add_recipe.html', form=form)
Ejemplo n.º 12
0
def api1_2_create_recipe():
    new_recipe = Recipe()
    new_recipe.import_data(request)
    db.session.add(new_recipe)
    db.session.commit()
    return jsonify({}), 201, {'Location': new_recipe.get_url()}
Ejemplo n.º 13
0
from project import db
from project.models import Recipe

#Drop all tables
db.drop_all()

# create the database and the database table
db.create_all()

# insert recipe data
recipe1 = Recipe(
    'Slow-Cooker Tacos',
    'Delicious ground beef that has been simmering in taco seasoning and sauce.  Perfect with hard-shelled tortillas!'
)
recipe2 = Recipe('Hamburgers', 'Classic dish elivated with pretzel buns.')
recipe3 = Recipe(
    'Mediterranean Chicken',
    'Grilled chicken served with pitas, hummus, and sauted vegetables.')
db.session.add(recipe1)
db.session.add(recipe2)
db.session.add(recipe3)

# commit the changes
db.session.commit()
Ejemplo n.º 14
0
ingre4 = Ingre(ingrename="fish slice", url="../static/img/FishSlice.jpg")
ingre5 = Ingre(ingrename="water", url="../static/img/Water.jpg")
ingre6 = Ingre(ingrename="soy sauce", url="../static/img/SoySauce.jpg")
ingre7 = Ingre(ingrename="green onion", url="../static/img/GreenOnions.jpg")
ingre8 = Ingre(ingrename="bitter melon", url="../static/img/BitterMelon.jpg")
ingre9 = Ingre(ingrename="mayonnaise", url="../static/img/Mayonnaise.jpg")
ingre10 = Ingre(ingrename="prickly ash", url="../static/img/PricklyAsh.jpg")
ingre11 = Ingre(ingrename="thick bean sauce", url="../static/img/ThickBeanSauce.jpg")

db.session.add_all([ingre1, ingre2, ingre3, ingre4, ingre5, ingre6, ingre7, ingre8, ingre9, ingre10, ingre11])

instruct1 = "Hello! Welcome to my kitchen.|Today I am going to teach you how to cook the sliced cold chicken.|Cut a chicken to small pieces|add|add|Boil the chicken for 10 mins|Poul out all the water|add|Cut the greenonions|add|Congratuations! You have finished learning this dish!"
instruct2 = "Hello! Welcome to my kitchen.|Today I am going to teach you how to cook the Sichuan fish.|add|add|add|Fry 5min|add|Boil for 10mins.|add|Boil for 6mins|Congratuations! You have finished learning this dish!"
instruct3 = "Hello! Welcome to my kitchen.|Today I am going to teach you how to cook the bitter shrimp ball.|Slice the bitter melon and put it at the bottom.|add|add|add|Steam for 20mins|add|Congratuations! You have finished learning this dish!"

recipe1 = Recipe(id=1,recipename="sliced_cold_chicken", ingresorder="2 5 6 7", instruction = instruct1)
recipe2 = Recipe(id=2,recipename="sichuan_fish", ingresorder="11 10 1 5 4", instruction = instruct2)
recipe3 = Recipe(id=3,recipename="bitter_shrimp_ball", ingresorder="8 3 9 7", instruction = instruct3)
recipe4 = Recipe(id=4,recipename="crystal_shrimp", ingresorder="1", instruction = " ")
recipe5 = Recipe(id=5,recipename="buddha_Jumps_over_the_wall", ingresorder="1", instruction = " ")
recipe6 = Recipe(id=6,recipename="steamed_preserved_hams", ingresorder="1", instruction = " ")
recipe7 = Recipe(id=7,recipename="phoenix_peony_stew", ingresorder="1", instruction = " ")
recipe8 = Recipe(id=8,recipename="jellyfish_with_vinegar", ingresorder="1", instruction = " ")



recipe1.add_ingres([ingre2, ingre5, ingre6, ingre7])
recipe2.add_ingres([ingre4, ingre1, ingre5, ingre11, ingre10])
recipe3.add_ingres([ingre8, ingre3, ingre9, ingre7])

Ejemplo n.º 15
0
ingre9 = Ingre(ingrename="mayonnaise", url="../static/img/Mayonnaise.jpg")
ingre10 = Ingre(ingrename="prickly ash", url="../static/img/PricklyAsh.jpg")
ingre11 = Ingre(ingrename="thick bean sauce",
                url="../static/img/ThickBeanSauce.jpg")

db.session.add_all([
    ingre1, ingre2, ingre3, ingre4, ingre5, ingre6, ingre7, ingre8, ingre9,
    ingre10, ingre11
])

instruct1 = "Hello! Welcome to my kitchen.|Today I am going to teach you how to cook the sliced cold chicken.|Cut a chicken to small pieces|add|add|Boil the chicken for 10 mins|Poul out all the water|add|Cut the greenonions|add|Congratuations! You have finished learning this dish!"
instruct2 = "Hello! Welcome to my kitchen.|Today I am going to teach you how to cook the Sichuan fish.|add|add|add|Fry 5min|add|Boil for 10mins.|add|Boil for 6mins|Congratuations! You have finished learning this dish!"
instruct3 = "Hello! Welcome to my kitchen.|Today I am going to teach you how to cook the bitter shrimp ball.|Slice the bitter melon and put it at the bottom.|add|add|add|Steam for 20mins|add|Congratuations! You have finished learning this dish!"

recipe1 = Recipe(id=1,
                 recipename="sliced_cold_chicken",
                 ingresorder="2 5 6 7",
                 instruction=instruct1)
recipe2 = Recipe(id=2,
                 recipename="sichuan_fish",
                 ingresorder="11 10 1 5 4",
                 instruction=instruct2)
recipe3 = Recipe(id=3,
                 recipename="bitter_shrimp_ball",
                 ingresorder="8 3 9 7",
                 instruction=instruct3)
recipe4 = Recipe(id=4,
                 recipename="crystal_shrimp",
                 ingresorder="1",
                 instruction=" ")
recipe5 = Recipe(id=5,
                 recipename="buddha_Jumps_over_the_wall",
Ejemplo n.º 16
0
ingredient5 = Ingredient(name='Nötfärs', measurement_unit='Gram')
ingredient6 = Ingredient(name='Cheddarost', measurement_unit='Gram')
ingredient7 = Ingredient(name='Ryggbiff', measurement_unit='Gram')
ingredient8 = Ingredient(name='Salt', measurement_unit='Gram')
ingredient9 = Ingredient(name='Peppar', measurement_unit='Gram')
ingredient10 = Ingredient(name='Soja', measurement_unit='Centiliter')
ingredient11 = Ingredient(name='Olivolja', measurement_unit='Deciliter')
ingredient12 = Ingredient(name='Rapsolja', measurement_unit='Deciliter')
ingredient13 = Ingredient(name='Timjan', measurement_unit='Gram')
ingredient14 = Ingredient(name='Basilika', measurement_unit='Gram')

# insert recipe data
recipe1 = Recipe(
    title='Hembakat surdegsbröd',
    description=
    'Underbart hembakat surdegsbröd, luftigt och knaprigt precis som om du hade köpt det på ditt favorit bageri.',
    image_filename='bread.jpeg',
    image_url="http://localhost:5000/static/img/bread.jpeg",
    user_id='4',
    is_public=True)
recipe2 = Recipe(
    title='Håll-käften-burgare',
    description=
    'En burgare fit for a king, hoppas du tog med dig din aptit för denna burgaren kommmer du inte avsluta hungrig.',
    image_filename='burgare.jpeg',
    image_url="http://localhost:5000/static/img/burgare_1.jpeg",
    user_id='4',
    is_public=True)
recipe3 = Recipe(
    title='Pannkakor',
    description=
    'Luftiga amerikanska pannkakor, perfekta själva men häll på lite sirap eller sylt för en otrolig upplevelse.',