コード例 #1
0
def validate_max_file_size(max_filesize_bytes, fieldfile):
    if fieldfile.size > max_filesize_bytes:
        raise ValidationError(
            _('Can not upload files larger than %(max_filesize)s.') % {
                'max_filesize':
                crhumanize.human_readable_filesize(max_filesize_bytes),
            },
            code='max_filesize_bytes_exceeded')
コード例 #2
0
 def test_less_than_kb(self):
     self.assertEqual('0B', crhumanize.human_readable_filesize(0))
     self.assertEqual('999B', crhumanize.human_readable_filesize(999))
コード例 #3
0
 def test_mb(self):
     self.assertEqual('1.0MB', crhumanize.human_readable_filesize(1000000))
     self.assertEqual('55.6MB', crhumanize.human_readable_filesize(55555555))
コード例 #4
0
 def test_tb(self):
     self.assertEqual('1.00TB', crhumanize.human_readable_filesize(1000000000000))
     self.assertEqual('55.56TB', crhumanize.human_readable_filesize(55555555555555))
コード例 #5
0
 def test_kb(self):
     self.assertEqual('1KB', crhumanize.human_readable_filesize(1000))
     self.assertEqual('999KB', crhumanize.human_readable_filesize(999999))