Esempio n. 1
0
 def test_custom_filename_field(self):
     obj = StorageModel.objects.create()
     obj.custom_name_file_field = "flap"
     obj.save()
     path = storage.path(model_instance_field_path(obj, "custom"))
     self.assertEqual(op.exists(path), True)
     self.assertEqual(open(path).read(), "flap")
Esempio n. 2
0
 def write_data(sender, instance, created, raw, using, **kwargs):
     if (name not in instance.__dict__ or
             instance.__dict__[name] is None):
         # Nothing to save
         return
     # Open the file for writing and acquire a lock on it if
     # possible
     path = model_instance_field_path(instance, filename)
     fs_storage = isinstance(self.storage, FileSystemStorage)
     if fs_storage:
         full_path = self.storage.path(path)
         directory = op.dirname(full_path)
         if not op.exists(directory):
             try:
                 os.makedirs(directory)
             except OSError, err:
                 # Another thread may have created the directory since
                 # the check
                 if err.errno == 17:
                     pass
Esempio n. 3
0
 def path(self, obj):
     if obj.pk is None:
         raise AttributeError("you must save the object to the database "
                 "before accessing this field")
     return model_instance_field_path(obj, self.filename)