kitware-resonant / django-resonant-utils

Django utilities for data management applications.
Apache License 2.0
2 stars 1 forks source link

Add a template tag for getting a dictionary value #29

Closed danlamanna closed 3 years ago

danlamanna commented 3 years ago

Fixes #28.

It turns out there is no need for an app to use template tags. Though the user would have to add girder_utils.templatetags to the the libraries/builtins option of the template engine. See https://docs.djangoproject.com/en/3.1/topics/templates/#django.template.backends.django.DjangoTemplates.

If in a template the user needs to retrieve a dictionary value by key and the key is itself stored in another variable - a template filter like this is needed.

If this seems widely useful we should merge it. I've personally used it on 3 django projects now, along with another filter which chunks iterables into groups of n.

danlamanna commented 3 years ago

@brianhelba This is the snippet I added to before_binding:

existing_options = configuration.TEMPLATES[0]['OPTIONS']
if existing_options.get('builtins'):
    existing_options['builtins'].append('girder_utils.templatetags')
else:
    existing_options['builtins'] = ['girder_utils.templatetags']