From bdff3914406735f2ff4cb60523917d343efb733c Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Wed, 17 Jan 2018 15:55:25 +0100 Subject: [PATCH] Support for rendering of video file attachments --- pillar/web/nodes/attachments.py | 17 ++++++++++++++++- src/styles/blog.sass | 3 +++ src/templates/nodes/attachments/file_video.pug | 11 +++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/templates/nodes/attachments/file_video.pug diff --git a/pillar/web/nodes/attachments.py b/pillar/web/nodes/attachments.py index 69ea7f36..a7eb0760 100644 --- a/pillar/web/nodes/attachments.py +++ b/pillar/web/nodes/attachments.py @@ -69,7 +69,8 @@ def render_attachment_file(attachment): sdk_file = pillarsdk.File.find(attachment['oid'], api=api) file_renderers = { - 'image': render_attachment_file_image + 'image': render_attachment_file_image, + 'video': render_attachment_file_video, } mime_type_cat, _ = sdk_file.content_type.split('/', 1) @@ -89,6 +90,20 @@ def render_attachment_file_image(sdk_file, attachment): file=sdk_file, vars=variations, attachment=attachment) +def render_attachment_file_video(sdk_file, attachment): + """Renders a video file.""" + + try: + # The very first variation is an mp4 file with max width of 1920px + default_variation = sdk_file.variations[0] + except IndexError: + log.error('Could not find variations for file %s' % sdk_file._id) + return flask.render_template('nodes/attachments/file_generic.html', file=sdk_file) + + return flask.render_template('nodes/attachments/file_video.html', + file=sdk_file, var=default_variation, attachment=attachment) + + def attachment_form_group_create(schema_prop): """Creates a wtforms.FieldList for attachments.""" diff --git a/src/styles/blog.sass b/src/styles/blog.sass index 05fc1ec3..916d0399 100644 --- a/src/styles/blog.sass +++ b/src/styles/blog.sass @@ -16,6 +16,9 @@ top: 15px bottom: 15px + video + max-width: 100% + #blog_post-edit-form padding: 20px diff --git a/src/templates/nodes/attachments/file_video.pug b/src/templates/nodes/attachments/file_video.pug new file mode 100644 index 00000000..8b0a06af --- /dev/null +++ b/src/templates/nodes/attachments/file_video.pug @@ -0,0 +1,11 @@ +| {% if 'link' in attachment and attachment['link'] != 'none' %} +| {% if attachment['link'] == 'self' %} +video(src="{{ var.link }}", alt="{{ file.filename }}", controls) +a.attachment(href="{{ file.link }}") {{ file.filename }} +| {% elif attachment['link'] == 'custom' %} +video(src="{{ var.link }}", alt="{{ file.filename }}", controls) +a.attachment(href="{{ attachment['link_custom'] }}") Learn more about this video +| {% endif %} +| {% else %} +video(src="{{ var.link }}", alt="{{ file.filename }}", controls) +| {% endif %}