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]
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])
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
# 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."""