Merge branch 'master' of github.com:MongoEngine/mongoengine

This commit is contained in:
Ross Lawley
2014-06-30 10:30:12 +01:00
12 changed files with 44 additions and 23 deletions

View File

@@ -680,15 +680,18 @@ class BaseDocument(object):
if isinstance(key, (list, tuple)):
continue
# ASCENDING from +,
# ASCENDING from +
# DESCENDING from -
# GEO2D from *
# TEXT from $
direction = pymongo.ASCENDING
if key.startswith("-"):
direction = pymongo.DESCENDING
elif key.startswith("*"):
direction = pymongo.GEO2D
if key.startswith(("+", "-", "*")):
elif key.startswith("$"):
direction = pymongo.TEXT
if key.startswith(("+", "-", "*", "$")):
key = key[1:]
# Use real field name, do it manually because we need field

View File

@@ -43,7 +43,7 @@ class BaseField(object):
:param required: If the field is required. Whether it has to have a
value or not. Defaults to False.
:param default: (optional) The default value for this field if no value
has been set (or if the value has been unset). It Can be a
has been set (or if the value has been unset). It can be a
callable.
:param unique: Is the field value unique or not. Defaults to False.
:param unique_with: (optional) The other field this field should be

View File

@@ -19,7 +19,7 @@ _dbs = {}
def register_connection(alias, name, host=None, port=None,
is_slave=False, read_preference=False, slaves=None,
read_preference=False,
username=None, password=None, authentication_source=None,
**kwargs):
"""Add a connection.
@@ -29,12 +29,8 @@ def register_connection(alias, name, host=None, port=None,
:param name: the name of the specific database to use
:param host: the host name of the :program:`mongod` instance to connect to
:param port: the port that the :program:`mongod` instance is running on
:param is_slave: whether the connection can act as a slave
** Depreciated pymongo 2.0.1+
:param read_preference: The read preference for the collection
** Added pymongo 2.1
:param slaves: a list of aliases of slave connections; each of these must
be a registered connection that has :attr:`is_slave` set to ``True``
:param username: username to authenticate with
:param password: password to authenticate with
:param authentication_source: database to authenticate against
@@ -47,9 +43,7 @@ def register_connection(alias, name, host=None, port=None,
'name': name,
'host': host or 'localhost',
'port': port or 27017,
'is_slave': is_slave,
'read_preference': read_preference,
'slaves': slaves or [],
'username': username,
'password': password,
'authentication_source': authentication_source
@@ -67,6 +61,10 @@ def register_connection(alias, name, host=None, port=None,
if "replicaSet" in conn_settings['host']:
conn_settings['replicaSet'] = True
# Deprecated parameters that should not be passed on
kwargs.pop('slaves', None)
kwargs.pop('is_slave', None)
conn_settings.update(kwargs)
_connection_settings[alias] = conn_settings
@@ -97,8 +95,6 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False):
conn_settings = _connection_settings[alias].copy()
conn_settings.pop('name', None)
conn_settings.pop('slaves', None)
conn_settings.pop('is_slave', None)
conn_settings.pop('username', None)
conn_settings.pop('password', None)
conn_settings.pop('authentication_source', None)
@@ -118,8 +114,6 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False):
connection_settings_iterator = ((alias, settings.copy()) for alias, settings in _connection_settings.iteritems())
for alias, connection_settings in connection_settings_iterator:
connection_settings.pop('name', None)
connection_settings.pop('slaves', None)
connection_settings.pop('is_slave', None)
connection_settings.pop('username', None)
connection_settings.pop('password', None)
if conn_settings == connection_settings and _connections.get(alias, None):

View File

@@ -12,7 +12,7 @@ class DeReference(object):
def __call__(self, items, max_depth=1, instance=None, name=None):
"""
Cheaply dereferences the items to a set depth.
Also handles the convertion of complex data types.
Also handles the conversion of complex data types.
:param items: The iterable (dict, list, queryset) to be dereferenced.
:param max_depth: The maximum depth to recurse to

View File

@@ -601,7 +601,7 @@ class BaseQuerySet(object):
:param alias: The database alias
.. versionadded:: 0.8
.. versionadded:: 0.9
"""
with switch_db(self._document, alias) as cls: