Commit 3307ecb8 authored by Seb's avatar Seb
Browse files

Any video type is now allowed to be upploaded

parent 8462f23f
...@@ -6,9 +6,6 @@ from django.forms.fields import FileField ...@@ -6,9 +6,6 @@ from django.forms.fields import FileField
from django.template.defaultfilters import filesizeformat from django.template.defaultfilters import filesizeformat
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
ALLOWED_EXTENSIONS = ['mov', 'mp4']
SUPPORTED_FORMATS_TEXT = _("MOV, MP4")
class WagtailVideoField(FileField): class WagtailVideoField(FileField):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
...@@ -21,25 +18,14 @@ class WagtailVideoField(FileField): ...@@ -21,25 +18,14 @@ class WagtailVideoField(FileField):
# Help text # Help text
if self.max_upload_size is not None: if self.max_upload_size is not None:
self.help_text = _( self.help_text = _(
"Supported formats: %(supported_formats)s. Maximum filesize: %(max_upload_size)s." "Maximum filesize: %(max_upload_size)s."
) % { ) % {
'supported_formats': SUPPORTED_FORMATS_TEXT,
'max_upload_size': max_upload_size_text, 'max_upload_size': max_upload_size_text,
} }
else:
self.help_text = _(
"Supported formats: %(supported_formats)s."
) % {
'supported_formats': SUPPORTED_FORMATS_TEXT,
}
# Error messages # Error messages
self.error_messages['invalid_image'] = _( self.error_messages['invalid_video_format'] = _(
"Not a supported image format. Supported formats: %s." "Not a valid video."
) % SUPPORTED_FORMATS_TEXT
self.error_messages['invalid_video_known_format'] = _(
"Not a valid %s video."
) )
self.error_messages['file_too_large'] = _( self.error_messages['file_too_large'] = _(
...@@ -51,23 +37,8 @@ class WagtailVideoField(FileField): ...@@ -51,23 +37,8 @@ class WagtailVideoField(FileField):
) % max_upload_size_text ) % max_upload_size_text
def check_video_file_format(self, f): def check_video_file_format(self, f):
# Check file extension if not f.content_type.startswith('video'):
extension = os.path.splitext(f.name)[1].lower()[1:] raise ValidationError(self.error_messages['invalid_video_format'])
if extension not in ALLOWED_EXTENSIONS:
raise ValidationError(self.error_messages['invalid_video'], code='invalid_video')
if hasattr(f, 'video'):
# Django 1.8 annotates the file object with the PIL image
pass
elif not f.closed:
# Open image file
file_position = f.tell()
f.seek(0)
f.seek(file_position)
else:
# Couldn't get the PIL image, skip checking the internal file format
return
def check_video_file_size(self, f): def check_video_file_size(self, f):
# Upload size checking can be disabled by setting max upload size to None # Upload size checking can be disabled by setting max upload size to None
......
...@@ -79,7 +79,6 @@ ...@@ -79,7 +79,6 @@
<script> <script>
window.fileupload_opts = { window.fileupload_opts = {
simple_upload_url: "{% url 'wagtailvideos:add' %}", simple_upload_url: "{% url 'wagtailvideos:add' %}",
accepted_file_types: /\.({{ allowed_extensions|join:"|" }})$/i, //must be regex
max_file_size: {{ max_filesize|stringformat:"s"|default:"null" }}, //numeric format max_file_size: {{ max_filesize|stringformat:"s"|default:"null" }}, //numeric format
errormessages: { errormessages: {
max_file_size: "{{ error_max_file_size }}", max_file_size: "{{ error_max_file_size }}",
......
...@@ -7,7 +7,6 @@ from django.views.decorators.vary import vary_on_headers ...@@ -7,7 +7,6 @@ from django.views.decorators.vary import vary_on_headers
from wagtail.wagtailadmin.utils import PermissionPolicyChecker from wagtail.wagtailadmin.utils import PermissionPolicyChecker
from wagtail.wagtailsearch.backends import get_search_backends from wagtail.wagtailsearch.backends import get_search_backends
from wagtailvideos.fields import ALLOWED_EXTENSIONS
from wagtailvideos.forms import get_video_form from wagtailvideos.forms import get_video_form
from wagtailvideos.models import Video from wagtailvideos.models import Video
from wagtailvideos.permissions import permission_policy from wagtailvideos.permissions import permission_policy
...@@ -76,7 +75,6 @@ def add(request): ...@@ -76,7 +75,6 @@ def add(request):
}, request=request), }, request=request),
}) })
else: else:
print(form.errors)
# Validation error # Validation error
return JsonResponse({ return JsonResponse({
'success': False, 'success': False,
...@@ -90,11 +88,9 @@ def add(request): ...@@ -90,11 +88,9 @@ def add(request):
return render(request, 'wagtailvideos/multiple/add.html', { return render(request, 'wagtailvideos/multiple/add.html', {
'max_filesize': form.fields['file'].max_upload_size, 'max_filesize': form.fields['file'].max_upload_size,
'help_text': form.fields['file'].help_text, 'help_text': form.fields['file'].help_text,
'allowed_extensions': ALLOWED_EXTENSIONS,
'error_max_file_size': form.fields['file'].error_messages['file_too_large_unknown_size'], 'error_max_file_size': form.fields['file'].error_messages['file_too_large_unknown_size'],
'error_accepted_file_types': form.fields['file'].error_messages['invalid_image'], 'error_accepted_file_types': form.fields['file'].error_messages['invalid_video_format'],
'collections': collections_to_choose, 'collections': collections_to_choose,
}) })
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment