Skip to content

Commit 0aeb1ca

Browse files
committed
Various fixes again
1 parent cd76a90 commit 0aeb1ca

File tree

22 files changed

+88
-89
lines changed

22 files changed

+88
-89
lines changed

docs/_themes/sphinx_rtd_theme/footer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% if next or prev %}
33
<div class="rst-footer-buttons">
44
{% if next %}
5-
<a href="{{ next.link|e }}" class="btn btn-neutral float-right" title="{{ next.title|striptags|e }}"/>Next <span class="icon icon-circle-arrow-right"></span></a>
5+
<a href="{{ next.link|e }}" class="btn btn-neutral float-right" title="{{ next.title|striptags|e }}">Next <span class="icon icon-circle-arrow-right"></span></a>
66
{% endif %}
77
{% if prev %}
88
<a href="{{ prev.link|e }}" class="btn btn-neutral" title="{{ prev.title|striptags|e }}"><span class="icon icon-circle-arrow-left"></span> Previous</a>

docs/guide/querying.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ Some variables are made available in the scope of the Javascript function:
598598

599599
The following example demonstrates the intended usage of
600600
:meth:`~mongoengine.queryset.QuerySet.exec_js` by defining a function that sums
601-
over a field on a document (this functionality is already available throught
601+
over a field on a document (this functionality is already available through
602602
:meth:`~mongoengine.queryset.QuerySet.sum` but is shown here for sake of
603603
example)::
604604

mongoengine/base/datastructures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def __repr__(self):
443443

444444

445445
class SemiStrictDict(StrictDict):
446-
__slots__ = ('_extras')
446+
__slots__ = ('_extras', )
447447
_classes = {}
448448

449449
def __getattr__(self, attr):

mongoengine/base/document.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ def __setattr__(self, name, value):
149149
# Handle dynamic data only if an initialised dynamic document
150150
if self._dynamic and not self._dynamic_lock:
151151

152-
field = None
153152
if not hasattr(self, name) and not name.startswith('_'):
154153
DynamicField = _import_class("DynamicField")
155154
field = DynamicField(db_field=name)
@@ -182,8 +181,8 @@ def __setattr__(self, name, value):
182181
except AttributeError:
183182
self__initialised = False
184183
# Check if the user has created a new instance of a class
185-
if (self._is_document and self__initialised
186-
and self__created and name == self._meta.get('id_field')):
184+
if (self._is_document and self__initialised and
185+
self__created and name == self._meta.get('id_field')):
187186
super(BaseDocument, self).__setattr__('_created', False)
188187

189188
super(BaseDocument, self).__setattr__(name, value)
@@ -327,7 +326,7 @@ def to_mongo(self, use_db_field=True, fields=None):
327326

328327
if value is not None:
329328

330-
if isinstance(field, (EmbeddedDocumentField)):
329+
if isinstance(field, EmbeddedDocumentField):
331330
if fields:
332331
key = '%s.' % field_name
333332
embedded_fields = [
@@ -416,7 +415,8 @@ def validate(self, clean=True):
416415

417416
def to_json(self, *args, **kwargs):
418417
"""Converts a document to JSON.
419-
:param use_db_field: Set to True by default but enables the output of the json structure with the field names and not the mongodb store db_names in case of set to False
418+
:param use_db_field: Set to True by default but enables the output of the json structure with the field names
419+
and not the mongodb store db_names in case of set to False
420420
"""
421421
use_db_field = kwargs.pop('use_db_field', True)
422422
return json_util.dumps(self.to_mongo(use_db_field), *args, **kwargs)
@@ -577,7 +577,7 @@ def _get_changed_fields(self, inspected=None):
577577
if (hasattr(field, 'field') and
578578
isinstance(field.field, ReferenceField)):
579579
continue
580-
elif (isinstance(field, SortedListField) and field._ordering):
580+
elif isinstance(field, SortedListField) and field._ordering:
581581
# if ordering is affected whole list is changed
582582
if any(map(lambda d: field._ordering in d._changed_fields, data)):
583583
changed_fields.append(db_field_name)
@@ -627,7 +627,7 @@ def _delta(self):
627627
if value or isinstance(value, (numbers.Number, bool)):
628628
continue
629629

630-
# If we've set a value that ain't the default value dont unset it.
630+
# If we've set a value that ain't the default value don't unset it.
631631
default = None
632632
if (self._dynamic and len(parts) and parts[0] in
633633
self._dynamic_fields):
@@ -979,7 +979,7 @@ def _lookup_field(cls, parts):
979979
if hasattr(getattr(field, 'field', None), 'lookup_member'):
980980
new_field = field.field.lookup_member(field_name)
981981
elif cls._dynamic and (isinstance(field, DynamicField) or
982-
getattr(getattr(field, 'document_type'), '_dynamic')):
982+
getattr(getattr(field, 'document_type'), '_dynamic')):
983983
new_field = DynamicField(db_field=field_name)
984984
else:
985985
# Look up subfield on the previous field or raise

mongoengine/base/fields.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __set__(self, instance, value):
112112
"""Descriptor for assigning a value to a field in a document.
113113
"""
114114

115-
# If setting to None and theres a default
115+
# If setting to None and there is a default
116116
# Then set the value to the default value
117117
if value is None:
118118
if self.null:
@@ -259,8 +259,8 @@ def __get__(self, instance, owner):
259259
instance._data[self.name] = value
260260

261261
if (self._auto_dereference and instance._initialised and
262-
isinstance(value, (BaseList, BaseDict))
263-
and not value._dereferenced):
262+
isinstance(value, (BaseList, BaseDict)) and
263+
not value._dereferenced):
264264
value = _dereference(
265265
value, max_depth=1, instance=instance, name=self.name
266266
)

