Source code for ciowarehouse.handlers.handler_video
"""A file handler for videos."""
from os.path import join
from chrysalio.helpers.literal import Literal
from ..lib.i18n import _
from ..lib.handler import Handler
# =============================================================================
[docs]def includeme(configurator):
"""Function to include CioWarehouse a handler.
:type configurator: pyramid.config.Configurator
:param configurator:
Object used to do configuration declaration within the application.
"""
Handler.register(configurator, HandlerVideo)
# =============================================================================
[docs]class HandlerVideo(Handler):
"""Class to manage an video."""
uid = 'video'
label = _('Generic video file handling')
extensions = ('.mp4', '.webm', '.ogv')
viewings = (
{'name': 'default', 'label': _('Default'),
'template': 'ciowarehouse:Templates/handler_layout_view.pt',
'css': ('/ciowarehouse/css/handler_video.css',)},)
# -------------------------------------------------------------------------
[docs] def view(self, request, warehouse, content=None, ts_factory=None):
"""Return a string containing HTML to display the file.
See: :meth:`.lib.handler.Handler.view`
"""
content = '<div class="cioVideo"><video controls="">'\
'<source src="{0}"/><span>{1}</span></video></div>'.format(
request.route_path(
'file_download', warehouse_id=warehouse.uid,
path=join(*request.matchdict['path'])),
request.localizer.translate(
_('Your browser does not support HTML5 video.')))
return self._chameleon_render(
request, warehouse, self.viewings[0], ts_factory or _,
{'content': Literal(content)})