Fixed a negative shelf counter bug.
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 11 May 2010 10:25:46 +0000 (12:25 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 11 May 2010 10:25:46 +0000 (12:25 +0200)
Must still correct current counts on the server after deployment.

apps/catalogue/views.py

index 6de5a26..60f984a 100644 (file)
@@ -294,12 +294,15 @@ def remove_from_shelf(request, shelf, book):
     book = get_object_or_404(models.Book, slug=book)
     shelf = get_object_or_404(models.Tag, slug=shelf, category='set', user=request.user)
     
     book = get_object_or_404(models.Book, slug=book)
     shelf = get_object_or_404(models.Tag, slug=shelf, category='set', user=request.user)
     
-    models.Tag.objects.remove_tag(book, shelf)
-    
-    shelf.book_count -= 1
-    shelf.save()
-    
-    return HttpResponse('Usunieto')
+    if shelf in book.tags:
+        models.Tag.objects.remove_tag(book, shelf)
+
+        shelf.book_count -= 1
+        shelf.save()
+
+        return HttpResponse('Usunięto')
+    else:
+        return HttpResponse('Książki nie ma na półce')
 
 
 def collect_books(books):
 
 
 def collect_books(books):