From 469622ce6793e628e8d44645dc39162a3ee2f12f Mon Sep 17 00:00:00 2001 From: Charles Shin Date: Sun, 19 Feb 2017 17:20:21 -0800 Subject: [PATCH] Added a custom Django template tag for retrieving responses to completed form questions --- edivorce/apps/core/templatetags/__init__.py | 0 .../apps/core/templatetags/input_option.py | 45 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 edivorce/apps/core/templatetags/__init__.py create mode 100644 edivorce/apps/core/templatetags/input_option.py diff --git a/edivorce/apps/core/templatetags/__init__.py b/edivorce/apps/core/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/edivorce/apps/core/templatetags/input_option.py b/edivorce/apps/core/templatetags/input_option.py new file mode 100644 index 00000000..4e6d68e8 --- /dev/null +++ b/edivorce/apps/core/templatetags/input_option.py @@ -0,0 +1,45 @@ +from django import template + +register = template.Library() + + +@register.simple_tag(takes_context=True) +def input_option(context, type, name='', value='', **kwargs): + """ + Usage: when specifying data attributes in templates, use "data_" intead of "data-". + """ + if type == "textarea": + tag = ['') + else: + # set initial value for textbox + if type == "text": + value = context.get(name, '') + tag = ['') + + return ''.join(tag) + + +def additional_attributes(tag, **kwargs): + for key, data_val in kwargs.items(): + if str.startswith(key, 'data_'): + key = str.replace(key, 'data_', 'data-') + tag.append(' ' + key + '="' + data_val + '"') + return tag