X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/f3e8dfa015744bd72796fdd8eff0d81f863cdc46..807700701f88085d514a75474b17f8e85bfd1ebd:/src/chunks/templatetags/chunks.py diff --git a/src/chunks/templatetags/chunks.py b/src/chunks/templatetags/chunks.py index 200002b8e..b8e9f4f6d 100644 --- a/src/chunks/templatetags/chunks.py +++ b/src/chunks/templatetags/chunks.py @@ -1,3 +1,6 @@ +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# from django import template from django.core.cache import cache from django.utils.safestring import mark_safe @@ -8,8 +11,8 @@ from ..models import Chunk, Attachment register = template.Library() -@register.simple_tag -def chunk(key, cache_time=0): +@register.simple_tag(takes_context=True) +def chunk(context, key, cache_time=0): try: cache_key = 'chunk:%s:%s' % (key, get_language()) c = cache.get(cache_key) @@ -20,7 +23,11 @@ def chunk(key, cache_time=0): except Chunk.DoesNotExist: n = Chunk(key=key) n.save() - return '' + content = '' + + if 'request' in context and context['request'].user.is_staff: + content = f'' + content + return mark_safe(content)