Skip to content

Commit

Permalink
More lenient data validation in process()
Browse files Browse the repository at this point in the history
  • Loading branch information
ckirby committed Oct 21, 2015
1 parent 5ccf31a commit 676a975
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion modelqueryform/__init__.py
@@ -1 +1 @@
__version__ = "1.1.0"
__version__ = "1.2.0"
10 changes: 3 additions & 7 deletions modelqueryform/forms.py
Expand Up @@ -198,13 +198,9 @@ def process(self, data_set=None):
if data_set is None:
data_set = self.model.objects.all()

if not data_set.exists():
raise ImproperlyConfigured("process requires a QuerySet to filter."
"Run as form.process(QuerySet)"
)

if not data_set[0]._meta.fields == self.model._meta.fields:
raise TypeError("Match the QuerySet to this form instances Model")
else:
if data_set.first() is not None and not data_set.first()._meta.fields == self.model._meta.fields:
raise TypeError("Match the QuerySet to this form instances Model")

filters = self.get_filters()

Expand Down
5 changes: 1 addition & 4 deletions tests/test_forms.py
Expand Up @@ -103,10 +103,7 @@ def test_process_without_data_without_filters(self):
def test_process_empty_dataset(self):
form = FormTest({})
form.is_valid()
self.assertRaises(ImproperlyConfigured,
form.process,
BaseModelForTest.objects.filter(integer=3)
)
self.assertEqual(len(form.process(BaseModelForTest.objects.filter(integer=3))), 0, 'Should be empty')

def test_process_model_mismatch(self):
form = FormTest({})
Expand Down

0 comments on commit 676a975

Please sign in to comment.