Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions splitjson/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ def __init__(self, attrs=None, newline='<br/>\n', sep='__', debug=False):
self.newline = newline
self.separator = sep
self.debug = debug
Widget.__init__(self, attrs)
Widget.__init__(self, attrs,)

def _as_text_field(self, name, key, value, is_sub=False):
attrs = self.build_attrs(self.attrs, type='text',
name="%s%s%s" % (name, self.separator, key))
attrs['value'] = utils.encoding.force_unicode(value)
attrs['id'] = attrs.get('name', None)
return u""" <label for="%s">%s:</label>
<input%s />""" % (attrs['id'], key, flatatt(attrs))
attrs = {
'type': 'text',
'name': "%s%s%s" % (name, self.separator, key),
'value': utils.encoding.force_str(value),
'id': "%s%s%s" % (name, self.separator, key), # Use a meaningful id
}
return u"""<label for="%s">%s:</label>
<input%s />""" % (attrs['id'], key, flatatt(attrs))

def _to_build(self, name, json_obj):
inputs = []
Expand All @@ -47,7 +49,7 @@ def _to_build(self, name, json_obj):
self.separator, key),
value))
inputs.extend([_l])
elif isinstance(json_obj, (basestring, int, float)):
elif isinstance(json_obj, (str, int, float)):
name, _, key = name.rpartition(self.separator)
inputs.append(self._as_text_field(name, key, json_obj))
elif json_obj is None:
Expand Down Expand Up @@ -148,7 +150,7 @@ def value_from_datadict(self, data, files, name):
result = self._to_pack_up(name, data_copy)
return json.dumps(result)

def render(self, name, value, attrs=None):
def render(self, name, value, attrs=None, renderer=None):
try:
value = json.loads(value)
except (TypeError, KeyError):
Expand Down