當前位置: 首頁>>代碼示例>>Python>>正文


Python defaultfilters.filesizeformat方法代碼示例

本文整理匯總了Python中django.template.defaultfilters.filesizeformat方法的典型用法代碼示例。如果您正苦於以下問題:Python defaultfilters.filesizeformat方法的具體用法?Python defaultfilters.filesizeformat怎麽用?Python defaultfilters.filesizeformat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.template.defaultfilters的用法示例。


在下文中一共展示了defaultfilters.filesizeformat方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: clean

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def clean(self, *args, **kwargs):
        data = super(PrivateFileField, self).clean(*args, **kwargs)
        file = data.file
        if isinstance(file, UploadedFile):
            # content_type is only available for uploaded files,
            # and not for files which are already stored in the model.
            content_type = file.content_type

            if self.content_types and content_type not in self.content_types:
                logger.debug('Rejected uploaded file type: %s', content_type)
                raise ValidationError(self.error_messages['invalid_file_type'])

            if self.max_file_size and file.size > self.max_file_size:
                raise ValidationError(self.error_messages['file_too_large'].format(
                    max_size=filesizeformat(self.max_file_size),
                    size=filesizeformat(file.size)
                ))

        return data 
開發者ID:edoburu,項目名稱:django-private-storage,代碼行數:21,代碼來源:fields.py

示例2: test_add_too_large_file

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def test_add_too_large_file(self):
        file_content = get_test_image_file().file.getvalue()

        response = self.post({
            'title': "Test image",
            'file': SimpleUploadedFile('test.png', file_content),
        })

        # Shouldn't redirect anywhere
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'wagtailimages/images/add.html')

        # The form should have an error
        self.assertFormError(
            response, 'form', 'file',
            "This file is too big ({file_size}). Maximum filesize {max_file_size}.".format(
                file_size=filesizeformat(len(file_content)),
                max_file_size=filesizeformat(1),
            )
        ) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:22,代碼來源:test_admin_views.py

示例3: test_localized_formats

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def test_localized_formats(self):
        with self.settings(USE_L10N=True), translation.override('de'):
            self.assertEqual(filesizeformat(1023), '1023\xa0Bytes')
            self.assertEqual(filesizeformat(1024), '1,0\xa0KB')
            self.assertEqual(filesizeformat(10 * 1024), '10,0\xa0KB')
            self.assertEqual(filesizeformat(1024 * 1024 - 1), '1024,0\xa0KB')
            self.assertEqual(filesizeformat(1024 * 1024), '1,0\xa0MB')
            self.assertEqual(filesizeformat(1024 * 1024 * 50), '50,0\xa0MB')
            self.assertEqual(filesizeformat(1024 * 1024 * 1024 - 1), '1024,0\xa0MB')
            self.assertEqual(filesizeformat(1024 * 1024 * 1024), '1,0\xa0GB')
            self.assertEqual(filesizeformat(1024 * 1024 * 1024 * 1024), '1,0\xa0TB')
            self.assertEqual(filesizeformat(1024 * 1024 * 1024 * 1024 * 1024), '1,0\xa0PB')
            self.assertEqual(filesizeformat(1024 * 1024 * 1024 * 1024 * 1024 * 2000), '2000,0\xa0PB')
            self.assertEqual(filesizeformat(complex(1, -1)), '0\xa0Bytes')
            self.assertEqual(filesizeformat(""), '0\xa0Bytes')
            self.assertEqual(filesizeformat("\N{GREEK SMALL LETTER ALPHA}"), '0\xa0Bytes') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_filesizeformat.py

示例4: check

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def check(request):
    return {
            'hostname': socket.gethostname(),
            'ips': ips,
            'cpus': psutil.cpu_count(),
            'uptime': timesince(datetime.fromtimestamp(psutil.boot_time())),
            'memory': {
                'total': filesizeformat(psutil.virtual_memory().total),
                'available': filesizeformat(psutil.virtual_memory().available),
                'used': filesizeformat(psutil.virtual_memory().used),
                'free': filesizeformat(psutil.virtual_memory().free),
                'percent': psutil.virtual_memory().percent
            },
            'swap': {
                'total': filesizeformat(psutil.swap_memory().total),
                'used': filesizeformat(psutil.swap_memory().used),
                'free': filesizeformat(psutil.swap_memory().free),
                'percent': psutil.swap_memory().percent
            }
        } 
開發者ID:pbs,項目名稱:django-heartbeat,代碼行數:22,代碼來源:host.py

示例5: test_add_too_large_file

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def test_add_too_large_file(self):
        video_file = create_test_video_file()

        response = self.post({
            'title': "Test video",
            'file': SimpleUploadedFile('small.mp4', video_file.read(), "video/mp4"),
        })

        # Shouldn't redirect anywhere
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'wagtailvideos/videos/add.html')

        # The form should have an error
        self.assertFormError(
            response, 'form', 'file',
            "This file is too big ({file_size}). Maximum filesize {max_file_size}.".format(
                file_size=filesizeformat(video_file.size),
                max_file_size=filesizeformat(1),
            )
        ) 
開發者ID:neon-jungle,項目名稱:wagtailvideos,代碼行數:22,代碼來源:test_admin_views.py

