X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/357027375ff8867f42ca34bcbfb5a78b5b185fc3..2b46783ce404f01b81d1f8af045c69a507078818:/src/social/utils.py?ds=sidebyside diff --git a/src/social/utils.py b/src/social/utils.py index bf1c24229..63a42279b 100755 --- a/src/social/utils.py +++ b/src/social/utils.py @@ -21,7 +21,7 @@ def likes(user, work, request=None): if not hasattr(request, 'social_likes'): # tuple: unchecked, checked, liked - request.social_likes = defaultdict(lambda:(set(), set(), set())) + request.social_likes = defaultdict(lambda: (set(), set(), set())) ct = ContentType.objects.get_for_model(type(work)) likes_t = request.social_likes[ct.pk] @@ -29,6 +29,7 @@ def likes(user, work, request=None): return work.pk in likes_t[2] else: likes_t[0].add(work.pk) + def _likes(): if likes_t[0]: ids = tuple(likes_t[0]) @@ -47,8 +48,8 @@ def get_set(user, name): try: tag = Tag.objects.get(category='set', user=user, name=name) except Tag.DoesNotExist: - tag = Tag.objects.create(category='set', user=user, name=name, - slug=utils.get_random_hash(name), sort_key=name.lower()) + tag = Tag.objects.create( + category='set', user=user, name=name, slug=utils.get_random_hash(name), sort_key=name.lower()) return tag @@ -68,6 +69,9 @@ def set_sets(user, work, sets): # delete empty tags Tag.objects.filter(category='set', user=user, items=None).delete() + if isinstance(work, Book): + work.update_popularity() + def cites_for_tags(tags): """Returns a QuerySet with all Cites for books with given tags."""