1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django_comments_xtd.models import XtdComment
6 from django.contrib import comments
7 from django import template
8 from migdal import app_settings
9 from migdal.models import Category
11 register = template.Library()
14 @register.simple_tag(takes_context=True)
15 def entry_begin(context, entry, detail=False):
16 t = template.loader.select_template((
17 'migdal/entry/%s/entry_begin.html' % entry.type,
18 'migdal/entry/entry_begin.html',
21 'request': context['request'],
25 return t.render(template.Context(context))
28 @register.simple_tag(takes_context=True)
29 def entry_short(context, entry):
30 t = template.loader.select_template((
31 'migdal/entry/%s/entry_short.html' % entry.type,
32 'migdal/entry/entry_short.html',
35 'request': context['request'],
38 return t.render(template.Context(context))
41 @register.simple_tag(takes_context=True)
42 def entry_promobox(context, entry, counter):
43 t = template.loader.select_template((
44 'migdal/entry/%s/entry_promobox.html' % entry.type,
45 'migdal/entry/entry_promobox.html',
48 'request': context['request'],
52 return t.render(template.Context(context))
55 @register.inclusion_tag('migdal/categories.html', takes_context=True)
56 def categories(context, taxonomy):
58 'request': context['request'],
59 'object_list': Category.objects.filter(taxonomy=taxonomy).exclude(entry__isnull=True)
64 @register.inclusion_tag('migdal/last_comments.html')
65 def last_comments(limit=app_settings.LAST_COMMENTS):
67 'object_list': XtdComment.objects.filter(is_public=True, is_removed=False).order_by('-submit_date')[:limit]}
70 @register.inclusion_tag(['comments/form.html'])
71 def entry_comment_form(entry):
73 'form': comments.get_form()(entry),
74 'next': entry.get_absolute_url(),