Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Wagtail Videos
Commits
3307ecb8
Commit
3307ecb8
authored
Jul 08, 2016
by
Seb
Browse files
Any video type is now allowed to be upploaded
parent
8462f23f
Changes
3
Hide whitespace changes
Inline
Side-by-side
wagtailvideos/fields.py
View file @
3307ecb8
...
...
@@ -6,9 +6,6 @@ from django.forms.fields import FileField
from
django.template.defaultfilters
import
filesizeformat
from
django.utils.translation
import
ugettext_lazy
as
_
ALLOWED_EXTENSIONS
=
[
'mov'
,
'mp4'
]
SUPPORTED_FORMATS_TEXT
=
_
(
"MOV, MP4"
)
class
WagtailVideoField
(
FileField
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -21,25 +18,14 @@ class WagtailVideoField(FileField):
# Help text
if
self
.
max_upload_size
is
not
None
:
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
,
}
else
:
self
.
help_text
=
_
(
"Supported formats: %(supported_formats)s."
)
%
{
'supported_formats'
:
SUPPORTED_FORMATS_TEXT
,
}
# Error messages
self
.
error_messages
[
'invalid_image'
]
=
_
(
"Not a supported image format. Supported formats: %s."
)
%
SUPPORTED_FORMATS_TEXT
self
.
error_messages
[
'invalid_video_known_format'
]
=
_
(
"Not a valid %s video."
self
.
error_messages
[
'invalid_video_format'
]
=
_
(
"Not a valid video."
)
self
.
error_messages
[
'file_too_large'
]
=
_
(
...
...
@@ -51,23 +37,8 @@ class WagtailVideoField(FileField):
)
%
max_upload_size_text
def
check_video_file_format
(
self
,
f
):
# Check file extension
extension
=
os
.
path
.
splitext
(
f
.
name
)[
1
].
lower
()[
1
:]
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
if
not
f
.
content_type
.
startswith
(
'video'
):
raise
ValidationError
(
self
.
error_messages
[
'invalid_video_format'
])
def
check_video_file_size
(
self
,
f
):
# Upload size checking can be disabled by setting max upload size to None
...
...
wagtailvideos/templates/wagtailvideos/multiple/add.html
View file @
3307ecb8
...
...
@@ -79,7 +79,6 @@
<script>
window
.
fileupload_opts
=
{
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
errormessages
:
{
max_file_size
:
"
{{ error_max_file_size }}
"
,
...
...
wagtailvideos/views/multiple.py
View file @
3307ecb8
...
...
@@ -7,7 +7,6 @@ from django.views.decorators.vary import vary_on_headers
from
wagtail.wagtailadmin.utils
import
PermissionPolicyChecker
from
wagtail.wagtailsearch.backends
import
get_search_backends
from
wagtailvideos.fields
import
ALLOWED_EXTENSIONS
from
wagtailvideos.forms
import
get_video_form
from
wagtailvideos.models
import
Video
from
wagtailvideos.permissions
import
permission_policy
...
...
@@ -76,7 +75,6 @@ def add(request):
},
request
=
request
),
})
else
:
print
(
form
.
errors
)
# Validation error
return
JsonResponse
({
'success'
:
False
,
...
...
@@ -90,11 +88,9 @@ def add(request):
return
render
(
request
,
'wagtailvideos/multiple/add.html'
,
{
'max_filesize'
:
form
.
fields
[
'file'
].
max_upload_size
,
'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_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
,
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment