lemoncurry/lemoncurry/templatetags/lemoncurry_tags.py

24 lines
529 B
Python
Raw Normal View History

2017-10-22 19:35:29 -04:00
import json
from os.path import join
from types import SimpleNamespace
2017-10-22 19:35:29 -04:00
2017-10-22 18:37:24 -04:00
from django import template
from django.conf import settings
register = template.Library()
cache = SimpleNamespace(package_json=None)
2017-10-22 18:37:24 -04:00
2017-10-22 19:35:29 -04:00
@register.simple_tag
def get_package_json():
if cache.package_json:
return cache.package_json
2017-10-22 19:35:29 -04:00
with open(join(settings.BASE_DIR, 'package.json')) as f:
cache.package_json = json.load(f)
return cache.package_json
2017-10-22 19:35:29 -04:00
2017-10-22 18:37:24 -04:00
@register.simple_tag
def site_name():
return settings.LEMONCURRY_SITE_NAME