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.
8 from django import template
10 from catalogue.models import Book, BookMedia
13 register = template.Library()
16 #~ @register.tag(name='captureas')
17 #~ def do_captureas(parser, token):
19 #~ tag_name, args = token.contents.split(None, 1)
21 #~ raise template.TemplateSyntaxError("'captureas' node requires a variable name.")
22 #~ nodelist = parser.parse(('endcaptureas',))
23 #~ parser.delete_first_token()
24 #~ return CaptureasNode(nodelist, args)
26 class StatsNode(template.Node):
27 def __init__(self, value, varname=None):
29 self.varname = varname
31 def render(self, context):
34 context[self.varname] = self.value
42 #~ def count_books_all(*args, **kwargs):
44 #~ return StatsNode(Book.objects.all().count())
47 def count_books_nonempty(parser, token):
49 tag_name, args = token.contents.split(None, 1)
52 return StatsNode(Book.objects.exclude(html_file='').count(), args)
54 #~ @register.simple_tag
55 #~ def count_books_empty():
56 #~ return Book.objects.exclude(html_file='').count()
58 #~ @register.simple_tag
59 #~ def count_books_root():
60 #~ return Book.objects.filter(parent=None).count()