unifying of messages and added to uploader

pull/676/head
Dave Cranwell 2014-10-08 15:35:35 +01:00 zatwierdzone przez Karl Hobley
rodzic 82657344de
commit 66c92f0333
4 zmienionych plików z 26 dodań i 23 usunięć

Wyświetl plik

@ -9,44 +9,43 @@ from django.template.defaultfilters import filesizeformat
from django.conf import settings
ALLOWED_EXTENSIONS = ['git', 'jpg', 'jpeg', 'png']
ALLOWED_EXTENSIONS = ['gif', 'jpg', 'jpeg', 'png']
ALLOWED_EXTENSIONS_TEXT = _("Supported formats: GIF, JPEG, PNG")
INVALID_IMAGE_ERROR = _(
"Not a supported image type. Please use a gif, jpeg or png file "
"with the correct file extension (*.gif, *.jpg or *.png)."
)
"Not a supported image format. %s"
) % ALLOWED_EXTENSIONS_TEXT
INVALID_IMAGE_KNOWN_FORMAT_ERROR = _(
"Not a valid %s image. Please use a gif, jpeg or png file "
"with the correct file extension (*.gif, *.jpg or *.png)."
"Not a valid %s image."
)
MAX_UPLOAD_SIZE = getattr(settings, 'WAGTAILIMAGES_MAX_UPLOAD_SIZE', 10 * 1024 * 1024)
if MAX_UPLOAD_SIZE is not None:
MAX_UPLOAD_SIZE_TEXT = filesizeformat(MAX_UPLOAD_SIZE)
MAX_UPLOAD_SIZE_TEXT = _("Maximum filesize: %s") % filesizeformat(MAX_UPLOAD_SIZE)
FILE_TOO_LARGE_ERROR = _(
"This file is too big (%%s). Image files must not exceed %s."
FILE_TOO_LARGE_ERROR = _("This file is too big. %s.") % (MAX_UPLOAD_SIZE_TEXT, )
FILE_TOO_LARGE_ERROR_SIZE_KNOWN = _(
"This file is too big (%%s). %s."
) % (MAX_UPLOAD_SIZE_TEXT, )
IMAGE_FIELD_HELP_TEXT = _(
"Supported formats: gif, jpeg, png. Max size: %s"
) % (MAX_UPLOAD_SIZE_TEXT, )
"%s. %s"
) % (ALLOWED_EXTENSIONS_TEXT, MAX_UPLOAD_SIZE_TEXT, )
else:
MAX_UPLOAD_SIZE_TEXT = ""
FILE_TOO_LARGE_ERROR = ""
IMAGE_FIELD_HELP_TEXT = _(
"Supported formats: gif, jpeg, png."
)
IMAGE_FIELD_HELP_TEXT = ALLOWED_EXTENSIONS_TEXT
class WagtailImageField(ImageField):
default_error_messages = {
'invalid_image': INVALID_IMAGE_ERROR,
'invalid_image_known_format': INVALID_IMAGE_KNOWN_FORMAT_ERROR,
'file_too_large': FILE_TOO_LARGE_ERROR,
'file_too_large': FILE_TOO_LARGE_ERROR_SIZE_KNOWN,
}
def __init__(self, *args, **kwargs):
@ -73,7 +72,8 @@ class WagtailImageField(ImageField):
image = Image.open(f)
except IOError:
# Uploaded file is not even an image file (or corrupted)
raise ValidationError(self.error_messages['invalid_image'], code='invalid_image')
raise ValidationError(self.error_messages['invalid_image_known_format'],
code='invalid_image_known_format')
f.seek(file_position)
else:

Wyświetl plik

@ -21,8 +21,8 @@ $(function(){
previewMinHeight:150,
previewMaxHeight:150,
messages: {
acceptFileTypes: window.fileupload_opts.messages.accepted_file_types,
maxFileSize: window.fileupload_opts.messages.max_file_size
acceptFileTypes: window.fileupload_opts.errormessages.accepted_file_types,
maxFileSize: window.fileupload_opts.errormessages.max_file_size
},
add: function (e, data) {
var $this = $(this);

Wyświetl plik

@ -16,6 +16,7 @@
<div class="nice-padding">
<div class="drop-zone">
<p>{% trans "Drag and drop images into this area to upload immediately." %}</p>
<p>{{ help_text }}
<form action="{% url 'wagtailimages_add_multiple' %}" method="POST" enctype="multipart/form-data">
<div class="replace-file-input">
@ -72,11 +73,11 @@
<script>
window.fileupload_opts = {
simple_upload_url: "{% url 'wagtailimages_add_image' %}",
accepted_file_types: /(\.|\/)(gif|jpe?g|png)$/i, //must be regex
accepted_file_types: /(\.|\/)({% for extn in allowed_extensions %}{{ extn }}{% if not forloop.last %}|{% endif %}{% endfor %})$/i, //must be regex
max_file_size: {{ max_filesize }}, //numeric format
messages: {
max_file_size: "max filesize message",
accepted_file_types: "filetypes message"
errormessages: {
max_file_size: "{{ error_max_file_size }}",
accepted_file_types: "{{ error_accepted_file_types }}"
}
}
window.tagit_opts = {

Wyświetl plik

@ -15,7 +15,7 @@ from wagtail.wagtailsearch.backends import get_search_backends
from wagtail.wagtailimages.models import get_image_model
from wagtail.wagtailimages.forms import get_image_form
from wagtail.wagtailimages.fields import MAX_UPLOAD_SIZE, IMAGE_FIELD_HELP_TEXT, ALLOWED_EXTENSIONS
from wagtail.wagtailimages.fields import MAX_UPLOAD_SIZE, IMAGE_FIELD_HELP_TEXT, INVALID_IMAGE_ERROR, ALLOWED_EXTENSIONS, ALLOWED_EXTENSIONS_TEXT, FILE_TOO_LARGE_ERROR
def json_response(document):
@ -84,6 +84,8 @@ def add(request):
'max_filesize': MAX_UPLOAD_SIZE,
'help_text': IMAGE_FIELD_HELP_TEXT,
'allowed_extensions': ALLOWED_EXTENSIONS,
'error_max_file_size': FILE_TOO_LARGE_ERROR,
'error_accepted_file_types': INVALID_IMAGE_ERROR,
})