From 56c4c9c9d413082b7e29f6507fdc98360a060ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Mon, 11 Sep 2023 15:23:18 -0300 Subject: [PATCH] =?UTF-8?q?Template=20tag=20para=20acessar=20itens=20em=20?= =?UTF-8?q?dicion=C3=A1rios=20pelo=20=C3=ADndice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/utils/templatetags/dict_get.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 sigi/apps/utils/templatetags/dict_get.py diff --git a/sigi/apps/utils/templatetags/dict_get.py b/sigi/apps/utils/templatetags/dict_get.py new file mode 100644 index 0000000..96733d2 --- /dev/null +++ b/sigi/apps/utils/templatetags/dict_get.py @@ -0,0 +1,14 @@ +from django import template +from django.conf import settings +from django.templatetags.static import static + +register = template.Library() + + +@register.filter +def get(d, key_name): + try: + value = d[key_name] + except KeyError: + value = settings.TEMPLATE_STRING_IF_INVALID + return value