dirty, ugly but workable
[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 import template
7 from migdal.models import Category
8
9 register = template.Library()
10
11
12 @register.simple_tag
13 def entry_begin(entry):
14     t = template.loader.select_template((
15         'migdal/entry/%s/entry_begin.html' % entry.type,
16         'migdal/entry/entry_begin.html',
17     ))
18     context = {'object': entry}
19     return t.render(template.Context(context))
20
21
22 @register.simple_tag
23 def entry_short(entry):
24     t = template.loader.select_template((
25         'migdal/entry/%s/entry_short.html' % entry.type,
26         'migdal/entry/entry_short.html',
27     ))
28     context = {'object': entry}
29     return t.render(template.Context(context))
30
31
32 @register.inclusion_tag('migdal/categories.html', takes_context=True)
33 def categories(context):
34     context.update({'object_list': Category.objects.all()})
35     return context
36
37
38 @register.inclusion_tag('migdal/last_comments.html')
39 def last_comments(limit=10):
40     return {'object_list': 
41         XtdComment.objects.filter(is_public=True, is_removed=False).order_by('-submit_date')[:limit]}