Merge pull request #212 from zakj/dev
Added GridFSProxy.__nonzero__ - thanks to zakj for the fix
This commit is contained in:
		| @@ -723,6 +723,9 @@ class GridFSProxy(object): | |||||||
|     def __get__(self, instance, value): |     def __get__(self, instance, value): | ||||||
|         return self |         return self | ||||||
|  |  | ||||||
|  |     def __nonzero__(self): | ||||||
|  |         return bool(self.grid_id) | ||||||
|  |  | ||||||
|     def get(self, id=None): |     def get(self, id=None): | ||||||
|         if id: |         if id: | ||||||
|             self.grid_id = id |             self.grid_id = id | ||||||
| @@ -805,7 +808,7 @@ class FileField(BaseField): | |||||||
|         # Check if a file already exists for this model |         # Check if a file already exists for this model | ||||||
|         grid_file = instance._data.get(self.name) |         grid_file = instance._data.get(self.name) | ||||||
|         self.grid_file = grid_file |         self.grid_file = grid_file | ||||||
|         if self.grid_file: |         if isinstance(self.grid_file, GridFSProxy): | ||||||
|             if not self.grid_file.key: |             if not self.grid_file.key: | ||||||
|                 self.grid_file.key = self.name |                 self.grid_file.key = self.name | ||||||
|                 self.grid_file.instance = instance |                 self.grid_file.instance = instance | ||||||
|   | |||||||
| @@ -1300,6 +1300,21 @@ class FieldTest(unittest.TestCase): | |||||||
|  |  | ||||||
|         TestFile.drop_collection() |         TestFile.drop_collection() | ||||||
|  |  | ||||||
|  |     def test_file_boolean(self): | ||||||
|  |         """Ensure that a boolean test of a FileField indicates its presence | ||||||
|  |         """ | ||||||
|  |         class TestFile(Document): | ||||||
|  |             file = FileField() | ||||||
|  |  | ||||||
|  |         testfile = TestFile() | ||||||
|  |         self.assertFalse(bool(testfile.file)) | ||||||
|  |         testfile.file = 'Hello, World!' | ||||||
|  |         testfile.file.content_type = 'text/plain' | ||||||
|  |         testfile.save() | ||||||
|  |         self.assertTrue(bool(testfile.file)) | ||||||
|  |  | ||||||
|  |         TestFile.drop_collection() | ||||||
|  |  | ||||||
|     def test_geo_indexes(self): |     def test_geo_indexes(self): | ||||||
|         """Ensure that indexes are created automatically for GeoPointFields. |         """Ensure that indexes are created automatically for GeoPointFields. | ||||||
|         """ |         """ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user