@@ -275,6 +275,30 @@ def to_python(self, value, **kwargs):
275
275
raise self .exception ("Array {0} cannot be converted to int" .format (value ))
276
276
277
277
278
+ # FieldFile also needs a model instance to save changes.
279
+ class FakeInstance (object ):
280
+ """
281
+ FieldFile needs a model instance to update when file is persisted
282
+ or deleted
283
+ """
284
+
285
+ def save (self ):
286
+ return
287
+
288
+ class FakeField (object ):
289
+ """
290
+ FieldFile needs a field object to generate a filename, persist
291
+ and delete files, so we are effectively mocking that.
292
+ """
293
+
294
+ name = "noop"
295
+ attname = "noop"
296
+ max_length = 10000
297
+
298
+ def generate_filename (field , instance , name ):
299
+ return os .path .join (self .preference .get_upload_path (), f .name )
300
+
301
+
278
302
class PreferenceFieldFile (FieldFile ):
279
303
"""
280
304
In order to have the same API that we have with models.FileField,
@@ -285,32 +309,7 @@ class PreferenceFieldFile(FieldFile):
285
309
286
310
def __init__ (self , preference , storage , name ):
287
311
super (FieldFile , self ).__init__ (None , name )
288
-
289
- # FieldFile also needs a model instance to save changes.
290
- class FakeInstance (object ):
291
- """
292
- FieldFile needs a model instance to update when file is persisted
293
- or deleted
294
- """
295
-
296
- def save (self ):
297
- return
298
-
299
312
self .instance = FakeInstance ()
300
-
301
- class FakeField (object ):
302
- """
303
- FieldFile needs a field object to generate a filename, persist
304
- and delete files, so we are effectively mocking that.
305
- """
306
-
307
- name = "noop"
308
- attname = "noop"
309
- max_length = 10000
310
-
311
- def generate_filename (field , instance , name ):
312
- return os .path .join (self .preference .get_upload_path (), f .name )
313
-
314
313
self .field = FakeField ()
315
314
self .storage = storage
316
315
self ._committed = True
0 commit comments