<commit_before>from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from .models import CookedAt, Recipe
from .forms import CookedAtForm, RecipeForm
from django.http import JsonResponse
from django.contrib import auth
from django.contrib import messages
import logging


def login(request):
    """
    Handle authentication
    :param request:
    :return:
    """
    if request.user.is_authenticated:
        return redirect('create')
    if request.method == "POST":
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = auth.authenticate(username=username, password=password)
        if user:
            auth.login(request, user)
            # return redirect('recipes')
            return redirect('create')
        else:
            messages.error(request, 'Username/Password is not valid!')
            return redirect('/')
    else:
        return render(request, 'login.html')


@login_required
def create(request):
    if request.method == 'POST' and request.content_type == 'application/json':
        logger = logging.getLogger(__name__)
        recipe_form = RecipeForm(request.POST)
        direction_form = DirectionForm(request.POST)
        ingredient_form = IngredientForm(request.POST)
        if recipe_form.is_valid() and direction_form.is_valid() and ingredient_form.is_valid():
            validated_recipe = recipe_form.save(commit=False)
            validated_direction = direction_form.save(commit=False)
            validated_ingredient = ingredient_form.save()
            validated_recipe.ingredient = validated_ingredient

            return JsonResponse({'status': 'created'})
        else:
            return JsonResponse({'error': 'Error on form validation!'})
    return render(request, 'add.html')<commit_msg>removed table from view<commit_after>from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from .models import CookedAt, Recipe
from .forms import CookedAtForm, RecipeForm
from django.http import JsonResponse
from django.contrib import auth
from django.contrib import messages
import logging


def login(request):
    """
    Handle authentication
    :param request:
    :return:
    """
    if request.user.is_authenticated:
        return redirect('create')
    if request.method == "POST":
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = auth.authenticate(username=username, password=password)
        if user:
            auth.login(request, user)
            # return redirect('recipes')
            return redirect('create')
        else:
            messages.error(request, 'Username/Password is not valid!')
            return redirect('/')
    else:
        return render(request, 'login.html')


@login_required
def create(request):
    if request.method == 'POST':
        logger = logging.getLogger(__name__)
        recipe_form = RecipeForm(request.POST, request.FILES)
        if recipe_form.is_valid():
            # validated_recipe = recipe_form.save(commit=False)
            # validated_direction = direction_form.save(commit=False)
            # validated_ingredient = ingredient_form.save()
            # validated_recipe.ingredient = validated_ingredient
            recipe_form.save()
            print("saved")
            messages.info(request, 'Recipe Added')
            return render(request, 'add.html')
        else:
            messages.error(request, recipe_form.errors)
            print(recipe_form.errors)
            print("errrorrr")
            return render(request, 'add.html')
    return render(request, 'add.html')
{'fraction_non_alphanumeric': 0.09828141783029001, 'fraction_numerical': 0.0, 'mean_word_length': 2.872141372141372, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '865401', 'n_tokens_mistral': 989, 'n_tokens_neox': 971, 'n_words': 234}