def __call__(self, data):
if self.max_size is not None and data.size > self.max_size:
params = {
'max_size': filesizeformat(self.max_size),
'size': filesizeformat(data.size),
}
raise ValidationError(self.error_messages['max_size'], 'max_size', params)
if self.min_size is not None and data.size < self.min_size:
params = {
'min_size': filesizeformat(self.mix_size),
'size': filesizeformat(data.size)
}
raise ValidationError(self.error_messages['min_size'], 'min_size', params)
if self.content_types is not None and len(self.content_types):
content_type = magic.from_buffer(data.read(), mime=True)
data.seek(0) # seek to start for future mime checks by django
if content_type not in self.content_types:
params = {
'content_type': content_type
}
raise ValidationError(self.error_messages['content_type'], 'content_type', params)
评论列表
文章目录