Commit 5f9e25b6 authored by Liam Brenner's avatar Liam Brenner
Browse files

Allow dictionary for jinja2 tag, other jinja2 tag fixes

parent 4d4c03a2
...@@ -5,10 +5,13 @@ from jinja2.ext import Extension ...@@ -5,10 +5,13 @@ from jinja2.ext import Extension
from .models import Video from .models import Video
def video(video, attrs='preload controls'): def video(video, **attrs):
if type(video) != Video: 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))) raise TypeError('Expected type {0}, received {1}.'.format(Video, type(video)))
return video.video_tag(attrs)
class WagtailVideosExtension(Extension): class WagtailVideosExtension(Extension):
......
...@@ -236,9 +236,13 @@ class AbstractVideo(CollectionMember, TagSearchable): ...@@ -236,9 +236,13 @@ class AbstractVideo(CollectionMember, TagSearchable):
except Transcode.DoesNotExist: except Transcode.DoesNotExist:
return self.do_transcode(media_format) 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: if self.thumbnail:
kw_attrs['poster'] = self.thumbnail.url attrs['poster'] = self.thumbnail.url
mime = mimetypes.MimeTypes() mime = mimetypes.MimeTypes()
sources = ["<source src='{0}' type='{1}'>" sources = ["<source src='{0}' type='{1}'>"
...@@ -249,7 +253,7 @@ class AbstractVideo(CollectionMember, TagSearchable): ...@@ -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("<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}>{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): def do_transcode(self, media_format, quality):
transcode, created = self.transcodes.get_or_create( transcode, created = self.transcodes.get_or_create(
......
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