Ejemplo n.º 1
0
def updateIngredient(request, ingredientID):
    template = 'food/updateIngredient.html'
    try:
        ingredient = Ingredient.objects.get(id=ingredientID)
    except Ingredient.DoesNotExist:
        return category(request, '')
    if request.method=='GET':
        form = IngredientForm(instance=ingredient)
        return render(request, template, {'form':form, 'ingredient':ingredient})
    # request.method=='POST'
    form = IngredientForm(request.POST, instance=ingredient)
    if not form.is_valid():
        return render(request, template, {'form':form, 'ingredient':ingredient})
    ingredient.save()
    return redirect(reverse('food:category', args=(ingredient.category.id,)))
Ejemplo n.º 2
0
def addIngredient(request, categoryID):
    template = 'food/addIngredient.html'
    try:
        IngredientCategory = Category.objects.get(id=categoryID)
    except Category.DoesNotExist:
        return category(request, categoryID)
    context = {'category':IngredientCategory}
    if request.method=='GET':
        context['form'] = IngredientForm()
        return render(request, template, context)
    # request.method=='POST'
    form = IngredientForm(request.POST)
    context['form'] = form
    if not form.is_valid():
            return render(request, template, context)
    Ingredient = form.save(commit=False)
    Ingredient.category = IngredientCategory
    Ingredient.save()
    return redirect(reverse('food:category', args=(categoryID, )))  
Ejemplo n.º 3
0
def description(request):
    if request.method == 'GET':
        recipe_id = request.GET.get('id', '')
        recipe = Recipe.objects.get(id=recipe_id)
        recipe_ingredients = Ingredient.objects.select_related().filter(
            recipe=recipe.id)
        return render(request, 'description.html', {
            'recipe': recipe,
            'ingredients': recipe_ingredients
        })
    else:
        form = IngredientForm()
    return render(request, 'ingredients.html', {'form': form})
Ejemplo n.º 4
0
def ingredients(request):
    if request.method == 'POST':
        form = IngredientForm(request.POST)
        user = request.user
        profile = Profile.objects.get(user__username=user)

        if form.is_valid():
            ingredients_recipes = list()
            ingredients_str = form.cleaned_data.get('ingredients')
            recetario = Recipe.objects.filter(
                ingredient__name__contains=ingredients_str)

            # Recomender system (content based)
            data = pd.read_csv('scraping/recipes.csv',
                               error_bad_lines=False,
                               delimiter=";",
                               encoding='latin-1')
            data.head(3)
            content_based = cB.ContentBased()
            content_based.fit(data, 'recipe_str')
            predict = content_based.predict([ingredients_str])
            recipes_predict = predict.get('title').values
            if len(recipes_predict) > 0:
                search = Search(profile=profile,
                                tags=ingredients_str,
                                date=datetime.date.today())
                search.save()
            for recipe in recipes_predict:
                a = Recipe.objects.filter(title=recipe)
                ingredients_recipes.append(a[0])
            return render(request, 'recipes.html',
                          {'recipes': ingredients_recipes})

    else:
        form = IngredientForm()
    return render(request, 'ingredients.html', {'form': form})