コード例 #1
0
ファイル: views.py プロジェクト: kennym/django-flashcard
def edit_flashcard(request, flashcard_id, template_name='edit_flashcard.html'):
    """
    Edit a flashcard.
    """
    flashcard = get_object_or_404(FlashCard, pk=flashcard_id)
    if request.method == "POST":
        form = FlashCardForm(instance=flashcard, data=request.POST)
        if form.is_valid():
            flashcard = form.save()
            return HttpResponseRedirect(flashcard.get_absolute_url())
    else:
        form = FlashCardForm(instance=flashcard)

    return_dict = {
        'form': form
    }
    return render_to_response(template_name, return_dict,
                             context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: kennym/django-flashcard
def create_flashcard(request, template_name='create_flashcard.html'):
    """
    Return a form for creating a flashcard.
    """
    if request.method == "POST":
        formset = FlashCardForm(data=request.POST)
        if formset.is_valid():
            formset.instance.user = request.user
            formset.save()
            # Redirect to the flashcard list index.
            return redirect(to='list_flashcards')
    else:
        formset = FlashCardForm()

    return_dict = {
        'formset': formset
    }

    return render_to_response(template_name, return_dict,
                             context_instance=RequestContext(request))
コード例 #3
0
def create_flashcard(request, template_name='create_flashcard.html'):
    """
    Return a form for creating a flashcard.
    """
    if request.method == "POST":
        formset = FlashCardForm(data=request.POST)
        if formset.is_valid():
            formset.instance.user = request.user
            formset.save()
            # Redirect to the flashcard list index.
            return redirect(to='list_flashcards')
    else:
        formset = FlashCardForm()

    return_dict = {'formset': formset}

    return render_to_response(template_name,
                              return_dict,
                              context_instance=RequestContext(request))
コード例 #4
0
def edit_flashcard(request, flashcard_id, template_name='edit_flashcard.html'):
    """
    Edit a flashcard.
    """
    flashcard = get_object_or_404(FlashCard, pk=flashcard_id)
    if request.method == "POST":
        form = FlashCardForm(instance=flashcard, data=request.POST)
        if form.is_valid():
            flashcard = form.save()
            return HttpResponseRedirect(flashcard.get_absolute_url())
    else:
        form = FlashCardForm(instance=flashcard)

    return_dict = {'form': form}
    return render_to_response(template_name,
                              return_dict,
                              context_instance=RequestContext(request))