1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django import template
6 from catalogue.models import Book
7 from social.models import Cite
8 from social.utils import likes, cites_for_tags
10 register = template.Library()
12 register.filter('likes', likes)
15 @register.inclusion_tag('social/cite_promo.html')
16 def cite_promo(ctx=None, fallback=False):
19 cites = Cite.objects.all()
20 elif isinstance(ctx, Book):
21 cites = ctx.cite_set.all()
22 if not cites.exists():
23 cites = cites_for_tags([ctx.book_tag()])
25 cites = cites_for_tags(ctx)
28 'cite': cites.order_by('?')[0] if cites.exists() else None,
34 @register.inclusion_tag('social/shelf_tags.html', takes_context=True)
35 def shelf_tags(context, book):
36 user = context['request'].user
37 if not user.is_authenticated():
40 tags = book.tags.filter(category='set', user=user).exclude(name='')