Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7a1b110f62 | ||
|
db8df057ce | ||
|
5d8ffded40 | ||
|
07f3e5356d | ||
|
1ece62f960 | ||
|
056c604dc3 | ||
|
2d08eec093 | ||
|
614b590551 |
4
AUTHORS
4
AUTHORS
@@ -107,4 +107,6 @@ that much better:
|
||||
* deignacio
|
||||
* shaunduncan
|
||||
* Meir Kriheli
|
||||
* Andrey Fedoseev
|
||||
* Andrey Fedoseev
|
||||
* aparajita
|
||||
* Tristan Escalada
|
@@ -2,6 +2,12 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
Changes in 0.6.13
|
||||
================
|
||||
- Fixed EmbeddedDocument db_field validation issue
|
||||
- Fixed StringField unicode issue
|
||||
- Fixes __repr__ modifying the cursor
|
||||
|
||||
Changes in 0.6.12
|
||||
=================
|
||||
- Fixes scalar lookups for primary_key
|
||||
|
@@ -12,7 +12,7 @@ from signals import *
|
||||
__all__ = (document.__all__ + fields.__all__ + connection.__all__ +
|
||||
queryset.__all__ + signals.__all__)
|
||||
|
||||
VERSION = (0, 6, 12)
|
||||
VERSION = (0, 6, 13)
|
||||
|
||||
|
||||
def get_version():
|
||||
|
@@ -957,6 +957,8 @@ class BaseDocument(object):
|
||||
try:
|
||||
data[field_name] = (value if value is None
|
||||
else field.to_python(value))
|
||||
if field_name != field.db_field:
|
||||
del data[field.db_field]
|
||||
except (AttributeError, ValueError), e:
|
||||
errors_dict[field_name] = e
|
||||
elif field.default:
|
||||
|
@@ -87,7 +87,7 @@ class Document(BaseDocument):
|
||||
system.
|
||||
|
||||
By default, _types will be added to the start of every index (that
|
||||
doesn't contain a list) if allow_inheritence is True. This can be
|
||||
doesn't contain a list) if allow_inheritance is True. This can be
|
||||
disabled by either setting types to False on the specific index or
|
||||
by setting index_types to False on the meta dictionary for the document.
|
||||
"""
|
||||
|
@@ -49,10 +49,13 @@ class StringField(BaseField):
|
||||
super(StringField, self).__init__(**kwargs)
|
||||
|
||||
def to_python(self, value):
|
||||
return unicode(value)
|
||||
if isinstance(value, unicode):
|
||||
return value
|
||||
else:
|
||||
return value.decode('utf-8')
|
||||
|
||||
def validate(self, value):
|
||||
if not isinstance(value, (str, unicode)):
|
||||
if not isinstance(value, basestring):
|
||||
self.error('StringField only accepts string values')
|
||||
|
||||
if self.max_length is not None and len(value) > self.max_length:
|
||||
|
@@ -341,6 +341,7 @@ class QuerySet(object):
|
||||
self._timeout = True
|
||||
self._class_check = True
|
||||
self._slave_okay = False
|
||||
self._iter = False
|
||||
self._scalar = []
|
||||
|
||||
# If inheritance is allowed, only return instances and instances of
|
||||
@@ -953,6 +954,7 @@ class QuerySet(object):
|
||||
def next(self):
|
||||
"""Wrap the result in a :class:`~mongoengine.Document` object.
|
||||
"""
|
||||
self._iter = True
|
||||
try:
|
||||
if self._limit == 0:
|
||||
raise StopIteration
|
||||
@@ -969,6 +971,7 @@ class QuerySet(object):
|
||||
|
||||
.. versionadded:: 0.3
|
||||
"""
|
||||
self._iter = False
|
||||
self._cursor.rewind()
|
||||
|
||||
def count(self):
|
||||
@@ -1808,21 +1811,24 @@ class QuerySet(object):
|
||||
return data
|
||||
|
||||
def __repr__(self):
|
||||
limit = REPR_OUTPUT_SIZE + 1
|
||||
start = (0 if self._skip is None else self._skip)
|
||||
if self._limit is None:
|
||||
stop = start + limit
|
||||
if self._limit is not None:
|
||||
if self._limit - start > limit:
|
||||
stop = start + limit
|
||||
else:
|
||||
stop = self._limit
|
||||
try:
|
||||
data = list(self[start:stop])
|
||||
except pymongo.errors.InvalidOperation:
|
||||
return ".. queryset mid-iteration .."
|
||||
"""Provides the string representation of the QuerySet
|
||||
|
||||
.. versionchanged:: 0.6.13 Now doesnt modify the cursor
|
||||
"""
|
||||
|
||||
if self._iter:
|
||||
return '.. queryset mid-iteration ..'
|
||||
|
||||
data = []
|
||||
for i in xrange(REPR_OUTPUT_SIZE + 1):
|
||||
try:
|
||||
data.append(self.next())
|
||||
except StopIteration:
|
||||
break
|
||||
if len(data) > REPR_OUTPUT_SIZE:
|
||||
data[-1] = "...(remaining elements truncated)..."
|
||||
|
||||
self.rewind()
|
||||
return repr(data)
|
||||
|
||||
def select_related(self, max_depth=1):
|
||||
|
@@ -5,7 +5,7 @@
|
||||
%define srcname mongoengine
|
||||
|
||||
Name: python-%{srcname}
|
||||
Version: 0.6.12
|
||||
Version: 0.6.13
|
||||
Release: 1%{?dist}
|
||||
Summary: A Python Document-Object Mapper for working with MongoDB
|
||||
|
||||
|
@@ -1282,6 +1282,22 @@ class DocumentTest(unittest.TestCase):
|
||||
comment.date = datetime.now()
|
||||
comment.validate()
|
||||
|
||||
def test_embedded_db_field_validate(self):
|
||||
|
||||
class SubDoc(EmbeddedDocument):
|
||||
val = IntField()
|
||||
|
||||
class Doc(Document):
|
||||
e = EmbeddedDocumentField(SubDoc, db_field='eb')
|
||||
|
||||
Doc.drop_collection()
|
||||
|
||||
Doc(e=SubDoc(val=15)).save()
|
||||
|
||||
doc = Doc.objects.first()
|
||||
doc.validate()
|
||||
self.assertEquals([None, 'e'], doc._data.keys())
|
||||
|
||||
def test_save(self):
|
||||
"""Ensure that a document may be saved in the database.
|
||||
"""
|
||||
|
@@ -636,17 +636,38 @@ class QuerySetTest(unittest.TestCase):
|
||||
self.assertEqual(people1, people2)
|
||||
self.assertEqual(people1, people3)
|
||||
|
||||
def test_repr_iteration(self):
|
||||
"""Ensure that QuerySet __repr__ can handle loops
|
||||
"""
|
||||
self.Person(name='Person 1').save()
|
||||
self.Person(name='Person 2').save()
|
||||
def test_repr(self):
|
||||
"""Test repr behavior isnt destructive"""
|
||||
|
||||
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))
|
||||
class Doc(Document):
|
||||
number = IntField()
|
||||
|
||||
def __repr__(self):
|
||||
return "<Doc: %s>" % self.number
|
||||
|
||||
Doc.drop_collection()
|
||||
|
||||
for i in xrange(1000):
|
||||
Doc(number=i).save()
|
||||
|
||||
docs = Doc.objects.order_by('number')
|
||||
|
||||
self.assertEquals(docs.count(), 1000)
|
||||
self.assertEquals(len(docs), 1000)
|
||||
|
||||
docs_string = "%s" % docs
|
||||
self.assertTrue("Doc: 0" in docs_string)
|
||||
|
||||
self.assertEquals(docs.count(), 1000)
|
||||
self.assertEquals(len(docs), 1000)
|
||||
|
||||
# Limit and skip
|
||||
self.assertEquals('[<Doc: 1>, <Doc: 2>, <Doc: 3>]', "%s" % docs[1:4])
|
||||
|
||||
self.assertEquals(docs.count(), 3)
|
||||
self.assertEquals(len(docs), 3)
|
||||
for doc in docs:
|
||||
self.assertEqual('.. queryset mid-iteration ..', repr(docs))
|
||||
|
||||
def test_regex_query_shortcuts(self):
|
||||
"""Ensure that contains, startswith, endswith, etc work.
|
||||
|
Reference in New Issue
Block a user