def try_remove_ingredient(sandwich_id, ingredient_id):
    sandwich = get_by_id(sandwich_id)
    ingredient = Ingredient.get_by_id(ingredient_id)

    if sandwich and ingredient:
        models.SandwichIngredient.objects.get(ingredient=ingredient,
                                              sandwich=sandwich).delete()
Exemple #2
0
    def setUp(self):
        ingredient = Ingredient.create("Pão")
        Ingredient.set_value(ingredient, 1.25)
        ingredient = Ingredient.create("Hamburger")
        Ingredient.set_value(ingredient, 1)
        ingredient = Ingredient.create("Bacon")
        Ingredient.set_value(ingredient, 2)

        name = "X-Bacon"
        list = ["Pão", "Hamburger", "Bacon"]
        profit = 5.5
        sandwich = Sandwich.create(name, profit, list)

        beverage = Beverage.create("Coca-cola", "2 Litros", 6)
Exemple #3
0
def create(request):
    dados = {
        'title': 'Criação de lanches',
        'header': 'Novo lanche',
        'icon': 'fas fa-hamburger',
        'ingredients': Ingredient.get_all_with_price()
    }

    return render(request, 'sandwich/create.html', dados)
Exemple #4
0
def edit(request, id):
    if id:
        dados = {
            'title': 'Atualizar ingrediente',
            'header': 'Atualizar ingrediente',
            'icon': 'fas fa-bacon',
            'ingredient': Ingredient.get_info_by_id(id)
        }

        return render(request, 'ingredient/create.html', dados)
    else:
        messages.error(request, "Erro no envio")
def filter(search):
    sandwichs = list(models.Sandwich.objects.filter(name__contains=search))

    ingredients = Ingredient.filter(search)
    for ingredient in ingredients:
        itens = models.SandwichIngredient.objects.filter(ingredient=ingredient)

        for item in itens:
            if item.sandwich not in sandwichs:
                sandwichs.append(item.sandwich)

    return sandwichs
Exemple #6
0
def edit(request, id):
    if id:
        dados = {
            'title': 'Editar lanche',
            'header': 'Editar lanche',
            'icon': 'fas fa-hamburger',
            'sandwich': Sandwich.get_by_id(id),
            'ingredients': Ingredient.get_all_with_price()
        }

        return render(request, 'sandwich/create.html', dados)
    else:
        messages.error(request, "ID nao encontrado")

    return redirect('/sandwich/list')
Exemple #7
0
def filter_submit(request):
    if request.GET:
        name = request.GET.get("name")
        if name:
            ingredients = Ingredient.filter(name)

            if len(ingredients) > 0:
                return return_list(request, ingredients)
            else:
                messages.error(request, 'Ingrediente nao encontrado')
        else:
            messages.error(request, 'Nome não pode estar em branco')
    else:
        messages.error(request, 'Erro durante a solicitação')

    return redirect('/ingredient/filter')
Exemple #8
0
def create_submit(request):
    if request.POST:
        name = request.POST.get("name")
        price = request.POST.get("price")
        if name:
            if price:
                ingredient = Ingredient.get_by_name(name)
                if ingredient is None:
                    create_execute(name, price)
                else:
                    messages.error(request,
                                   'Ingrediente com mesmo nome ja cadastrado')
            else:
                messages.error(request, 'Preço não pode estar em branco')
        else:
            messages.error(request, 'Nome não pode estar em branco')
    else:
        messages.error(request, 'Erro durante envio')

    return redirect('/ingredient/menu')
Exemple #9
0
def edit_execute(id, name, price):
    Ingredient.update(id, name, price)
Exemple #10
0
 def test_get_value_ingredient_all(self):
     ingredients = Ingredient.get_all_with_price()
     self.assertEqual(ingredients[0].price.value, 2)
     self.assertEqual(ingredients[1].price.value, 1)
Exemple #11
0
 def test_get_value_ingredient(self):
     ingredient = Ingredient.get_info_by_id(1)
     self.assertEqual(ingredient.price.value, 1.25)
Exemple #12
0
 def test_set_value_ingredient_id_2(self):
     ingredient = Ingredient.get_by_id(2)
     ingredient_value = Ingredient.set_value(ingredient, 1.25)
     self.assertEqual(ingredient_value.value, 1.25)
Exemple #13
0
 def test_create_ingredient(self):
     ingredient = Ingredient.create("Alface")
     self.assertEqual(ingredient.id, 4)
Exemple #14
0
def sandwich_recipe(sandwich, ingredient_name):
    ingredient = Ingredient.get_by_name(ingredient_name)

    if ingredient:
        models.SandwichIngredient.objects.create(sandwich=sandwich,
                                                 ingredient=ingredient)
Exemple #15
0
 def test_get_ingredient_by_id(self):
     ingredient = Ingredient.get_by_id(1)
     self.assertEqual(ingredient.name, "Pão")
Exemple #16
0
 def test_filter_ingredient(self):
     ingredients = Ingredient.filter('Pã')
     self.assertNotEqual(len(ingredients),0)
Exemple #17
0
 def test_get_all_ingredient(self):
     ingredients = Ingredient.get_all()
     self.assertIsNotNone(ingredients)
Exemple #18
0
 def test_get_ingredient_by_name(self):
     ingredient = Ingredient.get_by_name('Hamburger')
     self.assertEqual(ingredient.id, 2)
Exemple #19
0
def create_execute(name, price):
    ingredient = Ingredient.create(name)
    Ingredient.set_value(ingredient, price)
Exemple #20
0
def list(request):
    return return_list(request, Ingredient.get_all())
Exemple #21
0
    def test_get_ingredient_update(self):
        Ingredient.update(2, "Bacon", 2.45)
        ingredient = Ingredient.get_info_by_id(2)

        ingredient.price.value = float(ingredient.price.value)
        self.assertEqual(ingredient.price.value, 2.45)
Exemple #22
0
 def test_get_ingredient_update_name(self):
     Ingredient.update_name(2, "Bacon")
     ingredient = Ingredient.get_by_id(2)
     self.assertEqual(ingredient.name, "Bacon")
Exemple #23
0
 def test_set_value_ingredient_id_1(self):
     ingredient = Ingredient.get_by_id(1)
     ingredient_value = Ingredient.set_value(ingredient, 1.50)
     self.assertEqual(ingredient_value.value, 1.5)