Commit c70af40e authored by Seb's avatar Seb
Browse files

Start of work for template tag, rendering non transoded video working

parent 9d09e446
...@@ -142,15 +142,12 @@ class AbstractVideo(CollectionMember, TagSearchable): ...@@ -142,15 +142,12 @@ class AbstractVideo(CollectionMember, TagSearchable):
super(AbstractVideo, self).save(**kwargs) super(AbstractVideo, self).save(**kwargs)
@property @property
def filename(self): def url(self):
return os.path.basename(self.file.name) return self.file.url
@property @property
def default_alt_text(self): def filename(self):
# by default the alt text field (used in rich text insertion) is populated return os.path.basename(self.file.name)
# from the title. Subclasses might provide a separate alt field, and
# override this
return self.title
def is_editable_by_user(self, user): def is_editable_by_user(self, user):
from wagtail.wagtailimages.permissions import permission_policy from wagtail.wagtailimages.permissions import permission_policy
...@@ -172,8 +169,7 @@ class AbstractVideo(CollectionMember, TagSearchable): ...@@ -172,8 +169,7 @@ class AbstractVideo(CollectionMember, TagSearchable):
except Transcode.DoesNotExist: except Transcode.DoesNotExist:
output_dir = tempfile.mkdtemp() output_dir = tempfile.mkdtemp()
transcode_filename = os.path.splitext( transcode_filename = os.path.splitext(self.filename)[0] + '.' + media_format.name
os.path.basename(self.file.path))[0] + '.' + media_format.name
transcoded_file = self.do_transcode( transcoded_file = self.do_transcode(
media_format, self.file.path, output_dir, transcode_filename) media_format, self.file.path, output_dir, transcode_filename)
...@@ -257,12 +253,13 @@ def get_video_model(): ...@@ -257,12 +253,13 @@ def get_video_model():
except AttributeError: except AttributeError:
return Video return Video
except ValueError: except ValueError:
raise ImproperlyConfigured("WAGTAILIMAGES_IMAGE_MODEL must be of the form 'app_label.model_name'") raise ImproperlyConfigured("WAGTAILVIDEOS_VIDEO_MODEL must be of the form 'app_label.model_name'")
#TODO is this neccescary ??
image_model = apps.get_model(app_label, model_name) image_model = apps.get_model(app_label, model_name)
if image_model is None: if image_model is None:
raise ImproperlyConfigured( raise ImproperlyConfigured(
"WAGTAILIMAGES_IMAGE_MODEL refers to model '%s' that has not been installed" % "WAGTAILVIDEOS_VIDEO_MODEL refers to model '%s' that has not been installed" %
settings.WAGTAILIMAGES_IMAGE_MODEL settings.WAGTAILIMAGES_IMAGE_MODEL
) )
return image_model return image_model
......
...@@ -51,19 +51,18 @@ ...@@ -51,19 +51,18 @@
<video style='max-width:100%;height:auto;' {# FIXME Inline styles #} preload="auto" controls="true" poster='{{video.thumbnail.url}}'> <video style='max-width:100%;height:auto;' {# FIXME Inline styles #} preload="auto" controls="true" poster='{{video.thumbnail.url}}'>
<source src="{{video.file.url}}" type='video/mp4'/> <source src="{{video.file.url}}" type='video/mp4'/>
</video> </video>
{% if transcodes %}
<div class="focal-point-chooser" <h3>Available Transcodes</h3>
style="max-width: {{ rendition.width }}px; max-height: {{ rendition.height }}px;" <ul>
data-focal-point-x="{{ image.focal_point_x }}" {% for transcode in transcodes %}
data-focal-point-y="{{ image.focal_point_y }}" <li>{{ transcode.media_format }}</li>
data-focal-point-width="{{ image.focal_point_width }}" {% endfor %}
data-focal-point-height="{{ image.focal_point_height }}"> </ul>
{% else %}
<img {{ rendition.attrs }} data-original-width="{{ image.width }}" data-original-height="{{ image.height }}" class="show-transparency"> <h3>No transcodes found</h3>
<p>If you wish to generate HTML5 compliant transcodes use the button below. This may take a while.</p>
<div class="current-focal-point-indicator{% if not image.focal_point %} hidden{% endif %}"></div> <button>Generate Transcodes</button>
</div> {% endif %}
</div> </div>
<div class="col2 "> <div class="col2 ">
{% if url_generator_enabled %} {% if url_generator_enabled %}
......
from __future__ import absolute_import, unicode_literals
from django import template
from django.template import resolve_variable
from django.utils.text import mark_safe
from wagtailvideos.models import MediaFormats, Video
register = template.Library()
# {% video self.intro_video html5(optional) %}
@register.tag(name="video")
def video(parser, token):
contents = token.split_contents()
try:
video_field = contents[1] # A Video object should be the first variable
except ValueError:
raise template.TemplateSyntaxError("video tag requires a Video as the first option")
if len(contents) > 2:
return VideoNode(video_field, contents[2] == 'html5')
else:
return VideoNode(video_field)
class VideoNode(template.Node):
def __init__(self, video, html5=False):
self.video = template.Variable(video)
self.html5 = html5
def render(self, context):
video = self.video.resolve(context)
if not self.html5:
return mark_safe("<video controls><source src='{0}' type='{1}'></video>"
.format(video.url, 'video/mp4'))
else:
return ''
# TODO
# https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailimages/models.py#L500
...@@ -10,6 +10,7 @@ from wagtail.wagtailadmin import messages ...@@ -10,6 +10,7 @@ from wagtail.wagtailadmin import messages
from wagtail.wagtailadmin.forms import SearchForm from wagtail.wagtailadmin.forms import SearchForm
from wagtail.wagtailcore.models import Collection, Site from wagtail.wagtailcore.models import Collection, Site
from wagtail.wagtailsearch.backends import get_search_backends from wagtail.wagtailsearch.backends import get_search_backends
from wagtailvideos.forms import URLGeneratorForm, get_video_form from wagtailvideos.forms import URLGeneratorForm, get_video_form
from wagtailvideos.models import get_video_model from wagtailvideos.models import get_video_model
...@@ -122,6 +123,7 @@ def edit(request, video_id): ...@@ -122,6 +123,7 @@ def edit(request, video_id):
'form': form, 'form': form,
'url_generator_enabled': url_generator_enabled, 'url_generator_enabled': url_generator_enabled,
'filesize': video.get_file_size(), 'filesize': video.get_file_size(),
'transcodes': video.transcodes.all(),
}) })
......
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