5578c5d4d61b0f8a7e7d47916c68b6dd010acee2
[prawokultury.git] / migdal / templatetags / migdal_tags.py
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.
4 #
5 from django_comments_xtd.models import XtdComment
6 from django.contrib import comments
7 from django import template
8 from migdal.models import Category
9
10 register = template.Library()
11
12
13 @register.simple_tag(takes_context=True)
14 def entry_begin(context, entry):
15     t = template.loader.select_template((
16         'migdal/entry/%s/entry_begin.html' % entry.type,
17         'migdal/entry/entry_begin.html',
18     ))
19     context.update({'object': entry})
20     return t.render(template.Context(context))
21
22
23 @register.simple_tag(takes_context=True)
24 def entry_short(context, entry):
25     t = template.loader.select_template((
26         'migdal/entry/%s/entry_short.html' % entry.type,
27         'migdal/entry/entry_short.html',
28     ))
29     context.update({'object': entry})
30     return t.render(template.Context(context))
31
32
33 @register.inclusion_tag('migdal/categories.html', takes_context=True)
34 def categories(context):
35     context.update({'object_list': Category.objects.all()})
36     return context
37
38
39 @register.inclusion_tag('migdal/last_comments.html')
40 def last_comments(limit=10):
41     return {'object_list': 
42         XtdComment.objects.filter(is_public=True, is_removed=False).order_by('-submit_date')[:limit]}
43
44
45 @register.inclusion_tag(['comments/form.html'])
46 def entry_comment_form(entry):
47     return {
48             'form': comments.get_form()(entry),
49             'next': entry.get_absolute_url(),
50         }