コード例 #1
0
ファイル: views.py プロジェクト: ch3ka/codingcontest2012
def addbook(request):
    from tools import isbntools
    if request.method == "POST":
        form = BookForm(request.POST, request.FILES)
        if form.is_valid():
            return HttpResponseRedirect('/book/'+isbntools.strip(str(form.cleaned_data['isbn'])))
    else:
        form = BookForm()
    return render_to_response('addbook.html',
        {'form': form, 'isbnform': ISBNBookForm(request.POST)},
        context_instance=RequestContext(request)
    )
コード例 #2
0
ファイル: views.py プロジェクト: ch3ka/codingcontest2012
def editbook(request, isbn):
    book = Book.objects.get(isbn=isbn)
    if request.method == "POST" and request.user.is_authenticated():
        form = BookForm(request.POST, request.FILES, instance = book)
        if form.is_valid():
            form.save()
    else:
        form = BookForm(instance = book)

    return render_to_response('editbook.html', 
        {'book': book, 'form': form},
        context_instance=RequestContext(request)
    )