Commit bf014849 authored by Rafael Monnerat's avatar Rafael Monnerat

Add draft experimental Video and Audio fields. Initially, only supports HTML5 for now.

This code is a contribution from Gabriel Lima (NSI/IFF/Campos).



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42907 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 53ac23cc
from Products.Formulator.Field import ZMIField
from Products.Formulator import Widget, Validator
from Products.Formulator.DummyField import fields
from Products.Formulator import Validator
class AudioWidget(Widget.TextWidget):
"""
A widget that displays a Audio HTML element.
This widget is intended to be used in
conjunction with WebSite.
"""
property_names = Widget.TextWidget.property_names + \
['audio_controls', 'audio_error_message', 'audio_loop', \
'audio_preload', 'audio_autoplay']
audio_controls = fields.StringField('audio_controls',
title='Audio Controls',
description=("Controls to be used in Audio Player."),
default='controls',
required=0)
audio_error_message = fields.StringField('audio_error_message',
title='Audio Error Message',
description=("Error message to be showed when \
user's browser does not support the audio tag."),
default='Your browser does not support audio tag.',
required=0)
audio_loop = fields.StringField('audio_loop',
title='Audio Loop',
description=("Specifies that the audio file \
will start over again, every time it is finished."),
default='none',
required=0)
audio_preload = fields.StringField('audio_preload',
title='Audio Preload',
description=("Configure that you would like to \
start downloading the audio file as soon as possible."),
default='preload',
required=0)
audio_autoplay = fields.StringField('audio_autoplay',
title='Audio Autoplay',
description=("Configure that you would like to \
start downloading and playing the audio file as soon as possible."),
default='',
required=0)
def render(self, field, key, value, REQUEST, render_prefix=None):
return self.render_view(field, value, REQUEST, render_prefix)
def render_view(self, field, value, REQUEST=None, render_prefix=None):
if value is None:
return ''
return Widget.render_element("audio",
src=value,
controls=field.get_value('audio_controls'),
loop=field.get_value('audio_loop'),
preload=field.get_value('audio_preload'),
autoplay=field.get_value('audio_autoplay'),
contents=field.get_value('audio_error_message'))
AudioWidgetInstance = AudioWidget()
class AudioField(ZMIField):
""" Audio field
"""
meta_type = "AudioField"
widget = AudioWidgetInstance
validator = Validator.SuppressValidatorInstance
from Products.Formulator.Field import ZMIField
from Products.Formulator import Widget, Validator
from Products.Formulator.DummyField import fields
from Products.Formulator import Validator
class VideoWidget(Widget.TextWidget):
"""
A widget that displays a Video HTML element.
This widget is intended to be used in
conjunction with WebSite.
"""
property_names = Widget.TextWidget.property_names + \
['video_controls', 'video_error_message', 'video_loop', \
'video_width', 'video_height', 'video_preload', \
'video_autoplay']
video_controls = fields.StringField('video_controls',
title='Video Controls',
description=("Controls to be used in Video Player."),
default='controls',
required=0)
video_error_message = fields.StringField('video_error_message',
title='Video Error Message',
description=("Error message to be showed when \
user's browser does not support the video tag."),
default='Your browser does not support video tag.',
required=0)
video_loop = fields.StringField('video_loop',
title='Video Loop',
description=("Specifies that the video file \
will start over again, every time it is finished."),
default='none',
required=0)
video_width = fields.IntegerField('video_width',
title='Video Width',
description=(
"The width to be used when playing the video."),
default=160,
required=0)
video_height = fields.IntegerField('video_height',
title='Video Height',
description=(
"The height to be used when playing the video."),
default=85,
required=0)
video_preload = fields.StringField('video_preload',
title='Video Preload',
description=("Configure that you would like to \
start downloading the video file as soon as possible."),
default='preload',
required=0)
video_autoplay = fields.StringField('video_autoplay',
title='Video Autoplay',
description=("Configure that you would like to \
start downloading and playing the video file as soon as possible."),
default='',
required=0)
def render(self, field, key, value, REQUEST, render_prefix=None):
return self.render_view(field, value, REQUEST, render_prefix)
def render_view(self, field, value, REQUEST=None, render_prefix=None):
if value is None:
return ''
return Widget.render_element("video",
src=value,
controls=field.get_value('video_controls'),
loop=field.get_value('video_loop'),
width=field.get_value('video_width'),
height=field.get_value('video_height'),
preload=field.get_value('video_preload'),
autoplay=field.get_value('video_autoplay'),
contents=field.get_value('video_error_message'))
VideoWidgetInstance = VideoWidget()
class VideoField(ZMIField):
""" Video field
"""
meta_type = "VideoField"
widget = VideoWidgetInstance
validator = Validator.SuppressValidatorInstance
...@@ -156,6 +156,13 @@ def initialize( context ): ...@@ -156,6 +156,13 @@ def initialize( context ):
FieldRegistry.registerField(HyperLinkField.HyperLinkField, FieldRegistry.registerField(HyperLinkField.HyperLinkField,
'www/LinkField.gif') 'www/LinkField.gif')
import VideoField
FieldRegistry.registerField(VideoField.VideoField,
'www/StringField.gif')
import AudioField
FieldRegistry.registerField(AudioField.AudioField,
'www/StringField.gif')
# register help for the product # register help for the product
context.registerHelp() context.registerHelp()
# register field help for all fields # register field help for all fields
......
##############################################################################
#
# Copyright (c) 2011 Nexedi SARL and Contributors. All Rights Reserved.
# Gabriel Lima <ciberglo@gmail.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Form.AudioField import AudioField
from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.Globals import get_request
from StringIO import StringIO
from DateTime import DateTime
class TestAudioField(ERP5TypeTestCase):
"""Tests Audio field
"""
def getTitle(self):
return "Audio Field"
def afterSetUp(self):
self.field = AudioField('test_field')
self.widget = self.field.widget
def test_render_view(self):
self.field.values['default'] = 'Audio content'
self.assertEquals('<audio preload="preload" src="Audio content" ' +
'loop="none" controls="controls" autoplay="" >\nYour browser does not ' +
'support audio tag.</audio>', self.field.render_view(value='Audio content'))
self.field.values['audio_preload'] = 'none'
self.field.values['audio_loop'] = 'True'
self.field.values['audio_controls'] = 'none'
self.field.values['audio_autoplay'] = 'autoplay'
self.field.values['audio_error_message'] = 'Another error message'
self.assertEquals('<audio preload="none" src="Another Audio content" ' +
'loop="True" controls="none" autoplay="autoplay" >\nAnother error ' +
'message</audio>', self.field.render_view(value='Another Audio content'))
import unittest
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestAudioField))
return suite
##############################################################################
#
# Copyright (c) 2011 Nexedi SARL and Contributors. All Rights Reserved.
# Gabriel Lima <ciberglo@gmail.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Form.VideoField import VideoField
from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.Globals import get_request
from StringIO import StringIO
from DateTime import DateTime
class TestVideoField(ERP5TypeTestCase):
"""Tests Video field
"""
def getTitle(self):
return "Video Field"
def afterSetUp(self):
self.field = VideoField('test_field')
self.widget = self.field.widget
def test_render_view(self):
self.field.values['default'] = 'Video content'
self.assertEquals('<video preload="preload" src="Video content" controls="controls" height="85" width="160" loop="none" autoplay="" >\nYour browser does not support video tag.</video>', \
self.field.render_view(value='Video content'))
self.field.values['video_preload'] = 'none'
self.field.values['video_loop'] = 'True'
self.field.values['video_controls'] = 'none'
self.field.values['video_autoplay'] = 'autoplay'
self.field.values['video_error_message'] = 'Another error message'
self.field.values['video_height'] = 800
self.field.values['video_width'] = 1280
self.assertEquals('<video preload="none" src="Another Video content" ' +
'controls="none" height="800" width="1280" loop="True" autoplay="autoplay" ' +
'>\nAnother error message</video>', \
self.field.render_view(value='Another Video content'))
import unittest
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestVideoField))
return suite
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