mongoengine/base/metaclasses.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def __new__(cls, name, bases, attrs):
110110
for base in flattened_bases:
111111
if (not getattr(base, '_is_base_cls', True) and
112112
not getattr(base, '_meta', {}).get('abstract', True)):
113-
# Collate heirarchy for _cls and _subclasses
113+
# Collate hierarchy for _cls and _subclasses
114114
class_name.append(base.__name__)
115115

116116
if hasattr(base, '_meta'):
@@ -183,7 +183,7 @@ def __new__(cls, name, bases, attrs):
183183
"CachedReferenceFields is not allowed in EmbeddedDocuments")
184184
if not f.document_type:
185185
raise InvalidDocumentError(
186-
"Document is not avaiable to sync")
186+
"Document is not available to sync")
187187

188188
if f.auto_sync:
189189
f.start_listener()
@@ -245,7 +245,7 @@ def _import_classes(cls):
245245
EmbeddedDocument = _import_class('EmbeddedDocument')
246246
DictField = _import_class('DictField')
247247
CachedReferenceField = _import_class('CachedReferenceField')
248-
return (Document, EmbeddedDocument, DictField, CachedReferenceField)
248+
return Document, EmbeddedDocument, DictField, CachedReferenceField
249249

250250

251251
class TopLevelDocumentMetaclass(DocumentMetaclass):
@@ -301,8 +301,8 @@ def __new__(cls, name, bases, attrs):
301301

302302
# Prevent classes setting collection different to their parents
303303
# If parent wasn't an abstract class
304-
if (parent_doc_cls and 'collection' in attrs.get('_meta', {})
305-
and not parent_doc_cls._meta.get('abstract', True)):
304+
if (parent_doc_cls and 'collection' in attrs.get('_meta', {}) and
305+
not parent_doc_cls._meta.get('abstract', True)):
306306
msg = "Trying to set a collection on a subclass (%s)" % name
307307
warnings.warn(msg, SyntaxWarning)
308308
del attrs['_meta']['collection']
@@ -408,14 +408,15 @@ def __new__(cls, name, bases, attrs):
408408

409409
return new_class
410410

411-
def get_auto_id_names(self):
411+
@classmethod
412+
def get_auto_id_names(cls, new_class):
412413
id_name, id_db_name = ('id', '_id')
413-
if id_name not in self._fields and \
414-
id_db_name not in (v.db_field for v in self._fields.values()):
414+
if id_name not in new_class._fields and \
415+
id_db_name not in (v.db_field for v in new_class._fields.values()):
415416
return id_name, id_db_name
416417
id_basename, id_db_basename, i = 'auto_id', '_auto_id', 0
417-
while id_name in self._fields or \
418-
id_db_name in (v.db_field for v in self._fields.values()):
418+
while id_name in new_class._fields or \
419+
id_db_name in (v.db_field for v in new_class._fields.values()):
419420
id_name = '{0}_{1}'.format(id_basename, i)
420421
id_db_name = '{0}_{1}'.format(id_db_basename, i)
421422
i += 1

mongoengine/dereference.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _find_references(self, items, depth=0):
100100
if isinstance(item, (Document, EmbeddedDocument)):
101101
for field_name, field in item._fields.iteritems():
102102
v = item._data.get(field_name, None)
103-
if isinstance(v, (DBRef)):
103+
if isinstance(v, DBRef):
104104
reference_map.setdefault(field.document_type, set()).add(v.id)
105105
elif isinstance(v, (dict, SON)) and '_ref' in v:
106106
reference_map.setdefault(get_document(v['_cls']), set()).add(v['_ref'].id)
@@ -111,7 +111,7 @@ def _find_references(self, items, depth=0):
111111
if isinstance(field_cls, (Document, TopLevelDocumentMetaclass)):
112112
key = field_cls
113113
reference_map.setdefault(key, set()).update(refs)
114-
elif isinstance(item, (DBRef)):
114+
elif isinstance(item, DBRef):
115115
reference_map.setdefault(item.collection, set()).add(item.id)
116116
elif isinstance(item, (dict, SON)) and '_ref' in item:
117117
reference_map.setdefault(get_document(item['_cls']), set()).add(item['_ref'].id)
@@ -219,12 +219,12 @@ def _attach_objects(self, items, depth=0, instance=None, name=None):
219219
elif isinstance(v, (Document, EmbeddedDocument)):
220220
for field_name, field in v._fields.iteritems():
221221
v = data[k]._data.get(field_name, None)
222-
if isinstance(v, (DBRef)):
222+
if isinstance(v, DBRef):
223223
data[k]._data[field_name] = self.object_map.get(
224224
(v.collection, v.id), v)
225225
elif isinstance(v, (dict, SON)) and '_ref' in v:
226226
data[k]._data[field_name] = self.object_map.get(
227-
(v['_ref'].collection , v['_ref'].id), v)
227+
(v['_ref'].collection, v['_ref'].id), v)
228228
elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth:
229229
item_name = "{0}.{1}.{2}".format(name, k, field_name)
230230
data[k]._data[field_name] = self._attach_objects(v, depth, instance=instance, name=item_name)

