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):
super(AbstractVideo, self).save(**kwargs)
@property
def filename(self):
return os.path.basename(self.file.name)
def url(self):
return self.file.url
@property
def default_alt_text(self):
# by default the alt text field (used in rich text insertion) is populated
# from the title. Subclasses might provide a separate alt field, and
# override this
return self.title
def filename(self):
return os.path.basename(self.file.name)
def is_editable_by_user(self, user):
from wagtail.wagtailimages.permissions import permission_policy
......@@ -172,8 +169,7 @@ class AbstractVideo(CollectionMember, TagSearchable):
except Transcode.DoesNotExist:
output_dir = tempfile.mkdtemp()
transcode_filename = os.path.splitext(
os.path.basename(self.file.path))[0] + '.' + media_format.name
transcode_filename = os.path.splitext(self.filename)[0] + '.' + media_format.name
transcoded_file = self.do_transcode(
media_format, self.file.path, output_dir, transcode_filename)
......@@ -257,12 +253,13 @@ def get_video_model():
except AttributeError:
return Video
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)
if image_model is None:
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
)
return image_model
......
......@@ -51,19 +51,18 @@
<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'/>
</video>
<div class="focal-point-chooser"
style="max-width: {{ rendition.width }}px; max-height: {{ rendition.height }}px;"
data-focal-point-x="{{ image.focal_point_x }}"
data-focal-point-y="{{ image.focal_point_y }}"
data-focal-point-width="{{ image.focal_point_width }}"
data-focal-point-height="{{ image.focal_point_height }}">
<img {{ rendition.attrs }} data-original-width="{{ image.width }}" data-original-height="{{ image.height }}" class="show-transparency">
<div class="current-focal-point-indicator{% if not image.focal_point %} hidden{% endif %}"></div>
</div>
{% if transcodes %}
<h3>Available Transcodes</h3>
<ul>
{% for transcode in transcodes %}
<li>{{ transcode.media_format }}</li>
{% endfor %}
</ul>
{% else %}
<h3>No transcodes found</h3>
<p>If you wish to generate HTML5 compliant transcodes use the button below. This may take a while.</p>
<button>Generate Transcodes</button>
{% endif %}
</div>
<div class="col2 ">
{% 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
from wagtail.wagtailadmin.forms import SearchForm
from wagtail.wagtailcore.models import Collection, Site
from wagtail.wagtailsearch.backends import get_search_backends
from wagtailvideos.forms import URLGeneratorForm, get_video_form
from wagtailvideos.models import get_video_model
......@@ -122,6 +123,7 @@ def edit(request, video_id):
'form': form,
'url_generator_enabled': url_generator_enabled,
'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