X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/8d8fb6e63435faa5de2d07a52812f23b1796a29d..d0072de89eb395f99aedcdf7804e48b547cbbeca:/apps/social/templatetags/social_tags.py diff --git a/apps/social/templatetags/social_tags.py b/apps/social/templatetags/social_tags.py index 1b26d91c4..deac93df0 100755 --- a/apps/social/templatetags/social_tags.py +++ b/apps/social/templatetags/social_tags.py @@ -3,8 +3,29 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django import template -from social.utils import likes +from catalogue.models import Book +from social.models import Cite +from social.utils import likes, cites_for_tags register = template.Library() register.filter('likes', likes) + + +@register.inclusion_tag('social/cite_promo.html') +def cite_promo(ctx=None, fallback=False): + """Choose""" + if ctx is None: + cites = Cite.objects.all() + elif isinstance(ctx, Book): + cites = ctx.cite_set.all() + if not cites.exists(): + cites = cites_for_tags([ctx.book_tag()]) + else: + cites = cites_for_tags(ctx) + + return { + 'cite': cites.order_by('?')[0] if cites.exists() else None, + 'fallback': fallback, + 'ctx': ctx, + } \ No newline at end of file