mongoengine/document.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import re
44

55
from pymongo.read_preferences import ReadPreference
6-
from bson import ObjectId
76
from bson.dbref import DBRef
87
from mongoengine import signals
98
from mongoengine.common import _import_class
@@ -61,7 +60,7 @@ class EmbeddedDocument(BaseDocument):
6160
dictionary.
6261
"""
6362

64-
__slots__ = ('_instance')
63+
__slots__ = ('_instance', )
6564

6665
# The __metaclass__ attribute is removed by 2to3 when running with Python3
6766
# my_metaclass is defined so that metaclass can be queried in Python 2 & 3

mongoengine/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _format_errors(self):
126126
def generate_key(value, prefix=''):
127127
if isinstance(value, list):
128128
value = ' '.join([generate_key(k) for k in value])
129-
if isinstance(value, dict):
129+
elif isinstance(value, dict):
130130
value = ' '.join(
131131
[generate_key(v, k) for k, v in value.iteritems()])
132132

mongoengine/fields.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ def prepare_query_value(self, op, value):
667667
return StringField().prepare_query_value(op, value)
668668
return super(DynamicField, self).prepare_query_value(op, self.to_mongo(value))
669669

670-
671670
def validate(self, value, clean=True):
672671
if hasattr(value, "validate"):
673672
value.validate(clean=clean)
@@ -698,9 +697,10 @@ def validate(self, value):
698697

699698
def prepare_query_value(self, op, value):
700699
if self.field:
701-
if op in ('set', 'unset') and (not isinstance(value, basestring)
702-
and not isinstance(value, BaseDocument)
703-
and hasattr(value, '__iter__')):
700+
if op in ('set', 'unset') and (
701+
not isinstance(value, basestring) and
702+
not isinstance(value, BaseDocument) and
703+
hasattr(value, '__iter__')):
704704
return [self.field.prepare_query_value(op, v) for v in value]
705705
return self.field.prepare_query_value(op, value)
706706
return super(ListField, self).prepare_query_value(op, value)
@@ -718,12 +718,10 @@ class EmbeddedDocumentListField(ListField):
718718
719719
"""
720720

721-
def __init__(self, document_type, *args, **kwargs):
721+
def __init__(self, document_type, **kwargs):
722722
"""
723723
:param document_type: The type of
724724
:class:`~mongoengine.EmbeddedDocument` the list will hold.
725-
:param args: Arguments passed directly into the parent
726-
:class:`~mongoengine.ListField`.
727725
:param kwargs: Keyword arguments passed directly into the parent
728726
:class:`~mongoengine.ListField`.
729727
"""
@@ -975,7 +973,6 @@ def prepare_query_value(self, op, value):
975973
super(ReferenceField, self).prepare_query_value(op, value)
976974
return self.to_mongo(value)
977975

978-
979976
def validate(self, value):
980977

981978
if not isinstance(value, (self.document_type, DBRef)):
@@ -1100,7 +1097,7 @@ def prepare_query_value(self, op, value):
11001097

11011098
def validate(self, value):
11021099

1103-
if not isinstance(value, (self.document_type)):
1100+
if not isinstance(value, self.document_type):
11041101
self.error("A CachedReferenceField only accepts documents")
11051102

11061103
if isinstance(value, Document) and value.id is None:
@@ -1419,7 +1416,7 @@ def __get__(self, instance, owner):
14191416
def __set__(self, instance, value):
14201417
key = self.name
14211418
if ((hasattr(value, 'read') and not
1422-
isinstance(value, GridFSProxy)) or isinstance(value, str_types)):
1419+
isinstance(value, GridFSProxy)) or isinstance(value, str_types)):
14231420
# using "FileField() = file/string" notation
14241421
grid_file = instance._data.get(self.name)
14251422
# If a file already exists, delete it
@@ -1553,7 +1550,7 @@ def delete(self, *args, **kwargs):
15531550
if out and out.thumbnail_id:
15541551
self.fs.delete(out.thumbnail_id)
15551552

1556-
return super(ImageGridFsProxy, self).delete(*args, **kwargs)
1553+
return super(ImageGridFsProxy, self).delete()
15571554

15581555
def _put_thumbnail(self, thumbnail, format, progressive, **kwargs):
15591556
w, h = thumbnail.size

0 commit comments

Comments
 (0)