Exemple #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)
Exemple #2
0
 def get(sef, request, pk):
     book = Book.objects.get(id=pk)
     bookins = BookInstance.objects.filter(book=pk)
     bookcount = BookInstance.objects.filter(book=pk).count()
     bookcountAva = BookInstance.objects.filter(book=pk).filter(
         status__exact="a").count()
     if bookcountAva > 0:
         diffbooks = bookcountAva
         requestBook = BookInstance.objects.filter(book=pk).filter(
             status__exact="a").first()
         proposed_date = datetime.date.today() + datetime.timedelta(weeks=3)
         form = RenewLoanBook(initial={'renewal_date': proposed_date})
         ctx = {
             'book': book,
             'instances': bookins,
             'availablebooks': diffbooks,
             'requestbook': requestBook,
             'form': form
         }
         return render(request, 'catalog/detail.html', ctx)
     ctx = {'book': book, 'instances': bookins}
     return render(request, 'catalog/detail.html', ctx)
Exemple #3
0
 def test_renewal_date_label(self):
     form = RenewLoanBook()
     self.assertTrue(form.fields['renewal_date'].label == None
                     or form.fields['renewal_date'].label == 'renewal date')
Exemple #4
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())
Exemple #5
0
 def test_renew_date_today(self):
     date = datetime.date.today()
     form = RenewLoanBook(data={'renewal_date': date})
     self.assertTrue(form.is_valid())
Exemple #6
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())
Exemple #7
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())
Exemple #8
0
 def test_renew_form_date_help_text(self):
     form = RenewLoanBook()
     self.assertEqual(
         form.fields['renewal_date'].help_text,
         "Enter the date between now and 4 week (default: 3).")