Exemple #1
0
def correct_recipe(request):
	if request.method == 'POST':
		form = RecipeForm(request.POST, request.FILES)
		if form.is_valid():
			recipe = form.save(commit=False)
			recipe.user = request.user
			recipe.save()
			junk_id = request.POST['junkid']
			junk = JunkRecipe.objects.get(id = junk_id)
			formset = RecipeIngredientsFormset(request.POST, request.FILES, instance=recipe)
			if formset.is_valid():
				formset.save()
				recipe.save()
				junk.is_added = True
				junk.derived_recipe = recipe
				junk.save()
				return render_to_response('recipes/view_recipe.html', {'recipe': recipe,}, context_instance=RequestContext(request))
			else:
				recipe.delete()
		else:
			junk_id = request.POST['junkid']
			junk = JunkRecipe.objects.get(id = junk_id)
			formset = RecipeIngredientsFormset(request.POST, request.FILES)
	else:
		junk = random.choice(JunkRecipe.objects.filter(is_added = False))
		form = RecipeForm()
		formset = RecipeIngredientsFormset()
	return render_to_response('recipes/correct_recipe.html', {'form': form, 'formset': formset, 'junk': junk}, context_instance=RequestContext(request))
Exemple #2
0
def add_recipe(request):
    if request.method == 'POST':
        form = RecipeForm(request.POST, request.FILES)
        if form.is_valid():
            recipe = form.save(commit=False)
            recipe.user = request.user
            recipe.save()
            formset = RecipeIngredientsFormset(request.POST,
                                               request.FILES,
                                               instance=recipe)
            if formset.is_valid():
                formset.save()
                recipe.save()
                return render_to_response(
                    'recipes/view_recipe.html', {
                        'recipe': recipe,
                    },
                    context_instance=RequestContext(request))
            else:
                recipe.delete()
        else:
            formset = RecipeIngredientsFormset(request.POST, request.FILES)
    else:
        form = RecipeForm()
        formset = RecipeIngredientsFormset()
    return render_to_response('recipes/add_recipe.html', {
        'form': form,
        'formset': formset
    },
                              context_instance=RequestContext(request))
Exemple #3
0
def edit_recipe(request, id):
    recipe = get_object_or_404(Recipe, id=id)
    tag_prepop = Tag.objects.get_for_object(recipe)
    tool_prepop = recipe.tools.all()
    if recipe.user != request.user and request.user.is_superuser == False:
        return render_to_response('recipes/forbidden.html',
                                  context_instance=RequestContext(request))
    if request.method == 'POST':
        form = RecipeForm(request.POST, request.FILES, instance=recipe)
        formset = RecipeIngredientsFormset(request.POST,
                                           request.FILES,
                                           instance=recipe)
        if form.is_valid():
            recipe = form.save(commit=False)
            if formset.is_valid():
                formset.save()
                recipe.save()
                return render_to_response(
                    'recipes/view_recipe.html', {
                        'recipe': recipe,
                    },
                    context_instance=RequestContext(request))
    else:
        form = RecipeForm(instance=recipe)
        formset = RecipeIngredientsFormset(instance=recipe)
    return render_to_response('recipes/edit_recipe.html', {
        'recipe': recipe,
        'form': form,
        'formset': formset,
        'tag_prepop': tag_prepop,
        'tool_prepop': tool_prepop
    },
                              context_instance=RequestContext(request))
Exemple #4
0
def edit_recipe(request, id):
	recipe = get_object_or_404(Recipe, id=id)
	tag_prepop = Tag.objects.get_for_object(recipe)
	tool_prepop = recipe.tools.all()
	if recipe.user != request.user and request.user.is_superuser == False:
		return render_to_response('recipes/forbidden.html', context_instance=RequestContext(request))
	if request.method == 'POST':
		form = RecipeForm(request.POST, request.FILES, instance=recipe)
		formset = RecipeIngredientsFormset(request.POST, request.FILES, instance=recipe)
		if form.is_valid():
			recipe = form.save(commit=False)
			if formset.is_valid():
				formset.save()
				recipe.save()
				return render_to_response('recipes/view_recipe.html', {'recipe': recipe,}, context_instance=RequestContext(request))
	else:
		form = RecipeForm(instance=recipe)
		formset = RecipeIngredientsFormset(instance=recipe)
	return render_to_response('recipes/edit_recipe.html', {'recipe': recipe, 'form': form, 'formset': formset, 'tag_prepop': tag_prepop, 'tool_prepop': tool_prepop}, context_instance=RequestContext(request))
Exemple #5
0
def add_recipe(request):
	if request.method == 'POST':
		form = RecipeForm(request.POST, request.FILES)
		if form.is_valid():
			recipe = form.save(commit=False)
			recipe.user = request.user
			recipe.save()
			formset = RecipeIngredientsFormset(request.POST, request.FILES, instance=recipe)
			if formset.is_valid():
				formset.save()
				recipe.save()
				return render_to_response('recipes/view_recipe.html', {'recipe': recipe,}, context_instance=RequestContext(request))
			else:
				recipe.delete()
		else:
			formset = RecipeIngredientsFormset(request.POST, request.FILES)
	else:
		form = RecipeForm()
		formset = RecipeIngredientsFormset()
	return render_to_response('recipes/add_recipe.html', {'form': form, 'formset': formset}, context_instance=RequestContext(request))
Exemple #6
0
def correct_recipe(request):
    if request.method == 'POST':
        form = RecipeForm(request.POST, request.FILES)
        if form.is_valid():
            recipe = form.save(commit=False)
            recipe.user = request.user
            recipe.save()
            junk_id = request.POST['junkid']
            junk = JunkRecipe.objects.get(id=junk_id)
            formset = RecipeIngredientsFormset(request.POST,
                                               request.FILES,
                                               instance=recipe)
            if formset.is_valid():
                formset.save()
                recipe.save()
                junk.is_added = True
                junk.derived_recipe = recipe
                junk.save()
                return render_to_response(
                    'recipes/view_recipe.html', {
                        'recipe': recipe,
                    },
                    context_instance=RequestContext(request))
            else:
                recipe.delete()
        else:
            junk_id = request.POST['junkid']
            junk = JunkRecipe.objects.get(id=junk_id)
            formset = RecipeIngredientsFormset(request.POST, request.FILES)
    else:
        junk = random.choice(JunkRecipe.objects.filter(is_added=False))
        form = RecipeForm()
        formset = RecipeIngredientsFormset()
    return render_to_response('recipes/correct_recipe.html', {
        'form': form,
        'formset': formset,
        'junk': junk
    },
                              context_instance=RequestContext(request))