@@ -325,7 +325,7 @@ def to_python(self, value):
325
325
return value
326
326
return value .quantize (decimal .Decimal (".%s" % ("0" * self .precision )), rounding = self .rounding )
327
327
328
- def to_mongo (self , value , use_db_field = True ):
328
+ def to_mongo (self , value , ** kwargs ):
329
329
if value is None :
330
330
return value
331
331
if self .force_string :
@@ -388,7 +388,7 @@ def validate(self, value):
388
388
if not isinstance (new_value , (datetime .datetime , datetime .date )):
389
389
self .error (u'cannot parse date "%s"' % value )
390
390
391
- def to_mongo (self , value ):
391
+ def to_mongo (self , value , ** kwargs ):
392
392
if value is None :
393
393
return value
394
394
if isinstance (value , datetime .datetime ):
@@ -511,7 +511,7 @@ def to_python(self, value):
511
511
except :
512
512
return original_value
513
513
514
- def to_mongo (self , value ):
514
+ def to_mongo (self , value , ** kwargs ):
515
515
value = self .to_python (value )
516
516
return self ._convert_from_datetime (value )
517
517
@@ -546,11 +546,10 @@ def to_python(self, value):
546
546
return self .document_type ._from_son (value , _auto_dereference = self ._auto_dereference )
547
547
return value
548
548
549
- def to_mongo (self , value , use_db_field = True , fields = [] ):
549
+ def to_mongo (self , value , ** kwargs ):
550
550
if not isinstance (value , self .document_type ):
551
551
return value
552
- return self .document_type .to_mongo (value , use_db_field ,
553
- fields = fields )
552
+ return self .document_type .to_mongo (value , ** kwargs )
554
553
555
554
def validate (self , value , clean = True ):
556
555
"""Make sure that the document instance is an instance of the
@@ -600,11 +599,11 @@ def validate(self, value, clean=True):
600
599
601
600
value .validate (clean = clean )
602
601
603
- def to_mongo (self , document , use_db_field = True ):
602
+ def to_mongo (self , document , ** kwargs ):
604
603
if document is None :
605
604
return None
606
605
607
- data = document .to_mongo (use_db_field )
606
+ data = document .to_mongo (** kwargs )
608
607
if '_cls' not in data :
609
608
data ['_cls' ] = document ._class_name
610
609
return data
@@ -616,7 +615,7 @@ class DynamicField(BaseField):
616
615
617
616
Used by :class:`~mongoengine.DynamicDocument` to handle dynamic data"""
618
617
619
- def to_mongo (self , value ):
618
+ def to_mongo (self , value , ** kwargs ):
620
619
"""Convert a Python type to a MongoDB compatible type.
621
620
"""
622
621
@@ -625,7 +624,7 @@ def to_mongo(self, value):
625
624
626
625
if hasattr (value , 'to_mongo' ):
627
626
cls = value .__class__
628
- val = value .to_mongo ()
627
+ val = value .to_mongo (** kwargs )
629
628
# If we its a document thats not inherited add _cls
630
629
if isinstance (value , Document ):
631
630
val = {"_ref" : value .to_dbref (), "_cls" : cls .__name__ }
@@ -643,7 +642,7 @@ def to_mongo(self, value):
643
642
644
643
data = {}
645
644
for k , v in value .iteritems ():
646
- data [k ] = self .to_mongo (v )
645
+ data [k ] = self .to_mongo (v , ** kwargs )
647
646
648
647
value = data
649
648
if is_list : # Convert back to a list
@@ -755,8 +754,8 @@ def __init__(self, field, **kwargs):
755
754
self ._order_reverse = kwargs .pop ('reverse' )
756
755
super (SortedListField , self ).__init__ (field , ** kwargs )
757
756
758
- def to_mongo (self , value ):
759
- value = super (SortedListField , self ).to_mongo (value )
757
+ def to_mongo (self , value , ** kwargs ):
758
+ value = super (SortedListField , self ).to_mongo (value , ** kwargs )
760
759
if self ._ordering is not None :
761
760
return sorted (value , key = itemgetter (self ._ordering ),
762
761
reverse = self ._order_reverse )
@@ -942,7 +941,7 @@ def __get__(self, instance, owner):
942
941
943
942
return super (ReferenceField , self ).__get__ (instance , owner )
944
943
945
- def to_mongo (self , document ):
944
+ def to_mongo (self , document , ** kwargs ):
946
945
if isinstance (document , DBRef ):
947
946
if not self .dbref :
948
947
return document .id
@@ -965,7 +964,7 @@ def to_mongo(self, document):
965
964
id_field_name = cls ._meta ['id_field' ]
966
965
id_field = cls ._fields [id_field_name ]
967
966
968
- id_ = id_field .to_mongo (id_ )
967
+ id_ = id_field .to_mongo (id_ , ** kwargs )
969
968
if self .document_type ._meta .get ('abstract' ):
970
969
collection = cls ._get_collection_name ()
971
970
return DBRef (collection , id_ , cls = cls ._class_name )
@@ -1088,7 +1087,7 @@ def __get__(self, instance, owner):
1088
1087
1089
1088
return super (CachedReferenceField , self ).__get__ (instance , owner )
1090
1089
1091
- def to_mongo (self , document ):
1090
+ def to_mongo (self , document , ** kwargs ):
1092
1091
id_field_name = self .document_type ._meta ['id_field' ]
1093
1092
id_field = self .document_type ._fields [id_field_name ]
1094
1093
@@ -1103,10 +1102,11 @@ def to_mongo(self, document):
1103
1102
# TODO: should raise here or will fail next statement
1104
1103
1105
1104
value = SON ((
1106
- ("_id" , id_field .to_mongo (id_ )),
1105
+ ("_id" , id_field .to_mongo (id_ , ** kwargs )),
1107
1106
))
1108
1107
1109
- value .update (dict (document .to_mongo (fields = self .fields )))
1108
+ kwargs ['fields' ] = self .fields
1109
+ value .update (dict (document .to_mongo (** kwargs )))
1110
1110
return value
1111
1111
1112
1112
def prepare_query_value (self , op , value ):
@@ -1222,7 +1222,7 @@ def dereference(self, value):
1222
1222
doc = doc_cls ._from_son (doc )
1223
1223
return doc
1224
1224
1225
- def to_mongo (self , document , use_db_field = True ):
1225
+ def to_mongo (self , document , ** kwargs ):
1226
1226
if document is None :
1227
1227
return None
1228
1228
@@ -1241,7 +1241,7 @@ def to_mongo(self, document, use_db_field=True):
1241
1241
else :
1242
1242
id_ = document
1243
1243
1244
- id_ = id_field .to_mongo (id_ )
1244
+ id_ = id_field .to_mongo (id_ , ** kwargs )
1245
1245
collection = document ._get_collection_name ()
1246
1246
ref = DBRef (collection , id_ )
1247
1247
return SON ((
@@ -1270,7 +1270,7 @@ def __set__(self, instance, value):
1270
1270
value = bin_type (value )
1271
1271
return super (BinaryField , self ).__set__ (instance , value )
1272
1272
1273
- def to_mongo (self , value ):
1273
+ def to_mongo (self , value , ** kwargs ):
1274
1274
return Binary (value )
1275
1275
1276
1276
def validate (self , value ):
@@ -1495,7 +1495,7 @@ def get_proxy_obj(self, key, instance, db_alias=None, collection_name=None):
1495
1495
db_alias = db_alias ,
1496
1496
collection_name = collection_name )
1497
1497
1498
- def to_mongo (self , value ):
1498
+ def to_mongo (self , value , ** kwargs ):
1499
1499
# Store the GridFS file id in MongoDB
1500
1500
if isinstance (value , self .proxy_class ) and value .grid_id is not None :
1501
1501
return value .grid_id
@@ -1845,7 +1845,7 @@ def to_python(self, value):
1845
1845
return original_value
1846
1846
return value
1847
1847
1848
- def to_mongo (self , value ):
1848
+ def to_mongo (self , value , ** kwargs ):
1849
1849
if not self ._binary :
1850
1850
return unicode (value )
1851
1851
elif isinstance (value , basestring ):
0 commit comments