FileField's values are now optional. When no value is applied, no File object is created and referenced.
This commit is contained in:
parent
03c0fd9ada
commit
aa00feb6a5
@ -339,8 +339,8 @@ class BaseDocument(object):
|
|||||||
try:
|
try:
|
||||||
field._validate(value)
|
field._validate(value)
|
||||||
except (ValueError, AttributeError, AssertionError), e:
|
except (ValueError, AttributeError, AssertionError), e:
|
||||||
raise ValidationError('Invalid value for field of type "' +
|
raise ValidationError('Invalid value for field of type "%s": %s'
|
||||||
field.__class__.__name__ + '"')
|
% (field.__class__.__name__, value))
|
||||||
elif field.required:
|
elif field.required:
|
||||||
raise ValidationError('Field "%s" is required' % field.name)
|
raise ValidationError('Field "%s" is required' % field.name)
|
||||||
|
|
||||||
|
@ -591,15 +591,20 @@ class FileField(BaseField):
|
|||||||
|
|
||||||
def to_mongo(self, value):
|
def to_mongo(self, value):
|
||||||
# Store the GridFS file id in MongoDB
|
# Store the GridFS file id in MongoDB
|
||||||
return self.gridfs.grid_id
|
if self.gridfs.grid_id is not None:
|
||||||
|
return self.gridfs.grid_id
|
||||||
|
return None
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
# Use stored value (id) to lookup file in GridFS
|
# Use stored value (id) to lookup file in GridFS
|
||||||
return self.gridfs.get(id=value)
|
if self.gridfs.grid_id is not None:
|
||||||
|
return self.gridfs.get(id=value)
|
||||||
|
return None
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
assert isinstance(value, GridFSProxy)
|
if value.grid_id is not None:
|
||||||
assert isinstance(value.grid_id, pymongo.objectid.ObjectId)
|
assert isinstance(value, GridFSProxy)
|
||||||
|
assert isinstance(value.grid_id, pymongo.objectid.ObjectId)
|
||||||
|
|
||||||
class GeoPointField(BaseField):
|
class GeoPointField(BaseField):
|
||||||
"""A list storing a latitude and longitude.
|
"""A list storing a latitude and longitude.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user