Exemple #1
0
def making_edit(request, id):
    making = Making.objects.get(id=id)
    recipegroup = making.group
    if request.method == "POST":
        form = MakingForm(request.POST, instance=making)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("recipe_info", args=(recipegroup.id,)))
    else:
        form = MakingForm(instance=making)
    return render_to_response("recipes/making_edit.html", {"form": form, "recipegroup": recipegroup, "making": making} , context_instance=RequestContext(request))
Exemple #2
0
def recipe_info(request, id, template_name):
    recipegroup = RecipeGroup.objects.get(id=id)
    descrform = DescrForm(initial={"description":recipegroup.description})
    form = MakingForm()
    if request.method == 'POST' and request.user.is_authenticated():
        if request.GET.get("descr") is not None:
            descrform = DescrForm(request.POST)
            if descrform.is_valid():
                recipegroup.description = descrform.cleaned_data["description"]
                recipegroup.save()
        else:
            form = MakingForm(request.POST)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.group = recipegroup
                instance.save()
                form = MakingForm()

    recipegroup.description = recipegroup.description.replace("\n", "<br>")

    makings = Making.objects.filter(group=recipegroup)
    return render_to_response(template_name, {"descr_form": descrform, "form": form, "recipegroup": recipegroup, "makings": makings}, context_instance=RequestContext(request))