Esempio n. 1
0
 def _to_hidden(value, name):
     if isinstance(value, list):
         for idx, value in enumerate(value):
             _to_hidden(value, make_name(name, idx))
     elif isinstance(value, dict):
         for key, value in value.iteritems():
             _to_hidden(value, make_name(name, key))
     else:
         _add_field(name, value)
Esempio n. 2
0
 def __getitem__(self, name):
     subwidget = self._subwidgets.get(name)
     if subwidget is None:
         # this could raise a KeyError we pass through
         subwidget = _make_widget(self._field.fields[name],
                                  make_name(self.name, name),
                                  self._value.get(name),
                                  self._all_errors)
         self._subwidgets[name] = subwidget
     return subwidget
Esempio n. 3
0
 def test_make_name(self):
     self.assertEqual(utils.make_name(None, None), 'None')
     self.assertEqual(utils.make_name(None, ()), '()')
     self.assertEqual(utils.make_name((), None), '().None')
     self.assertEqual(utils.make_name(u'abc', u'def'), 'abc.def')
     self.assertEqual(utils.make_name(u'a\xef', u'd\xef'), u'a\xef.d\xef')
     self.assertEqual(utils.make_name('a\xef', 'd\xef'), 'a\xef.d\xef')
     self.assertRaises(UnicodeDecodeError, utils.make_name, '\xef', u'ef')
Esempio n. 4
0
 def __getitem__(self, index):
     if not isinstance(index, (int, long)):
         raise TypeError('list widget indices must be integers')
     subwidget = self._subwidgets.get(index)
     if subwidget is None:
         try:
             value = self._value[index]
         except IndexError:
             # return an widget without value if we try
             # to access a field not in the list
             value = None
         subwidget = _make_widget(self._field.field,
                                  make_name(self.name, index), value,
                                  self._all_errors)
         self._subwidgets[index] = subwidget
     return subwidget
Esempio n. 5
0
 def unpack(self, form, key=None):
     rv = {}
     for name, error in self.errors.iteritems():
         rv.update(error.unpack(form, make_name(key, name)))
     return rv