Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
5f4b70f3a9 | ||
|
51b429e5b0 | ||
|
360624eb6e | ||
|
d9d2291837 | ||
|
cbdf816232 | ||
|
2d71eb8a18 | ||
|
64d2532ce9 | ||
|
0376910f33 | ||
|
6d503119a1 | ||
|
bfae93e57e | ||
|
d0e42a4798 | ||
|
2a34358abc | ||
|
fd2bb8ea45 | ||
|
98e5daa0e0 | ||
|
ad2e119282 | ||
|
c20c30d8d1 | ||
|
66d215c9c1 | ||
|
46e088d379 | ||
|
bbdd15161a | ||
|
ea9dc8cfb8 | ||
|
6bd2ccc9bf | ||
|
56327c6b58 | ||
|
712e8a51e4 | ||
|
421f324f9e | ||
|
8fe4a70299 | ||
|
3af6d0dbfd | ||
|
e2bef076d3 | ||
|
1bf9f28f4b | ||
|
f1e7b97a93 | ||
|
8cfe13ad90 | ||
|
0f420abc8e | ||
|
3b5b715567 | ||
|
520051af25 | ||
|
fd18a48608 | ||
|
64860c6287 | ||
|
58635b24ba | ||
|
3ec9dfc108 | ||
|
bd1572f11a | ||
|
95c58bd793 | ||
|
65591c7727 | ||
|
737cbf5f60 | ||
|
4c67cbb4b7 | ||
|
ed2cc2a60b | ||
|
61411bb259 | ||
|
fcdb0eff8f | ||
|
30d9347272 |
3
AUTHORS
3
AUTHORS
@@ -97,3 +97,6 @@ that much better:
|
|||||||
* Shalabh Aggarwal
|
* Shalabh Aggarwal
|
||||||
* Chris Williams
|
* Chris Williams
|
||||||
* Robert Kajic
|
* Robert Kajic
|
||||||
|
* Jacob Peddicord
|
||||||
|
* Nils Hasenbanck
|
||||||
|
* mostlystatic
|
@@ -2,7 +2,30 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
Changes in 0.6.x
|
Changes in 0.6.4
|
||||||
|
================
|
||||||
|
|
||||||
|
- Refactored connection / fixed replicasetconnection
|
||||||
|
- Bug fix for unknown connection alias error message
|
||||||
|
- Sessions support Django 1.3 and Django 1.4
|
||||||
|
- Minor fix for ReferenceField
|
||||||
|
|
||||||
|
Changes in 0.6.3
|
||||||
|
================
|
||||||
|
- Updated sessions for Django 1.4
|
||||||
|
- Bug fix for updates where listfields contain embedded documents
|
||||||
|
- Bug fix for collection naming and mixins
|
||||||
|
|
||||||
|
Changes in 0.6.2
|
||||||
|
================
|
||||||
|
- Updated documentation for ReplicaSet connections
|
||||||
|
- Hack round _types issue with SERVER-5247 - querying other arrays may also cause problems.
|
||||||
|
|
||||||
|
Changes in 0.6.1
|
||||||
|
================
|
||||||
|
- Fix for replicaSet connections
|
||||||
|
|
||||||
|
Changes in 0.6
|
||||||
================
|
================
|
||||||
|
|
||||||
- Added FutureWarning to inherited classes not declaring 'allow_inheritance' as the default will change in 0.7
|
- Added FutureWarning to inherited classes not declaring 'allow_inheritance' as the default will change in 0.7
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
Using MongoEngine with Django
|
Using MongoEngine with Django
|
||||||
=============================
|
=============================
|
||||||
|
|
||||||
|
.. note :: Updated to support Django 1.4
|
||||||
|
|
||||||
Connecting
|
Connecting
|
||||||
==========
|
==========
|
||||||
In your **settings.py** file, ignore the standard database settings (unless you
|
In your **settings.py** file, ignore the standard database settings (unless you
|
||||||
|
@@ -26,7 +26,12 @@ name - just supply the uri as the :attr:`host` to
|
|||||||
|
|
||||||
connect('project1', host='mongodb://localhost/database_name')
|
connect('project1', host='mongodb://localhost/database_name')
|
||||||
|
|
||||||
|
ReplicaSets
|
||||||
|
===========
|
||||||
|
|
||||||
|
MongoEngine now supports :func:`~pymongo.replica_set_connection.ReplicaSetConnection`
|
||||||
|
to use them please use a URI style connection and provide the `replicaSet` name in the
|
||||||
|
connection kwargs.
|
||||||
|
|
||||||
Multiple Databases
|
Multiple Databases
|
||||||
==================
|
==================
|
||||||
|
@@ -5,15 +5,13 @@ Signals
|
|||||||
|
|
||||||
.. versionadded:: 0.5
|
.. versionadded:: 0.5
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
Signal support is provided by the excellent `blinker`_ library and
|
Signal support is provided by the excellent `blinker`_ library and
|
||||||
will gracefully fall back if it is not available.
|
will gracefully fall back if it is not available.
|
||||||
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
The following document signals exist in MongoEngine and are pretty self explanatory:
|
|
||||||
=======
|
|
||||||
The following document signals exist in MongoEngine and are pretty self-explanatory:
|
The following document signals exist in MongoEngine and are pretty self-explanatory:
|
||||||
>>>>>>> master
|
|
||||||
|
|
||||||
* `mongoengine.signals.pre_init`
|
* `mongoengine.signals.pre_init`
|
||||||
* `mongoengine.signals.post_init`
|
* `mongoengine.signals.post_init`
|
||||||
|
@@ -18,6 +18,8 @@ Document.objects.with_id - now raises an InvalidQueryError if used with a filter
|
|||||||
FutureWarning - A future warning has been added to all inherited classes that
|
FutureWarning - A future warning has been added to all inherited classes that
|
||||||
don't define `allow_inheritance` in their meta.
|
don't define `allow_inheritance` in their meta.
|
||||||
|
|
||||||
|
You may need to update pyMongo to 2.0 for use with Sharding.
|
||||||
|
|
||||||
0.4 to 0.5
|
0.4 to 0.5
|
||||||
===========
|
===========
|
||||||
|
|
||||||
@@ -74,7 +76,7 @@ To upgrade use a Mixin class to set meta like so ::
|
|||||||
class MyAceDocument(Document, BaseMixin):
|
class MyAceDocument(Document, BaseMixin):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
MyAceDocument._get_collection_name() == myacedocument
|
MyAceDocument._get_collection_name() == "myacedocument"
|
||||||
|
|
||||||
Alternatively, you can rename your collections eg ::
|
Alternatively, you can rename your collections eg ::
|
||||||
|
|
||||||
|
@@ -12,7 +12,7 @@ from signals import *
|
|||||||
__all__ = (document.__all__ + fields.__all__ + connection.__all__ +
|
__all__ = (document.__all__ + fields.__all__ + connection.__all__ +
|
||||||
queryset.__all__ + signals.__all__)
|
queryset.__all__ + signals.__all__)
|
||||||
|
|
||||||
VERSION = (0, 6, 1)
|
VERSION = (0, 6, 4)
|
||||||
|
|
||||||
|
|
||||||
def get_version():
|
def get_version():
|
||||||
|
@@ -478,13 +478,18 @@ class DocumentMetaclass(type):
|
|||||||
attrs.update(dict([(k, v) for k, v in base.__dict__.items()
|
attrs.update(dict([(k, v) for k, v in base.__dict__.items()
|
||||||
if issubclass(v.__class__, BaseField)]))
|
if issubclass(v.__class__, BaseField)]))
|
||||||
|
|
||||||
|
# Handle simple mixin's with meta
|
||||||
|
if hasattr(base, 'meta') and not isinstance(base, DocumentMetaclass):
|
||||||
|
meta = attrs.get('meta', {})
|
||||||
|
meta.update(base.meta)
|
||||||
|
attrs['meta'] = meta
|
||||||
|
|
||||||
for p_base in base.__bases__:
|
for p_base in base.__bases__:
|
||||||
#optimize :-)
|
#optimize :-)
|
||||||
if p_base in (object, BaseDocument):
|
if p_base in (object, BaseDocument):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
attrs.update(_get_mixin_fields(p_base))
|
attrs.update(_get_mixin_fields(p_base))
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
metaclass = attrs.get('__metaclass__')
|
metaclass = attrs.get('__metaclass__')
|
||||||
@@ -498,6 +503,7 @@ class DocumentMetaclass(type):
|
|||||||
simple_class = True
|
simple_class = True
|
||||||
|
|
||||||
for base in bases:
|
for base in bases:
|
||||||
|
|
||||||
# Include all fields present in superclasses
|
# Include all fields present in superclasses
|
||||||
if hasattr(base, '_fields'):
|
if hasattr(base, '_fields'):
|
||||||
doc_fields.update(base._fields)
|
doc_fields.update(base._fields)
|
||||||
@@ -526,7 +532,8 @@ class DocumentMetaclass(type):
|
|||||||
simple_class = False
|
simple_class = False
|
||||||
|
|
||||||
doc_class_name = '.'.join(reversed(class_name))
|
doc_class_name = '.'.join(reversed(class_name))
|
||||||
meta = attrs.get('_meta', attrs.get('meta', {}))
|
meta = attrs.get('_meta', {})
|
||||||
|
meta.update(attrs.get('meta', {}))
|
||||||
|
|
||||||
if 'allow_inheritance' not in meta:
|
if 'allow_inheritance' not in meta:
|
||||||
meta['allow_inheritance'] = True
|
meta['allow_inheritance'] = True
|
||||||
|
@@ -39,22 +39,7 @@ def register_connection(alias, name, host='localhost', port=27017,
|
|||||||
"""
|
"""
|
||||||
global _connection_settings
|
global _connection_settings
|
||||||
|
|
||||||
# Handle uri style connections
|
conn_settings = {
|
||||||
if "://" in host:
|
|
||||||
uri_dict = uri_parser.parse_uri(host)
|
|
||||||
if uri_dict.get('database') is None:
|
|
||||||
raise ConnectionError("If using URI style connection include "\
|
|
||||||
"database name in string")
|
|
||||||
_connection_settings[alias] = {
|
|
||||||
'host': host,
|
|
||||||
'name': uri_dict.get('database'),
|
|
||||||
'username': uri_dict.get('username'),
|
|
||||||
'password': uri_dict.get('password')
|
|
||||||
}
|
|
||||||
_connection_settings[alias].update(kwargs)
|
|
||||||
return
|
|
||||||
|
|
||||||
_connection_settings[alias] = {
|
|
||||||
'name': name,
|
'name': name,
|
||||||
'host': host,
|
'host': host,
|
||||||
'port': port,
|
'port': port,
|
||||||
@@ -64,7 +49,22 @@ def register_connection(alias, name, host='localhost', port=27017,
|
|||||||
'password': password,
|
'password': password,
|
||||||
'read_preference': read_preference
|
'read_preference': read_preference
|
||||||
}
|
}
|
||||||
_connection_settings[alias].update(kwargs)
|
|
||||||
|
# Handle uri style connections
|
||||||
|
if "://" in host:
|
||||||
|
uri_dict = uri_parser.parse_uri(host)
|
||||||
|
if uri_dict.get('database') is None:
|
||||||
|
raise ConnectionError("If using URI style connection include "\
|
||||||
|
"database name in string")
|
||||||
|
conn_settings.update({
|
||||||
|
'host': host,
|
||||||
|
'name': uri_dict.get('database'),
|
||||||
|
'username': uri_dict.get('username'),
|
||||||
|
'password': uri_dict.get('password'),
|
||||||
|
'read_preference': read_preference,
|
||||||
|
})
|
||||||
|
|
||||||
|
_connection_settings[alias] = conn_settings
|
||||||
|
|
||||||
|
|
||||||
def disconnect(alias=DEFAULT_CONNECTION_NAME):
|
def disconnect(alias=DEFAULT_CONNECTION_NAME):
|
||||||
@@ -86,7 +86,7 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False):
|
|||||||
|
|
||||||
if alias not in _connections:
|
if alias not in _connections:
|
||||||
if alias not in _connection_settings:
|
if alias not in _connection_settings:
|
||||||
msg = 'Connection with alias "%s" has not been defined'
|
msg = 'Connection with alias "%s" has not been defined' % alias
|
||||||
if alias == DEFAULT_CONNECTION_NAME:
|
if alias == DEFAULT_CONNECTION_NAME:
|
||||||
msg = 'You have not defined a default connection'
|
msg = 'You have not defined a default connection'
|
||||||
raise ConnectionError(msg)
|
raise ConnectionError(msg)
|
||||||
@@ -105,11 +105,13 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False):
|
|||||||
for slave_alias in conn_settings['slaves']:
|
for slave_alias in conn_settings['slaves']:
|
||||||
slaves.append(get_connection(slave_alias))
|
slaves.append(get_connection(slave_alias))
|
||||||
conn_settings['slaves'] = slaves
|
conn_settings['slaves'] = slaves
|
||||||
conn_settings.pop('read_preference')
|
conn_settings.pop('read_preference', None)
|
||||||
|
|
||||||
connection_class = Connection
|
connection_class = Connection
|
||||||
if 'replicaSet' in conn_settings:
|
if 'replicaSet' in conn_settings:
|
||||||
conn_settings['hosts_or_uri'] = conn_settings.pop('host', None)
|
conn_settings['hosts_or_uri'] = conn_settings.pop('host', None)
|
||||||
|
# Discard port since it can't be used on ReplicaSetConnection
|
||||||
|
conn_settings.pop('port', None)
|
||||||
connection_class = ReplicaSetConnection
|
connection_class = ReplicaSetConnection
|
||||||
try:
|
try:
|
||||||
_connections[alias] = connection_class(**conn_settings)
|
_connections[alias] = connection_class(**conn_settings)
|
||||||
|
@@ -1,13 +1,15 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
from mongoengine import *
|
from mongoengine import *
|
||||||
|
|
||||||
from django.utils.hashcompat import md5_constructor, sha_constructor
|
|
||||||
from django.utils.encoding import smart_str
|
from django.utils.encoding import smart_str
|
||||||
from django.contrib.auth.models import AnonymousUser
|
from django.contrib.auth.models import AnonymousUser
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
import datetime
|
try:
|
||||||
|
from django.contrib.auth.hashers import check_password, make_password
|
||||||
REDIRECT_FIELD_NAME = 'next'
|
except ImportError:
|
||||||
|
"""Handle older versions of Django"""
|
||||||
|
|
||||||
def get_hexdigest(algorithm, salt, raw_password):
|
def get_hexdigest(algorithm, salt, raw_password):
|
||||||
raw_password, salt = smart_str(raw_password), smart_str(salt)
|
raw_password, salt = smart_str(raw_password), smart_str(salt)
|
||||||
@@ -17,6 +19,19 @@ def get_hexdigest(algorithm, salt, raw_password):
|
|||||||
return sha_constructor(salt + raw_password).hexdigest()
|
return sha_constructor(salt + raw_password).hexdigest()
|
||||||
raise ValueError('Got unknown password algorithm type in password')
|
raise ValueError('Got unknown password algorithm type in password')
|
||||||
|
|
||||||
|
def check_password(raw_password, password):
|
||||||
|
algo, salt, hash = password.split('$')
|
||||||
|
return hash == get_hexdigest(algo, salt, raw_password)
|
||||||
|
|
||||||
|
def make_password(raw_password):
|
||||||
|
from random import random
|
||||||
|
algo = 'sha1'
|
||||||
|
salt = get_hexdigest(algo, str(random()), str(random()))[:5]
|
||||||
|
hash = get_hexdigest(algo, salt, raw_password)
|
||||||
|
return '%s$%s$%s' % (algo, salt, hash)
|
||||||
|
|
||||||
|
|
||||||
|
REDIRECT_FIELD_NAME = 'next'
|
||||||
|
|
||||||
class User(Document):
|
class User(Document):
|
||||||
"""A User document that aims to mirror most of the API specified by Django
|
"""A User document that aims to mirror most of the API specified by Django
|
||||||
@@ -34,7 +49,7 @@ class User(Document):
|
|||||||
email = EmailField(verbose_name=_('e-mail address'))
|
email = EmailField(verbose_name=_('e-mail address'))
|
||||||
password = StringField(max_length=128,
|
password = StringField(max_length=128,
|
||||||
verbose_name=_('password'),
|
verbose_name=_('password'),
|
||||||
help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
|
help_text=_("Use '[algo]$[iterations]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
|
||||||
is_staff = BooleanField(default=False,
|
is_staff = BooleanField(default=False,
|
||||||
verbose_name=_('staff status'),
|
verbose_name=_('staff status'),
|
||||||
help_text=_("Designates whether the user can log into this admin site."))
|
help_text=_("Designates whether the user can log into this admin site."))
|
||||||
@@ -75,11 +90,7 @@ class User(Document):
|
|||||||
assigning to :attr:`~mongoengine.django.auth.User.password` as the
|
assigning to :attr:`~mongoengine.django.auth.User.password` as the
|
||||||
password is hashed before storage.
|
password is hashed before storage.
|
||||||
"""
|
"""
|
||||||
from random import random
|
self.password = make_password(raw_password)
|
||||||
algo = 'sha1'
|
|
||||||
salt = get_hexdigest(algo, str(random()), str(random()))[:5]
|
|
||||||
hash = get_hexdigest(algo, salt, raw_password)
|
|
||||||
self.password = '%s$%s$%s' % (algo, salt, hash)
|
|
||||||
self.save()
|
self.save()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@@ -89,8 +100,7 @@ class User(Document):
|
|||||||
:attr:`~mongoengine.django.auth.User.password` as the password is
|
:attr:`~mongoengine.django.auth.User.password` as the password is
|
||||||
hashed before storage.
|
hashed before storage.
|
||||||
"""
|
"""
|
||||||
algo, salt, hash = self.password.split('$')
|
return check_password(raw_password, self.password)
|
||||||
return hash == get_hexdigest(algo, salt, raw_password)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_user(cls, username, password, email=None):
|
def create_user(cls, username, password, email=None):
|
||||||
|
@@ -1,3 +1,6 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.sessions.backends.base import SessionBase, CreateError
|
from django.contrib.sessions.backends.base import SessionBase, CreateError
|
||||||
from django.core.exceptions import SuspiciousOperation
|
from django.core.exceptions import SuspiciousOperation
|
||||||
from django.utils.encoding import force_unicode
|
from django.utils.encoding import force_unicode
|
||||||
@@ -6,13 +9,13 @@ from mongoengine.document import Document
|
|||||||
from mongoengine import fields
|
from mongoengine import fields
|
||||||
from mongoengine.queryset import OperationError
|
from mongoengine.queryset import OperationError
|
||||||
from mongoengine.connection import DEFAULT_CONNECTION_NAME
|
from mongoengine.connection import DEFAULT_CONNECTION_NAME
|
||||||
from django.conf import settings
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
MONGOENGINE_SESSION_DB_ALIAS = getattr(
|
MONGOENGINE_SESSION_DB_ALIAS = getattr(
|
||||||
settings, 'MONGOENGINE_SESSION_DB_ALIAS',
|
settings, 'MONGOENGINE_SESSION_DB_ALIAS',
|
||||||
DEFAULT_CONNECTION_NAME)
|
DEFAULT_CONNECTION_NAME)
|
||||||
|
|
||||||
|
|
||||||
class MongoSession(Document):
|
class MongoSession(Document):
|
||||||
session_key = fields.StringField(primary_key=True, max_length=40)
|
session_key = fields.StringField(primary_key=True, max_length=40)
|
||||||
session_data = fields.StringField()
|
session_data = fields.StringField()
|
||||||
@@ -51,6 +54,8 @@ class SessionStore(SessionBase):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def save(self, must_create=False):
|
def save(self, must_create=False):
|
||||||
|
if self.session_key is None:
|
||||||
|
self.create()
|
||||||
s = MongoSession(session_key=self.session_key)
|
s = MongoSession(session_key=self.session_key)
|
||||||
s.session_data = self.encode(self._get_session(no_load=must_create))
|
s.session_data = self.encode(self._get_session(no_load=must_create))
|
||||||
s.expire_date = self.get_expiry_date()
|
s.expire_date = self.get_expiry_date()
|
||||||
|
@@ -8,7 +8,7 @@ import uuid
|
|||||||
from bson import Binary, DBRef, SON, ObjectId
|
from bson import Binary, DBRef, SON, ObjectId
|
||||||
|
|
||||||
from base import (BaseField, ComplexBaseField, ObjectIdField,
|
from base import (BaseField, ComplexBaseField, ObjectIdField,
|
||||||
ValidationError, get_document)
|
ValidationError, get_document, BaseDocument)
|
||||||
from queryset import DO_NOTHING, QuerySet
|
from queryset import DO_NOTHING, QuerySet
|
||||||
from document import Document, EmbeddedDocument
|
from document import Document, EmbeddedDocument
|
||||||
from connection import get_db, DEFAULT_CONNECTION_NAME
|
from connection import get_db, DEFAULT_CONNECTION_NAME
|
||||||
@@ -497,6 +497,7 @@ class ListField(ComplexBaseField):
|
|||||||
def prepare_query_value(self, op, value):
|
def prepare_query_value(self, op, value):
|
||||||
if self.field:
|
if self.field:
|
||||||
if op in ('set', 'unset') and (not isinstance(value, basestring)
|
if op in ('set', 'unset') and (not isinstance(value, basestring)
|
||||||
|
and not isinstance(value, BaseDocument)
|
||||||
and hasattr(value, '__iter__')):
|
and hasattr(value, '__iter__')):
|
||||||
return [self.field.prepare_query_value(op, v) for v in value]
|
return [self.field.prepare_query_value(op, v) for v in value]
|
||||||
return self.field.prepare_query_value(op, value)
|
return self.field.prepare_query_value(op, value)
|
||||||
@@ -656,6 +657,9 @@ class ReferenceField(BaseField):
|
|||||||
return super(ReferenceField, self).__get__(instance, owner)
|
return super(ReferenceField, self).__get__(instance, owner)
|
||||||
|
|
||||||
def to_mongo(self, document):
|
def to_mongo(self, document):
|
||||||
|
if isinstance(document, DBRef):
|
||||||
|
return document
|
||||||
|
|
||||||
id_field_name = self.document_type._meta['id_field']
|
id_field_name = self.document_type._meta['id_field']
|
||||||
id_field = self.document_type._fields[id_field_name]
|
id_field = self.document_type._fields[id_field_name]
|
||||||
|
|
||||||
|
@@ -1371,8 +1371,15 @@ class QuerySet(object):
|
|||||||
write_options = {}
|
write_options = {}
|
||||||
|
|
||||||
update = QuerySet._transform_update(self._document, **update)
|
update = QuerySet._transform_update(self._document, **update)
|
||||||
|
query = self._query
|
||||||
|
|
||||||
|
# SERVER-5247 hack
|
||||||
|
remove_types = "_types" in query and ".$." in unicode(update)
|
||||||
|
if remove_types:
|
||||||
|
del query["_types"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ret = self._collection.update(self._query, update, multi=multi,
|
ret = self._collection.update(query, update, multi=multi,
|
||||||
upsert=upsert, safe=safe_update,
|
upsert=upsert, safe=safe_update,
|
||||||
**write_options)
|
**write_options)
|
||||||
if ret is not None and 'n' in ret:
|
if ret is not None and 'n' in ret:
|
||||||
@@ -1400,10 +1407,17 @@ class QuerySet(object):
|
|||||||
if not write_options:
|
if not write_options:
|
||||||
write_options = {}
|
write_options = {}
|
||||||
update = QuerySet._transform_update(self._document, **update)
|
update = QuerySet._transform_update(self._document, **update)
|
||||||
|
query = self._query
|
||||||
|
|
||||||
|
# SERVER-5247 hack
|
||||||
|
remove_types = "_types" in query and ".$." in unicode(update)
|
||||||
|
if remove_types:
|
||||||
|
del query["_types"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Explicitly provide 'multi=False' to newer versions of PyMongo
|
# Explicitly provide 'multi=False' to newer versions of PyMongo
|
||||||
# as the default may change to 'True'
|
# as the default may change to 'True'
|
||||||
ret = self._collection.update(self._query, update, multi=False,
|
ret = self._collection.update(query, update, multi=False,
|
||||||
upsert=upsert, safe=safe_update,
|
upsert=upsert, safe=safe_update,
|
||||||
**write_options)
|
**write_options)
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
%define srcname mongoengine
|
%define srcname mongoengine
|
||||||
|
|
||||||
Name: python-%{srcname}
|
Name: python-%{srcname}
|
||||||
Version: 0.6.1
|
Version: 0.6.4
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
Summary: A Python Document-Object Mapper for working with MongoDB
|
Summary: A Python Document-Object Mapper for working with MongoDB
|
||||||
|
|
||||||
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pymongo
|
@@ -96,7 +96,7 @@ class DocumentTest(unittest.TestCase):
|
|||||||
# Ensure Document isn't treated like an actual document
|
# Ensure Document isn't treated like an actual document
|
||||||
self.assertFalse(hasattr(Document, '_fields'))
|
self.assertFalse(hasattr(Document, '_fields'))
|
||||||
|
|
||||||
def test_collection_name(self):
|
def test_collection_naming(self):
|
||||||
"""Ensure that a collection with a specified name may be used.
|
"""Ensure that a collection with a specified name may be used.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -157,11 +157,12 @@ class DocumentTest(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
class BaseDocument(Document, BaseMixin):
|
class BaseDocument(Document, BaseMixin):
|
||||||
pass
|
meta = {'allow_inheritance': True}
|
||||||
|
|
||||||
class MyDocument(BaseDocument):
|
class MyDocument(BaseDocument):
|
||||||
pass
|
pass
|
||||||
self.assertEquals('mydocument', OldMixinNamingConvention._get_collection_name())
|
|
||||||
|
self.assertEquals('basedocument', MyDocument._get_collection_name())
|
||||||
|
|
||||||
def test_get_superclasses(self):
|
def test_get_superclasses(self):
|
||||||
"""Ensure that the correct list of superclasses is assembled.
|
"""Ensure that the correct list of superclasses is assembled.
|
||||||
|
@@ -329,11 +329,11 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
|
|
||||||
BlogPost(title="ABC", comments=[c1, c2]).save()
|
BlogPost(title="ABC", comments=[c1, c2]).save()
|
||||||
|
|
||||||
BlogPost.objects(comments__by="joe").update(inc__comments__S__votes=1)
|
BlogPost.objects(comments__by="jane").update(inc__comments__S__votes=1)
|
||||||
|
|
||||||
post = BlogPost.objects.first()
|
post = BlogPost.objects.first()
|
||||||
self.assertEquals(post.comments[0].by, 'joe')
|
self.assertEquals(post.comments[1].by, 'jane')
|
||||||
self.assertEquals(post.comments[0].votes, 4)
|
self.assertEquals(post.comments[1].votes, 8)
|
||||||
|
|
||||||
# Currently the $ operator only applies to the first matched item in
|
# Currently the $ operator only applies to the first matched item in
|
||||||
# the query
|
# the query
|
||||||
@@ -1518,6 +1518,37 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
|
|
||||||
BlogPost.drop_collection()
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_list_embedded_documents(self):
|
||||||
|
|
||||||
|
class Author(EmbeddedDocument):
|
||||||
|
name = StringField()
|
||||||
|
|
||||||
|
class Message(Document):
|
||||||
|
title = StringField()
|
||||||
|
authors = ListField(EmbeddedDocumentField('Author'))
|
||||||
|
|
||||||
|
Message.drop_collection()
|
||||||
|
|
||||||
|
message = Message(title="hello", authors=[Author(name="Harry")])
|
||||||
|
message.save()
|
||||||
|
|
||||||
|
Message.objects(authors__name="Harry").update_one(
|
||||||
|
set__authors__S=Author(name="Ross"))
|
||||||
|
|
||||||
|
message = message.reload()
|
||||||
|
self.assertEquals(message.authors[0].name, "Ross")
|
||||||
|
|
||||||
|
Message.objects(authors__name="Ross").update_one(
|
||||||
|
set__authors=[Author(name="Harry"),
|
||||||
|
Author(name="Ross"),
|
||||||
|
Author(name="Adam")])
|
||||||
|
|
||||||
|
message = message.reload()
|
||||||
|
self.assertEquals(message.authors[0].name, "Harry")
|
||||||
|
self.assertEquals(message.authors[1].name, "Ross")
|
||||||
|
self.assertEquals(message.authors[2].name, "Adam")
|
||||||
|
|
||||||
def test_order_by(self):
|
def test_order_by(self):
|
||||||
"""Ensure that QuerySets may be ordered.
|
"""Ensure that QuerySets may be ordered.
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user