Beispiel #1
0
def renew_books(request, pk):

    book_instance = get_object_or_404(BookInstance, id=pk)
    if request.method == "POST":
        form = RenewLoanBook(request.POST)
        print(form)
        if form.is_valid():
            book_instance.due_back = form.cleaned_data['renewal_date']
            book_instance.save()
            return redirect(reverse_lazy('catalog:allloanedbooks'))
    else:
        proposed_date = datetime.date.today() + datetime.timedelta(weeks=3)
        form = RenewLoanBook(initial={'renewal_date': proposed_date})
    ctx = {'book_instance': book_instance, 'form': form}

    return render(request, 'catalog/renewal_book.html', ctx)
Beispiel #2
0
 def test_renew_date_max(self):
     date = datetime.date.today() + datetime.timedelta(weeks=4)
     form = RenewLoanBook(data={'renewal_date': date})
     self.assertTrue(form.is_valid())
Beispiel #3
0
 def test_renew_date_today(self):
     date = datetime.date.today()
     form = RenewLoanBook(data={'renewal_date': date})
     self.assertTrue(form.is_valid())
Beispiel #4
0
 def test_renew_date_to_future(self):
     date = datetime.date.today() + datetime.timedelta(
         weeks=4) + datetime.timedelta(days=1)
     form = RenewLoanBook(data={'renewal_date': date})
     self.assertFalse(form.is_valid())
Beispiel #5
0
 def test_renew_from_date_past(self):
     date = datetime.date.today() - datetime.timedelta(days=1)
     form = RenewLoanBook(data={'renewal_date': date})
     self.assertFalse(form.is_valid())