A => form_guard/helpers.py +7 -0
@@ 0,0 1,7 @@
+
+
+def is_string(obj):
+ try:
+ return isinstance(obj, basestring)
+ except NameError:
+ return isinstance(obj, str)
M form_guard/templatetags/form_guard_tags.py +4 -0
@@ 1,10 1,14 @@
# -*- coding: utf-8 -*-
from django import template
+from form_guard.helpers import is_string
+
register = template.Library()
@register.inclusion_tag('form_guard/js_snippet.html', takes_context=True)
def form_guard_js(context, form):
+ if is_string(form):
+ return {'FORM_GUARD_FIELD_ID': form}
field_id = form.fields[form.FORM_GUARD_FIELD_NAME].widget.attrs.get('id')
return {'FORM_GUARD_FIELD_ID': field_id}