Пример #1
0
 def form_valid(self, form):
     lending = form.save(commit=False)
     lending.borrower = self.request.user
     if is_lending_possible(lending.beginning_date, lending.book_copy):
         lending.save()
         remove_from_queue(lending.book_copy, lending.borrower, lending)
     else:
         messages.add_message(
             self.request,
             messages.ERROR,
             _("This lending is not possible and you should have had errors on the form!"),
         )
     return redirect("book_detail", book_id=lending.book_copy.book.id)
Пример #2
0
 def clean(self):
     beginning_date = self.cleaned_data['beginning_date']
     book_copy = self.cleaned_data['book_copy']
     is_lending_possible(beginning_date,book_copy)
     return self.cleaned_data