Esempio n. 1
0
 def test_directory_parititioning(self):
     """Test that files are partitioned into upload directories."""
     test = lambda r, exp, s: [exp == utils.get_partition_id(i, s)
                               for i in range(*r)]
     all_true = lambda l: filter(lambda x: not x, l)
     self.assertEmpty(all_true(test((1, 10), 1, 10)))
     self.assertEmpty(all_true(test((11, 20), 2, 10)))
     self.assertEmpty(all_true(test((1001, 2000), 2, 1000)))
Esempio n. 2
0
def determine_upload_path(instance, filename):
    chunk_size = 1000  # max files per directory
    path = getattr(settings, 'USER_AVATAR_PATH', 'images/profiles/')
    path = path.lstrip('/').rstrip('/')
    return "%(path)s/%(partition)d/%(filename)s" % {
        'path': path,
        'partition': get_partition_id(instance.pk, chunk_size),
        'filename': safe_filename(filename)
    }
Esempio n. 3
0
def determine_upload_path(instance, filename):
    chunk_size = 1000  # max files per directory
    path = getattr(settings, "USER_AVATAR_PATH", "images/profiles/")
    path = path.lstrip("/").rstrip("/")
    return "%(path)s/%(partition)d/%(filename)s" % {
        "path": path,
        "partition": get_partition_id(instance.pk, chunk_size),
        "filename": safe_filename(filename),
    }
Esempio n. 4
0
def determine_upload_path(instance, filename):
    chunk_size = 1000  # max files per directory
    path = getattr(settings, 'USER_AVATAR_PATH', 'images/profiles/')
    path = path.lstrip('/').rstrip('/')
    return "%(path)s/%(partition)d/%(filename)s" % {
        'path': path,
        'partition': get_partition_id(instance.pk, chunk_size),
        'filename': safe_filename(filename)
    }
Esempio n. 5
0
 def test_directory_parititioning(self):
     """Test that files are partitioned into upload directories."""
     test = lambda r, exp, s: [
         exp == utils.get_partition_id(i, s) for i in range(*r)
     ]
     all_true = lambda l: filter(lambda x: not x, l)
     self.assertEmpty(all_true(test((1, 10), 1, 10)))
     self.assertEmpty(all_true(test((11, 20), 2, 10)))
     self.assertEmpty(all_true(test((1001, 2000), 2, 1000)))