Пример #1
0
def add_book(request):
    if request.method == "POST":
        form_book = AddBookForm(data=request.POST)
        if form_book.is_valid():
            form_book.save()
        return redirect('books:all_books')
    else:
        form_book = AddBookForm()

    return render(request, 'books/add_book.html', {'form_book': form_book})
Пример #2
0
def add_book(request):
    profile = UserProfile.objects.get(user=request.user)
    my_books = Book.objects.exclude(UserProfile=profile)
    if request.method == 'POST':
        form_instance = AddBookForm(request.POST)
        if(form_instance.is_valid()):
            instance = form_instance.save(commit=False)
            book = Book.objects.get(title=instance.title)
            book.UserProfile.add(profile)

            context = {
                    'books': my_books,
                    "form": form_instance,
                    "is_user": checkAuth(request),
            }
            return HttpResponseRedirect('../books')
    else:
      form_instance = AddBookForm()
    context = {
            'books': my_books,
            "form": form_instance,
            "user": request.user,
            "profile": profile,
            "is_user": checkAuth(request),
    }
    return render(request, 'add_book.html', context=context)
Пример #3
0
def add_book(request):
    add_book_form = AddBookForm(data=request.POST)
    if add_book_form.is_valid():
        book = add_book_form.save(commit=False)
        book.user_id = request.user.id
        book.save()
        return redirect('books:add_book')
    else:
        add_book_form = AddBookForm()
    return render(request, 'books/add_book.html',
                  {'add_book_form': add_book_form})
Пример #4
0
def add_book(request):
    if request.method == "POST":
        form = AddBookForm(request.POST, request.FILES)
        if form.is_valid():
            blog_item = form.save(commit=False)
            blog_item.user = request.user
            blog_item.save()

            return redirect('books:index')

    else:
        form = AddBookForm()
    return render(request, 'books/new.html', {'form': form})
Пример #5
0
def add_book(request):
    book = None    
    error = False
    if request.POST:
        temp = Book()        
        book = AddBookForm(request.POST, instance = temp)
        if book.is_valid():
            book.save()
            return HttpResponseRedirect('/add/success/')
        else:
            error = True
            book = AddBookForm()
            return render_to_response('add_book.html',
                    {'book': book, 'error': error})
    book = AddBookForm()
    return render_to_response('add_book.html',
                    {'book': book, 'error': error})
Пример #6
0
def update(request):
    error = False
    if 'q' in request.GET:
        q = request.GET['q']
        temp = Book.objects.get(ISBN=q)
        if request.POST:
            book = AddBookForm(request.POST, instance = temp)
            if book.is_valid():
                book.save()
                return HttpResponseRedirect('/update/success/')
            else:
                error = True
                book = AddBookForm(instance = temp)
                return render_to_response('update.html',
                        {'book': book, 'error': error})
    book = AddBookForm(instance = temp)
    return render_to_response('update.html',
                    {'book': book, 'error': error})
Пример #7
0
def test_add_book_form():
    form = AddBookForm(
        data={
            'title': 'Eryk',
            'author': 'Terry Pratchett',
            'published_date': '2009'
        }
    )

    assert form.is_valid() is True

    form = AddBookForm(
        data={
            'title': 'Eryk',
            'author': 'Terry Pratchett',
            'published_date': '2009.10.10'
        }
    )

    assert form.is_valid() is False