X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/5c05e41cfb2907f6621833a8f673d66bfcac2699..9b97d5a2faa6f56b439dcefe9c7bb23e0a84b39c:/apps/catalogue/views.py diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 7168fb05d..c9d6ab227 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -176,7 +176,6 @@ def user_shelves(request): return render_to_response('catalogue/user_shelves.html', locals(), context_instance=RequestContext(request)) -@login_required @cache.never_cache def book_sets(request, slug): book = get_object_or_404(models.Book, slug=slug) @@ -189,8 +188,18 @@ def book_sets(request, slug): if request.method == 'POST': form = forms.ObjectSetsForm(book, request.user, request.POST) if form.is_valid(): - book.tags = ([models.Tag.objects.get(pk=id) for id in form.cleaned_data['set_ids']] + - list(book.tags.filter(~Q(category='set') | ~Q(user=request.user)))) + old_shelves = list(book.tags.filter(category='set')) + new_shelves = [models.Tag.objects.get(pk=id) for id in form.cleaned_data['set_ids']] + + for shelf in [shelf for shelf in old_shelves if shelf not in new_shelves]: + shelf.book_count -= 1 + shelf.save() + + for shelf in [shelf for shelf in new_shelves if shelf not in old_shelves]: + shelf.book_count += 1 + shelf.save() + + book.tags = new_shelves + list(book.tags.filter(~Q(category='set') | ~Q(user=request.user))) if request.is_ajax(): return HttpResponse('

Półki zostały zapisane.

') else: @@ -212,6 +221,9 @@ def remove_from_shelf(request, shelf, book): models.Tag.objects.remove_tag(book, shelf) + shelf.book_count -= 1 + shelf.save() + return HttpResponse('Usunieto') @@ -272,8 +284,7 @@ def new_set(request): else: return HttpResponseRedirect('/') - return render_to_response('catalogue/book_sets.html', locals(), - context_instance=RequestContext(request)) + return HttpResponseRedirect('/') @login_required