class ThumbnailModel(models.Model): """creates a thumbnail resized to maximum size to fit a 100x75 area""" image = StdImageField( upload_to=UploadTo(name='image', path='img'), blank=True, variations={'thumbnail': (100, 75)} )
class ForceMinSizeModel(models.Model): """creates a thumbnail resized to maximum size to fit a 100x75 area""" image = StdImageField( upload_to=UploadTo(name='image', path='img'), force_min_size=True, variations={'thumbnail': (600, 600)} )
class MyStorageModel(CustomManagerModel): """delays creation of 150x150 thumbnails until it is called manually""" image = StdImageField( upload_to=UploadTo(name='image', path='img'), variations={'thumbnail': (150, 150, True)}, storage=FileSystemStorage(), )
class CustomRenderVariationsModel(models.Model): """Use custom render_variations.""" image = StdImageField( upload_to=UploadTo(name='image', path='img'), variations={'thumbnail': (150, 150)}, render_variations=custom_render_variations, )
class ResizeModel(models.Model): """resizes image to maximum size to fit a 640x480 area""" image = StdImageField( upload_to=UploadTo(name='image', path='img'), variations={ 'medium': {'width': 400, 'height': 400}, 'thumbnail': (100, 75), } )
class UtilVariationsModel(models.Model): """delays creation of 150x150 thumbnails until it is called manually""" image = StdImageField(upload_to=UploadTo(name='image', path='img'), variations={'thumbnail': (150, 150, True)}, render_variations=render_job)
class MinSizeModel(models.Model): image = StdImageField(upload_to=UploadTo(name='image', path='img'), validators=[MinSizeValidator(200, 200)])
class MaxSizeModel(models.Model): image = StdImageField(upload_to=UploadTo(name='image', path='img'), validators=[MaxSizeValidator(16, 16)])
class ResizeCropModel(models.Model): """resizes image to 640x480 cropping if necessary""" image = StdImageField(upload_to=UploadTo(name='image', path='img'), variations={'thumbnail': (150, 150, True)})
class AdminDeleteModel(models.Model): """can be deleted through admin""" image = StdImageField(upload_to=UploadTo(name='image', path='img'), blank=True)
def test_file_name_kwargs(self): file_name = UploadTo(path='/foo', name='bar', ext='.BAZ')(object(), '/path/to/file') assert file_name == '/foo/bar.baz'
def test_file_name_no_ext(self): file_name = UploadTo()(object(), '/path/to/file') assert file_name == '/path/to/file'
def test_file_name_lower(self): file_name = UploadTo()(object(), '/path/To/File.JPEG') assert file_name == '/path/to/file.jpeg'
def test_file_name(self): file_name = UploadTo()(object(), '/path/to/file.jpeg') assert file_name == '/path/to/file.jpeg'