X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/98b2c09ef1f1c8288a31517f61423264c6b3291c..HEAD:/src/chunks/templatetags/chunks.py diff --git a/src/chunks/templatetags/chunks.py b/src/chunks/templatetags/chunks.py index 968d284fd..6a891f9de 100644 --- a/src/chunks/templatetags/chunks.py +++ b/src/chunks/templatetags/chunks.py @@ -1,16 +1,20 @@ -# -*- coding: utf-8 -*- +# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. +# from django import template from django.core.cache import cache +from django.utils.safestring import mark_safe +from django.utils.translation import get_language 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_' + key + cache_key = 'chunk:%s:%s' % (key, get_language()) c = cache.get(cache_key) if c is None: c = Chunk.objects.get(key=key) @@ -19,8 +23,12 @@ def chunk(key, cache_time=0): except Chunk.DoesNotExist: n = Chunk(key=key) n.save() - return '' - return content + content = '' + + if 'request' in context and context['request'].user.is_staff: + content = f'' + content + + return mark_safe(content) @register.simple_tag