Fundraising in PDF.
[wolnelektury.git] / src / sponsors / templatetags / sponsors.py
1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 from django import template
5 from django.core.cache import cache
6 from django.utils.safestring import mark_safe
7 from sponsors.models import SponsorPage
8
9
10 register = template.Library()
11
12
13 @register.simple_tag
14 def sponsor_page(name):
15     key = 'sponsor_page:' + name
16     content = cache.get(key)
17     if content is None:
18         try:
19             page = SponsorPage.objects.get(name=name)
20         except SponsorPage.DoesNotExist:
21             content = ''
22         else:
23             content = page.html
24         cache.set(key, content) 
25     return mark_safe(content)