+# 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
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)
except Chunk.DoesNotExist:
n = Chunk(key=key)
n.save()
- return ''
+ content = ''
+
+ if context['request'].user.is_staff:
+ content = f'<span data-edit="chunks/chunk/{key}"></span>' + content
+
return mark_safe(content)