X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/142cf364fb3fc7cd95df709126ada97b6944c128..f293bf6e6217d2277d11b65fdb63bc35badc8e68:/apps/catalogue/views.py?ds=sidebyside diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index e6e5eb927..13bb5ac18 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -29,6 +29,7 @@ from django.views.generic.list_detail import object_list from catalogue import models from catalogue import forms from catalogue.utils import split_tags, AttachmentHttpResponse, async_build_pdf +from catalogue.tasks import touch_tag from pdcounter import models as pdcounter_models from pdcounter import views as pdcounter_views from suggest.forms import PublishingSuggestForm @@ -56,9 +57,11 @@ class JSONResponse(HttpResponse): def catalogue(request): - tags = models.Tag.objects.exclude(category__in=('set', 'book')) + tags = models.Tag.objects.exclude( + category__in=('set', 'book')).exclude(book_count=0) + tags = list(tags) for tag in tags: - tag.count = tag.get_count() + tag.count = tag.book_count categories = split_tags(tags) fragment_tags = categories.get('theme', []) @@ -223,7 +226,7 @@ def book_detail(request, book): book = models.Book.objects.get(**kwargs) except models.Book.DoesNotExist: return pdcounter_views.book_stub_detail(request, kwargs['slug']) - + book_tag = book.book_tag() tags = list(book.tags.filter(~Q(category='set'))) categories = split_tags(tags) @@ -520,12 +523,10 @@ def book_sets(request, book): 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 = None - shelf.save() + touch_tag(shelf) for shelf in [shelf for shelf in new_shelves if shelf not in old_shelves]: - shelf.book_count = None - shelf.save() + touch_tag(shelf) book.tags = new_shelves + list(book.tags.filter(~Q(category='set') | ~Q(user=request.user))) if request.is_ajax(): @@ -553,9 +554,7 @@ def remove_from_shelf(request, shelf, book): if shelf in book.tags: models.Tag.objects.remove_tag(book, shelf) - - shelf.book_count = None - shelf.save() + touch_tag(shelf) return HttpResponse(_('Book was successfully removed from the shelf')) else: