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
5f9e25b6
Commit
5f9e25b6
authored
Sep 26, 2016
by
Liam Brenner
Browse files
Allow dictionary for jinja2 tag, other jinja2 tag fixes
parent
4d4c03a2
Changes
2
Show whitespace changes
Inline
Side-by-side
wagtailvideos/jinja2tags.py
View file @
5f9e25b6
...
...
@@ -5,10 +5,13 @@ from jinja2.ext import Extension
from
.models
import
Video
def
video
(
video
,
attrs
=
'preload controls'
):
if
type
(
video
)
!=
Video
:
raise
TypeError
(
'Expected type {0}, received {1}.'
.
format
(
Video
,
type
(
video
)))
def
video
(
video
,
**
attrs
):
if
isinstance
(
video
,
Video
):
defaults
=
{
'preload'
:
True
,
'controls'
:
True
}
defaults
.
update
(
attrs
)
return
video
.
video_tag
(
attrs
)
else
:
raise
TypeError
(
'Expected type {0}, received {1}.'
.
format
(
Video
,
type
(
video
)))
class
WagtailVideosExtension
(
Extension
):
...
...
wagtailvideos/models.py
View file @
5f9e25b6
...
...
@@ -236,9 +236,13 @@ class AbstractVideo(CollectionMember, TagSearchable):
except
Transcode
.
DoesNotExist
:
return
self
.
do_transcode
(
media_format
)
def
video_tag
(
self
,
attrs
,
kw_attrs
=
{}):
def
video_tag
(
self
,
attrs
=
None
):
if
attrs
is
None
:
attrs
=
{}
else
:
attrs
=
attrs
.
copy
()
if
self
.
thumbnail
:
kw_
attrs
[
'poster'
]
=
self
.
thumbnail
.
url
attrs
[
'poster'
]
=
self
.
thumbnail
.
url
mime
=
mimetypes
.
MimeTypes
()
sources
=
[
"<source src='{0}' type='{1}'>"
...
...
@@ -249,7 +253,7 @@ class AbstractVideo(CollectionMember, TagSearchable):
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>"
)
return
mark_safe
(
"<video {0}
{1}>{2}
</video>"
.
format
(
attrs
,
flatatt
(
kw_
attrs
),
"
\n
"
.
join
(
sources
)))
"<video {0}
>
\n
{1}
\n
</video>"
.
format
(
flatatt
(
attrs
),
"
\n
"
.
join
(
sources
)))
def
do_transcode
(
self
,
media_format
,
quality
):
transcode
,
created
=
self
.
transcodes
.
get_or_create
(
...
...
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