示例6: upload_size_error

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def upload_size_error(request, max_size, image=None):
    subscriptions_url = reverse('subscription_list')
    open_link = "<a href=\"%s\">" % subscriptions_url
    close_link = "</a>"
    msg = "Sorry, but this image is too large. Under your current subscription plan, the maximum allowed image size is %(max_size)s. %(open_link)sWould you like to upgrade?%(close_link)s"

    messages.error(request, _(msg) % {
        "max_size": filesizeformat(max_size),
        "open_link": open_link,
        "close_link": close_link
    })

    if image is not None:
        return HttpResponseRedirect(image.get_absolute_url())

    return HttpResponseRedirect('/upload/') 
開發者ID:astrobin,項目名稱:astrobin,代碼行數:18,代碼來源:__init__.py

示例7: clean

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def clean(self, *args, **kwargs):
        uploaded_file = super(FormBuilderFileField, self).clean(*args, **kwargs)
        if not uploaded_file:
            if self.required:
                raise forms.ValidationError(_('This field is required.'))
            return uploaded_file

        if not os.path.splitext(uploaded_file.name)[1].lstrip('.').lower() in \
                self.allowed_file_types:
            raise forms.ValidationError(
                _('Sorry, this filetype is not allowed. '
                  'Allowed filetype: %s') % ', '.join(self.allowed_file_types))

        if uploaded_file._size > self.max_upload_size:
            params = {
                'max_size': filesizeformat(self.max_upload_size),
                'size': filesizeformat(uploaded_file._size)
            }
            msg = _(
                'Please keep file size under %(max_size)s. Current size is %(size)s.') % params
            raise forms.ValidationError(msg)

        return uploaded_file 
開發者ID:mishbahr,項目名稱:djangocms-forms,代碼行數:25,代碼來源:fields.py

示例8: clean_attachment

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def clean_attachment(self):
        max_filesize = 10 * 1024 * 1024  # 10MB
        from django.template.defaultfilters import filesizeformat
        f = self.cleaned_data.get('attachment')
        if f and f.size > max_filesize:
            size = filesizeformat(max_filesize)
            error = _('Attachment should be no larger than %s') % size
            raise forms.ValidationError(error)

        return f 
開發者ID:fpsw,項目名稱:Servo,代碼行數:12,代碼來源:repairs.py

示例9: clean_photo

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def clean_photo(self):
        MAX_FILESIZE = 1*1024*1024 # 1 MB
        from django.template.defaultfilters import filesizeformat
        photo = self.cleaned_data.get('photo')
        if photo and photo.size > MAX_FILESIZE:
            size = filesizeformat(MAX_FILESIZE)
            error = _('Profile picture should be no larger than %s') % size
            raise forms.ValidationError(error)

        return photo 
開發者ID:fpsw,項目名稱:Servo,代碼行數:12,代碼來源:account.py

示例10: filesize

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def filesize(self):
        try:
            return filesizeformat(int(self.size))
        except ValueError:
            return self.size 
開發者ID:ideascube,項目名稱:ideascube,代碼行數:7,代碼來源:catalog.py

示例11: clean

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def clean(self, data, initial=None):
        file = super(RestrictedFileField, self).clean(data, initial)

        try:
            content_type = file.content_type
            if content_type in self.content_types:
                if file._size > self.max_upload_size:
                    raise ValidationError(_('Please keep filesize under %s. Current filesize %s') % (
                        filesizeformat(self.max_upload_size), filesizeformat(file._size)))
            else:
                raise ValidationError(_('Filetype not supported.'))
        except AttributeError:
            pass

        return data 
開發者ID:liyao001,項目名稱:BioQueue,代碼行數:17,代碼來源:forms.py

示例12: clean_upl

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def clean_upl(self):
        content = self.cleaned_data['upl']
        logger.info(content.content_type)
        if content.size > DEPOSIT_MAX_FILE_SIZE:
            raise forms.ValidationError(_('File too large (%(size)s). Maximum size is %(maxsize)s.') %
                                        {'size': filesizeformat(content._size),
                                         'maxsize': filesizeformat(DEPOSIT_MAX_FILE_SIZE)},
                                        code='too_large')
        return content 
開發者ID:dissemin,項目名稱:dissemin,代碼行數:11,代碼來源:forms.py

示例13: validate_size

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def validate_size(content):
    """Validates if the size of the content in not too big."""
    if content.file.size > validate_size.MAX_UPLOAD_SIZE:
        message = format_lazy(
            _("Please keep filesize under {limit}. Current filesize {current}"),
            limit=filesizeformat(validate_size.MAX_UPLOAD_SIZE),
            current=filesizeformat(content.file.size))
        raise ValidationError(message, code='file-size') 
開發者ID:tejoesperanto,項目名稱:pasportaservo,代碼行數:10,代碼來源:validators.py

示例14: file_size

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def file_size(file, article):
    try:
        return filesizeformat(file.get_file_size(article))
    except BaseException:
        return 0 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:7,代碼來源:files.py

示例15: check_image_file_size

# 需要導入模塊: from django.template import defaultfilters [as 別名]
# 或者: from django.template.defaultfilters import filesizeformat [as 別名]
def check_image_file_size(self, f):
        # Upload size checking can be disabled by setting max upload size to None
        if self.max_upload_size is None:
            return

        # Check the filesize
        if f.size > self.max_upload_size:
            raise ValidationError(self.error_messages['file_too_large'] % (
                filesizeformat(f.size),
            ), code='file_too_large') 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:12,代碼來源:fields.py


注:本文中的django.template.defaultfilters.filesizeformat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。