mirror of
https://github.com/Hopiu/django-markdownx.git
synced 2026-05-28 05:53:59 +00:00
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
|
|
from django.utils.translation import ugettext_lazy as _
|
||
|
|
from django.forms import ValidationError
|
||
|
|
|
||
|
|
|
||
|
|
class MarkdownxImageUploadError(ValidationError):
|
||
|
|
"""
|
||
|
|
|
||
|
|
"""
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def not_uploaded():
|
||
|
|
"""
|
||
|
|
No file is available to upload.
|
||
|
|
|
||
|
|
:return:
|
||
|
|
:rtype:
|
||
|
|
"""
|
||
|
|
return MarkdownxImageUploadError(_('No files have been uploaded.'))
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def unsupported_format():
|
||
|
|
"""
|
||
|
|
The file is of a format not defined in `settings.py`
|
||
|
|
or if default, in `markdownx/settings.py`.
|
||
|
|
|
||
|
|
:return:
|
||
|
|
:rtype:
|
||
|
|
"""
|
||
|
|
return MarkdownxImageUploadError(_('File type is not supported.'))
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def invalid_size(current, expected):
|
||
|
|
"""
|
||
|
|
The file is larger in size that the maximum allow in `settings.py` (or the default).
|
||
|
|
|
||
|
|
:param current:
|
||
|
|
:type current:
|
||
|
|
:param expected:
|
||
|
|
:type expected:
|
||
|
|
:return:
|
||
|
|
:rtype:
|
||
|
|
"""
|
||
|
|
from django.template.defaultfilters import filesizeformat
|
||
|
|
|
||
|
|
return MarkdownxImageUploadError(
|
||
|
|
_('Please keep file size under {max}. Current file size {current}').format(
|
||
|
|
max=filesizeformat(expected),
|
||
|
|
current=filesizeformat(current)
|
||
|
|
)
|
||
|
|
)
|