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
ba38a6cc
Commit
ba38a6cc
authored
Sep 26, 2016
by
Liam Brenner
Committed by
GitHub
Sep 26, 2016
Browse files
Merge pull request #8 from takeflight/jinja2-tags
Add jinja2 tag
parents
4f7c599d
5f9e25b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
wagtailvideos/jinja2tags.py
0 → 100644
View file @
ba38a6cc
from
__future__
import
absolute_import
,
unicode_literals
from
jinja2.ext
import
Extension
from
.models
import
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
):
def
__init__
(
self
,
environment
):
super
(
WagtailVideosExtension
,
self
).
__init__
(
environment
)
self
.
environment
.
globals
.
update
({
'video'
:
video
,
})
videos
=
WagtailVideosExtension
wagtailvideos/models.py
View file @
ba38a6cc
...
...
@@ -2,6 +2,7 @@ from __future__ import absolute_import, print_function, unicode_literals
import
datetime
import
logging
import
mimetypes
import
os
import
os.path
import
re
...
...
@@ -17,7 +18,9 @@ from django.core.urlresolvers import reverse
from
django.db
import
models
from
django.db.models.signals
import
post_save
,
pre_delete
from
django.dispatch.dispatcher
import
receiver
from
django.forms.widgets
import
flatatt
from
django.utils.encoding
import
python_2_unicode_compatible
from
django.utils.text
import
mark_safe
from
django.utils.translation
import
ugettext_lazy
as
_
from
enumchoicefield
import
ChoiceEnum
,
EnumChoiceField
from
taggit.managers
import
TaggableManager
...
...
@@ -233,6 +236,25 @@ class AbstractVideo(CollectionMember, TagSearchable):
except
Transcode
.
DoesNotExist
:
return
self
.
do_transcode
(
media_format
)
def
video_tag
(
self
,
attrs
=
None
):
if
attrs
is
None
:
attrs
=
{}
else
:
attrs
=
attrs
.
copy
()
if
self
.
thumbnail
:
attrs
[
'poster'
]
=
self
.
thumbnail
.
url
mime
=
mimetypes
.
MimeTypes
()
sources
=
[
"<source src='{0}' type='{1}'>"
.
format
(
self
.
url
,
mime
.
guess_type
(
self
.
url
)[
0
])]
transcodes
=
self
.
transcodes
.
exclude
(
processing
=
True
).
filter
(
error_message__exact
=
''
)
for
transcode
in
transcodes
:
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}>
\n
{1}
\n
</video>"
.
format
(
flatatt
(
attrs
),
"
\n
"
.
join
(
sources
)))
def
do_transcode
(
self
,
media_format
,
quality
):
transcode
,
created
=
self
.
transcodes
.
get_or_create
(
media_format
=
media_format
,
...
...
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