Merge pull request #1681 from matmair/more-templatetags

More templatetags
This commit is contained in:
Oliver 2021-06-18 08:18:40 +10:00 committed by GitHub
commit 9991f4a694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -208,6 +208,29 @@ def get_color_theme_css(username):
return inventree_css_static_url
@register.filter
def keyvalue(dict, key):
"""
access to key of supplied dict
usage:
{% mydict|keyvalue:mykey %}
"""
return dict[key]
@register.simple_tag()
def call_method(obj, method_name, *args):
"""
enables calling model methods / functions from templates with arguments
usage:
{% call_method model_object 'fnc_name' argument1 %}
"""
method = getattr(obj, method_name)
return method(*args)
@register.simple_tag()
def authorized_owners(group):
""" Return authorized owners """