Fixed queryset repr mid iteration

Closes #144
This commit is contained in:
Ross Lawley 2011-06-17 15:04:07 +01:00
parent f3d265bbe0
commit 99f923e27f
3 changed files with 17 additions and 1 deletions

View File

@ -5,6 +5,7 @@ Changelog
Changes in dev
==============
- Fixed queryet __repr__ mid iteration
- Added hint() support, so cantell Mongo the proper index to use for the query
- Fixed issue with inconsitent setting of _cls breaking inherited referencing
- Added help_text and verbose_name to fields to help with some form libs

View File

@ -1524,7 +1524,10 @@ class QuerySet(object):
limit = REPR_OUTPUT_SIZE + 1
if self._limit is not None and self._limit < limit:
limit = self._limit
data = list(self[self._skip:limit])
try:
data = list(self[self._skip:limit])
except pymongo.errors.InvalidOperation:
return ".. queryset mid-iteration .."
if len(data) > REPR_OUTPUT_SIZE:
data[-1] = "...(remaining elements truncated)..."
return repr(data)

View File

@ -463,6 +463,18 @@ class QuerySetTest(unittest.TestCase):
self.assertEqual(people1, people2)
def test_repr_iteration(self):
"""Ensure that QuerySet __repr__ can handle loops
"""
self.Person(name='Person 1').save()
self.Person(name='Person 2').save()
queryset = self.Person.objects
self.assertEquals('[<Person: Person object>, <Person: Person object>]', repr(queryset))
for person in queryset:
self.assertEquals('.. queryset mid-iteration ..', repr(queryset))
def test_regex_query_shortcuts(self):
"""Ensure that contains, startswith, endswith, etc work.
"""