Ejemplo n.º 1
0
def diarys_form(request, id=None, action=None):
    if id:
        diary_form = DiaryForm(request.POST or None, instance=get_object_or_404(Diary, pk=id))
    else:
        diary_form = DiaryForm(request.POST or None)

    if request.method == "POST" and diary_form.is_valid():
        diary = diary_form.save(commit=False)
        diary.author = request.user
        diary.save()
        return HttpResponseRedirect(reverse("diary_list") + "#diary_%d" % diary.id)

    return render_to_response("org/diary.html", {"diary_form": diary_form}, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def diarys_form(request, id=None, action=None):
    if id:
        diary_form = DiaryForm(request.POST or None, instance=Diary.objects.get(id=id))
    else:
        diary_form = DiaryForm(request.POST or None)

    if request.method == "POST" and diary_form.is_valid():
        diary = diary_form.save(commit=False)
        diary.author = request.user
        diary.save()
        return HttpResponseRedirect(diary.get_absolute_url())

    return render_to_response(
        'org/diary.html',
        {'diary_form': diary_form},
        context_instance=RequestContext(request))