Commits

Daniil Bondarev committed 66beb65 Draft

Added get_data_dict to BaseForm.
Return dictionary with data from form's field.

  • Participants
  • Parent commits 4718015

Comments (0)

Files changed (2)

File tests/form.py

         self.assertEqual(form['test'].data, 1)
         self.assertEqual(form['foo'].data, '')
 
+    def test_get_data_dict(self):
+        form = self.get_form()
+        form.process(test='foobar')
+        data_dict = form.get_data_dict()
+        self.assertEqual(data_dict, {'test': 'foobar'})
+
     def test_populate_obj(self):
         m = type(str('Model'), (object, ), {})
         form = self.get_form()

File wtforms/form.py

         """
         return None
 
+    def get_data_dict(self):
+        """
+        Return a dictionary with data from the form's field. 
+        """
+        return {name:field.data for name, field in self._fields.iteritems()}
+
     def populate_obj(self, obj):
         """
         Populates the attributes of the passed `obj` with data from the form's