def as_widget(self): """Return the form as widget.""" # if there is submitted data, use that for the widget if self.raw_data is not None: data = self.raw_data # otherwise go with the data from the source (eg: database) else: data = self.data return _make_widget(self._root_field, None, data, self.errors)
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
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