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 django.utils.functional import lazy
7 from django.utils.cache import add_never_cache_headers
8 from catalogue.models import Book
9 from ssify import ssi_variable
10 from ssify.utils import ssi_vary_on_cookie
11 from social.utils import likes, get_or_choose_cite
13 register = template.Library()
16 @ssi_variable(register, patch_response=[ssi_vary_on_cookie])
17 def likes_book(request, book_id):
18 return likes(request.user, Book.objects.get(pk=book_id), request)
21 @ssi_variable(register, name='choose_cite', patch_response=[add_never_cache_headers])
22 def choose_cite_tag(request, book_id=None, tag_ids=None):
23 cite = get_or_choose_cite(request, book_id, tag_ids)
24 return cite.pk if cite is not None else None
27 @register.inclusion_tag('social/cite_promo.html')
28 def render_cite(cite):
34 @ssi_variable(register, patch_response=[ssi_vary_on_cookie])
35 def book_shelf_tags(request, book_id):
36 if not request.user.is_authenticated():
38 book = Book.objects.get(pk=book_id)
39 lks = likes(request.user, book, request)
44 tags = book.tags.filter(category='set', user=request.user).exclude(name='')
48 return template.loader.render_to_string('social/shelf_tags.html', ctx)
49 return lazy(get_value, str)()