def decline_counteroffer(request, id): counteroffer = get_object_or_404(Counteroffer, id=id) buyer = get_object_or_404(User, id=counteroffer.creator.id) offer = get_object_or_404(Offer, id=counteroffer.offer.id) book = get_object_or_404(Book, id=offer.book.id) # Akzeptiere nicht Notification.counteroffer_decline(counteroffer, buyer, book) counteroffer.decline() messages.add_message(request, messages.SUCCESS, 'Der Preisvorschlag wurde erfolgreich abgelehnt. Der Interessent wird benachrichtigt') return HttpResponseRedirect(reverse('app_notification:notificationsPage'))
def unpublishBook(request, id): book = get_object_or_404(Book, id=id) if book.is_in_active_payment_process(): messages.add_message(request, messages.ERROR, 'Das Buch wird gerade verkauft und kann daher nicht unveröffentlicht werden!') return HttpResponseRedirect(reverse('app_book:book-detail', kwargs={'id': id})) if request.method == 'PUT': unpublish_book(book) messages.add_message(request, messages.SUCCESS, 'Das Buch wird nun nicht mehr zum Verkauf angeboten!') # decline all active counteroffers: user = get_object_or_404(User, id=request.user.id) offer = book.offer_set.filter(seller_user = user).first() counteroffers = Counteroffer.objects.filter(offer=offer, active=True) for co in counteroffers: Notification.counteroffer_decline(co, co.creator, book) # use GET request for redirected location via HTTP status code 303 (see other). counteroffers.update(active=False, accepted=False) return HttpResponseRedirect(reverse('app_book:book-detail', kwargs={'id': id})) else: raise ("Use http method PUT for unpublishing a book.")
def decline_all_counteroffers_for_offer(offer): counteroffers = Counteroffer.objects.filter(offer=offer, active=True, accepted=False) for co in counteroffers: co.decline() Notification.counteroffer_decline(co, co.creator, offer.book)