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
3e0677e0
Commit
3e0677e0
authored
Sep 28, 2016
by
Liam Brenner
Committed by
GitHub
Sep 28, 2016
Browse files
Merge pull request #10 from takeflight/cleanup
Cleanup, enforce isort and flake8
parents
d5be1142
0dc15f0c
Changes
11
Hide whitespace changes
Inline
Side-by-side
.travis.yml
View file @
3e0677e0
language
:
python
language
:
python
cache
:
pip
cache
:
pip
# Matrix of build options
python
:
-
'
2.7'
-
'
3.4'
-
'
3.5'
env
:
env
:
global
:
global
:
-
DJANGO_SETTINGS_MODULE="tests.app.settings"
-
DJANGO_SETTINGS_MODULE="tests.app.settings"
-
TOX_ENV=
-
TOX_ENV=
matrix
:
matrix
:
-
DJANGO='18' WAGTAIL='14'
-
TOX_ENV=flake8,isort
-
DJANGO='19' WAGTAIL='14'
-
DJANGO='18' WAGTAIL='15'
matrix
:
-
DJANGO='19' WAGTAIL='15'
-
env
:
DJANGO='18' WAGTAIL='14'
-
DJANGO='19' WAGTAIL='16'
python
:
2.7
-
DJANGO='110' WAGTAIL='16'
-
env
:
DJANGO='18' WAGTAIL='14'
python
:
3.4
-
env
:
DJANGO='18' WAGTAIL='14'
python
:
3.5
-
env
:
DJANGO='19' WAGTAIL='14'
python
:
2.7
-
env
:
DJANGO='19' WAGTAIL='14'
python
:
3.4
-
env
:
DJANGO='19' WAGTAIL='14'
python
:
3.5
-
env
:
DJANGO='18' WAGTAIL='15'
python
:
2.7
-
env
:
DJANGO='18' WAGTAIL='15'
python
:
3.4
-
env
:
DJANGO='18' WAGTAIL='15'
python
:
3.5
-
env
:
DJANGO='19' WAGTAIL='15'
python
:
2.7
-
env
:
DJANGO='19' WAGTAIL='15'
python
:
3.4
-
env
:
DJANGO='19' WAGTAIL='15'
python
:
3.5
-
env
:
DJANGO='19' WAGTAIL='16'
python
:
2.7
-
env
:
DJANGO='19' WAGTAIL='16'
python
:
3.4
-
env
:
DJANGO='19' WAGTAIL='16'
python
:
3.5
-
env
:
DJANGO='110' WAGTAIL='16'
python
:
2.7
-
env
:
DJANGO='110' WAGTAIL='16'
python
:
3.4
-
env
:
DJANGO='110' WAGTAIL='16'
python
:
3.5
-
env
:
TOX_ENV='flake8,isort'
python
:
3.5
before_install
:
before_install
:
# - sudo add-apt-repository ppa:mc3man/trusty-media -y // Inlcudes all multimedia options but 404s currently :(
# - sudo add-apt-repository ppa:mc3man/trusty-media -y // Inlcudes all multimedia options but 404s currently :(
...
...
setup.cfg
View file @
3e0677e0
[metadata]
[metadata]
description-file = README.rst
description-file = README.rst
[bdist_wheel]
[bdist_wheel]
universal = 1
universal = 1
[isort]
skip_glob = */migrations/*
line_length = 79
multi_line_output = 4
[pep8]
max-line-length = 100
[flake8]
max-line-length = 100
ignore = E501
exclude = migrations
tests/test_template_tag.py
View file @
3e0677e0
...
@@ -16,7 +16,7 @@ class TestVideoTag(TestCase):
...
@@ -16,7 +16,7 @@ class TestVideoTag(TestCase):
def
render_video_tag
(
self
,
video
,
attrs
=
''
):
def
render_video_tag
(
self
,
video
,
attrs
=
''
):
temp
=
Template
(
'{% load wagtailvideos_tags %}{% video video_obj '
+
attrs
+
' %}'
)
temp
=
Template
(
'{% load wagtailvideos_tags %}{% video video_obj '
+
attrs
+
' %}'
)
context
=
Context
({
'video_obj'
:
video
})
context
=
Context
({
'video_obj'
:
video
})
return
temp
.
render
(
context
)
return
temp
.
render
(
context
)
def
test_video_tag
(
self
):
def
test_video_tag
(
self
):
...
...
tox.ini
View file @
3e0677e0
...
@@ -8,14 +8,18 @@ envlist =
...
@@ -8,14 +8,18 @@ envlist =
py{27,34,35}-dj{18,19}-wt15
py{27,34,35}-dj{18,19}-wt15
# Current version
# Current version
py{27,34,35}-dj{19,110}-wt16
py{27,34,35}-dj{19,110}-wt16
# Enforce good style
flake8,isort
[base]
deps
=
mock
[testenv]
[testenv]
commands
=
python runtests.py {posargs}
commands
=
python runtests.py {posargs}
pip_pre
=
True
pip_pre
=
True
deps
=
deps
=
mock
{
[base]
deps}
dj18:
Django~=1.8.0
dj18:
Django~=1.8.0
dj19:
Django~=1.9.0
dj19:
Django~=1.9.0
dj110:
Django~=1.10.0
dj110:
Django~=1.10.0
...
@@ -23,3 +27,16 @@ deps =
...
@@ -23,3 +27,16 @@ deps =
wt14:
wagtail~=1.4.0
wt14:
wagtail~=1.4.0
wt15:
wagtail~=1.5.0
wt15:
wagtail~=1.5.0
wt16:
wagtail~=1.6.0
wt16:
wagtail~=1.6.0
[testenv:flake8]
deps
=
flake8
basepython
=
python3.5
commands
=
flake8 wagtailvideos/ tests/
[testenv:isort]
usedevelop
=
True
deps
=
{
[base]
deps}
isort
=
=4.2.2
basepython
=
python3.5
commands
=
isort --recursive --diff --check-only wagtailvideos/ tests/
wagtailvideos/fields.py
View file @
3e0677e0
from
__future__
import
absolute_import
,
print_function
,
unicode_literals
from
__future__
import
absolute_import
,
print_function
,
unicode_literals
import
os
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.forms.fields
import
FileField
from
django.forms.fields
import
FileField
...
...
wagtailvideos/forms.py
View file @
3e0677e0
...
@@ -2,12 +2,11 @@ from __future__ import absolute_import, print_function, unicode_literals
...
@@ -2,12 +2,11 @@ from __future__ import absolute_import, print_function, unicode_literals
from
django
import
forms
from
django
import
forms
from
django.forms.models
import
modelform_factory
from
django.forms.models
import
modelform_factory
from
django.forms.widgets
import
FileInput
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
enumchoicefield.forms
import
EnumField
from
enumchoicefield.forms
import
EnumField
from
wagtail.wagtailadmin
import
widgets
from
wagtail.wagtailadmin
import
widgets
from
wagtail.wagtailadmin.forms
import
(
BaseCollectionMemberForm
,
from
wagtail.wagtailadmin.forms
import
(
collection_member_permission_formset_factory
)
BaseCollectionMemberForm
,
collection_member_permission_formset_factory
)
from
wagtailvideos.fields
import
WagtailVideoField
from
wagtailvideos.fields
import
WagtailVideoField
from
wagtailvideos.models
import
MediaFormats
,
Video
,
VideoQuality
from
wagtailvideos.models
import
MediaFormats
,
Video
,
VideoQuality
...
@@ -18,6 +17,7 @@ from wagtailvideos.permissions import \
...
@@ -18,6 +17,7 @@ from wagtailvideos.permissions import \
class
BaseVideoForm
(
BaseCollectionMemberForm
):
class
BaseVideoForm
(
BaseCollectionMemberForm
):
permission_policy
=
video_permission_policy
permission_policy
=
video_permission_policy
# Callback to allow us to override the default form field for the image file field
# Callback to allow us to override the default form field for the image file field
def
formfield_for_dbfield
(
db_field
,
**
kwargs
):
def
formfield_for_dbfield
(
db_field
,
**
kwargs
):
# Check if this is the file field
# Check if this is the file field
...
@@ -57,7 +57,7 @@ class VideoTranscodeAdminForm(forms.Form):
...
@@ -57,7 +57,7 @@ class VideoTranscodeAdminForm(forms.Form):
media_format
=
EnumField
(
MediaFormats
)
media_format
=
EnumField
(
MediaFormats
)
quality
=
EnumField
(
VideoQuality
)
quality
=
EnumField
(
VideoQuality
)
def
__init__
(
self
,
video
,
data
=
None
,
**
kwargs
):
def
__init__
(
self
,
video
,
data
=
None
,
**
kwargs
):
super
(
VideoTranscodeAdminForm
,
self
).
__init__
(
data
=
data
,
**
kwargs
)
super
(
VideoTranscodeAdminForm
,
self
).
__init__
(
data
=
data
,
**
kwargs
)
self
.
video
=
video
self
.
video
=
video
...
...
wagtailvideos/models.py
View file @
3e0677e0
...
@@ -24,7 +24,6 @@ from django.utils.text import mark_safe
...
@@ -24,7 +24,6 @@ from django.utils.text import mark_safe
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
enumchoicefield
import
ChoiceEnum
,
EnumChoiceField
from
enumchoicefield
import
ChoiceEnum
,
EnumChoiceField
from
taggit.managers
import
TaggableManager
from
taggit.managers
import
TaggableManager
from
unidecode
import
unidecode
from
wagtail.wagtailadmin.taggable
import
TagSearchable
from
wagtail.wagtailadmin.taggable
import
TagSearchable
from
wagtail.wagtailadmin.utils
import
get_object_usage
from
wagtail.wagtailadmin.utils
import
get_object_usage
from
wagtail.wagtailcore.models
import
CollectionMember
from
wagtail.wagtailcore.models
import
CollectionMember
...
@@ -67,6 +66,7 @@ class MediaFormats(ChoiceEnum):
...
@@ -67,6 +66,7 @@ class MediaFormats(ChoiceEnum):
VideoQuality
.
highest
:
'9'
VideoQuality
.
highest
:
'9'
}[
quality
]
}[
quality
]
class
VideoQuerySet
(
SearchableQuerySetMixin
,
models
.
QuerySet
):
class
VideoQuerySet
(
SearchableQuerySetMixin
,
models
.
QuerySet
):
pass
pass
...
@@ -314,7 +314,7 @@ class TranscodingThread(threading.Thread):
...
@@ -314,7 +314,7 @@ class TranscodingThread(threading.Thread):
elif
media_format
is
MediaFormats
.
mp4
:
elif
media_format
is
MediaFormats
.
mp4
:
subprocess
.
check_output
(
args
+
[
subprocess
.
check_output
(
args
+
[
'-codec:v'
,
'libx264'
,
'-codec:v'
,
'libx264'
,
'-preset'
,
'slow'
,
# TODO Checkout other presets
'-preset'
,
'slow'
,
# TODO Checkout other presets
'-crf'
,
quality_param
,
'-crf'
,
quality_param
,
'-codec:a'
,
'copy'
,
'-codec:a'
,
'copy'
,
output_file
,
output_file
,
...
...
wagtailvideos/templatetags/wagtailvideos_tags.py
View file @
3e0677e0
...
@@ -5,7 +5,6 @@ import mimetypes
...
@@ -5,7 +5,6 @@ import mimetypes
from
django
import
template
from
django
import
template
from
django.forms.widgets
import
flatatt
from
django.forms.widgets
import
flatatt
from
django.utils.text
import
mark_safe
from
django.utils.text
import
mark_safe
from
wagtailvideos.models
import
MediaFormats
,
Video
register
=
template
.
Library
()
register
=
template
.
Library
()
# {% video self.intro_video extra_att extra_att %}
# {% video self.intro_video extra_att extra_att %}
...
@@ -13,7 +12,7 @@ register = template.Library()
...
@@ -13,7 +12,7 @@ register = template.Library()
@
register
.
tag
(
name
=
"video"
)
@
register
.
tag
(
name
=
"video"
)
def
video
(
parser
,
token
):
def
video
(
parser
,
token
):
template_params
=
token
.
split_contents
()[
1
:]
# Everything after 'video'
template_params
=
token
.
split_contents
()[
1
:]
# Everything after 'video'
video_expr
=
template_params
[
0
]
video_expr
=
template_params
[
0
]
extra_attrs
=
{}
extra_attrs
=
{}
...
@@ -28,6 +27,7 @@ def video(parser, token):
...
@@ -28,6 +27,7 @@ def video(parser, token):
extra_attrs
[
param
]
=
''
# attributes without values e.g. autoplay, controls
extra_attrs
[
param
]
=
''
# attributes without values e.g. autoplay, controls
return
VideoNode
(
video_expr
,
extra_attrs
)
return
VideoNode
(
video_expr
,
extra_attrs
)
class
VideoNode
(
template
.
Node
):
class
VideoNode
(
template
.
Node
):
def
__init__
(
self
,
video
,
attrs
=
{}):
def
__init__
(
self
,
video
,
attrs
=
{}):
self
.
video
=
template
.
Variable
(
video
)
self
.
video
=
template
.
Variable
(
video
)
...
@@ -48,7 +48,7 @@ class VideoNode(template.Node):
...
@@ -48,7 +48,7 @@ class VideoNode(template.Node):
transcodes
=
video
.
transcodes
.
exclude
(
processing
=
True
).
filter
(
error_message__exact
=
''
)
transcodes
=
video
.
transcodes
.
exclude
(
processing
=
True
).
filter
(
error_message__exact
=
''
)
for
transcode
in
transcodes
:
for
transcode
in
transcodes
:
sources
.
append
(
"<source src='{0}' type='video/{1}' >"
.
format
(
transcode
.
url
,
transcode
.
media_format
.
name
))
sources
.
append
(
"<source src='{0}' type='video/{1}' >"
.
format
(
transcode
.
url
,
transcode
.
media_format
.
name
))
sources
.
append
(
"<p>Sorry, your browser doesn't support playback for this video</p>"
)
sources
.
append
(
"<p>Sorry, your browser doesn't support playback for this video</p>"
)
return
mark_safe
(
return
mark_safe
(
"<video {0}>{1}</video>"
.
format
(
flatatt
(
self
.
attrs
),
"
\n
"
.
join
(
sources
)))
"<video {0}>{1}</video>"
.
format
(
flatatt
(
self
.
attrs
),
"
\n
"
.
join
(
sources
)))
wagtailvideos/views/multiple.py
View file @
3e0677e0
...
@@ -41,7 +41,6 @@ def add(request):
...
@@ -41,7 +41,6 @@ def add(request):
# no need to show a collections chooser
# no need to show a collections chooser
collections_to_choose
=
None
collections_to_choose
=
None
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
if
not
request
.
is_ajax
():
if
not
request
.
is_ajax
():
return
HttpResponseBadRequest
(
"Cannot POST to this view without AJAX"
)
return
HttpResponseBadRequest
(
"Cannot POST to this view without AJAX"
)
...
...
wagtailvideos/views/videos.py
View file @
3e0677e0
...
@@ -2,8 +2,8 @@ from __future__ import absolute_import, print_function, unicode_literals
...
@@ -2,8 +2,8 @@ from __future__ import absolute_import, print_function, unicode_literals
import
os
import
os
from
django.core.urlresolvers
import
NoReverseMatch
,
reverse
from
django.core.urlresolvers
import
reverse
from
django.http
import
HttpResponseNotAllowed
,
JsonResponse
from
django.http
import
HttpResponseNotAllowed
from
django.shortcuts
import
get_object_or_404
,
redirect
,
render
from
django.shortcuts
import
get_object_or_404
,
redirect
,
render
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
django.views.decorators.vary
import
vary_on_headers
from
django.views.decorators.vary
import
vary_on_headers
...
@@ -11,7 +11,7 @@ from wagtail.utils.pagination import paginate
...
@@ -11,7 +11,7 @@ from wagtail.utils.pagination import paginate
from
wagtail.wagtailadmin
import
messages
from
wagtail.wagtailadmin
import
messages
from
wagtail.wagtailadmin.forms
import
SearchForm
from
wagtail.wagtailadmin.forms
import
SearchForm
from
wagtail.wagtailadmin.utils
import
PermissionPolicyChecker
from
wagtail.wagtailadmin.utils
import
PermissionPolicyChecker
from
wagtail.wagtailcore.models
import
Collection
,
Site
from
wagtail.wagtailcore.models
import
Collection
from
wagtail.wagtailsearch.backends
import
get_search_backends
from
wagtail.wagtailsearch.backends
import
get_search_backends
from
wagtailvideos.forms
import
VideoTranscodeAdminForm
,
get_video_form
from
wagtailvideos.forms
import
VideoTranscodeAdminForm
,
get_video_form
...
@@ -21,6 +21,7 @@ from wagtailvideos.utils import ffmpeg_installed
...
@@ -21,6 +21,7 @@ from wagtailvideos.utils import ffmpeg_installed
permission_checker
=
PermissionPolicyChecker
(
permission_policy
)
permission_checker
=
PermissionPolicyChecker
(
permission_policy
)
@
permission_checker
.
require_any
(
'add'
,
'change'
,
'delete'
)
@
permission_checker
.
require_any
(
'add'
,
'change'
,
'delete'
)
@
vary_on_headers
(
'X-Requested-With'
)
@
vary_on_headers
(
'X-Requested-With'
)
def
index
(
request
):
def
index
(
request
):
...
@@ -125,6 +126,7 @@ def edit(request, video_id):
...
@@ -125,6 +126,7 @@ def edit(request, video_id):
'user_can_delete'
:
permission_policy
.
user_has_permission_for_instance
(
request
.
user
,
'delete'
,
video
)
'user_can_delete'
:
permission_policy
.
user_has_permission_for_instance
(
request
.
user
,
'delete'
,
video
)
})
})
def
create_transcode
(
request
,
video_id
):
def
create_transcode
(
request
,
video_id
):
if
request
.
method
!=
'POST'
:
if
request
.
method
!=
'POST'
:
return
HttpResponseNotAllowed
([
'POST'
])
return
HttpResponseNotAllowed
([
'POST'
])
...
...
wagtailvideos/wagtail_hooks.py
View file @
3e0677e0
...
@@ -38,10 +38,12 @@ def editor_js():
...
@@ -38,10 +38,12 @@ def editor_js():
urlresolvers
.
reverse
(
'wagtailvideos:chooser'
)
urlresolvers
.
reverse
(
'wagtailvideos:chooser'
)
)
)
@
hooks
.
register
(
'register_group_permission_panel'
)
@
hooks
.
register
(
'register_group_permission_panel'
)
def
register_video_permissions_panel
():
def
register_video_permissions_panel
():
return
GroupVideoPermissionFormSet
return
GroupVideoPermissionFormSet
@
hooks
.
register
(
'register_admin_menu_item'
)
@
hooks
.
register
(
'register_admin_menu_item'
)
def
register_images_menu_item
():
def
register_images_menu_item
():
return
MenuItem
(
return
MenuItem
(
...
...
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