Index: django/newforms/widgets.py
===================================================================
--- django/newforms/widgets.py (wersja 7609)
+++ django/newforms/widgets.py (kopia robocza)
@@ -18,7 +18,7 @@
from util import flatatt
__all__ = (
- 'Widget', 'TextInput', 'PasswordInput',
+ 'Widget', 'TextInput', 'PasswordInput', 'JsonInputs',
'HiddenInput', 'MultipleHiddenInput',
'FileInput', 'DateTimeInput', 'Textarea', 'CheckboxInput',
'Select', 'NullBooleanSelect', 'SelectMultiple', 'RadioSelect',
@@ -157,6 +157,31 @@
return mark_safe(u'' % (flatatt(final_attrs),
conditional_escape(force_unicode(value))))
+class JsonInputs(Widget):
+ def render(self, name, value, attrs=None):
+ import simplejson
+ if value is None: value = '{}'
+ value = simplejson.loads(force_unicode(value))
+ ret = ''
+ if value and len(value) > 0:
+ for key in value.keys():
+ ret += '
' % (key, value[key])
+ ret += ' '
+ return mark_safe(ret)
+ def value_from_datadict(self, data, files, name):
+ json = data.copy()
+ if json.has_key('json_key[]') and json.has_key('json_value[]'):
+ keys = json.getlist("json_key[]")
+ values = json.getlist("json_value[]")
+ jsonDict = {}
+ for (key, value) in map(None, keys, values):
+ if len(key) > 0:
+ jsonDict[key] = value
+ import simplejson
+ text = simplejson.dumps(jsonDict)
+ json['text'] = text
+ return super(JsonInputs, self).value_from_datadict(json, files, name)
+
class DateTimeInput(Input):
input_type = 'text'
format = '%Y-%m-%d %H:%M:%S' # '2006-10-25 14:30:59'