[Erp5-report] r42907 rafael - /erp5/trunk/products/ERP5Form/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Feb 1 20:16:37 CET 2011
Author: rafael
Date: Tue Feb 1 20:16:37 2011
New Revision: 42907
URL: http://svn.erp5.org?rev=42907&view=rev
Log:
Add draft experimental Video and Audio fields. Initially, only supports HTML5 for now.
This code is a contribution from Gabriel Lima (NSI/IFF/Campos).
Added:
erp5/trunk/products/ERP5Form/AudioField.py
erp5/trunk/products/ERP5Form/VideoField.py
erp5/trunk/products/ERP5Form/testAudioField.py
erp5/trunk/products/ERP5Form/testVideoField.py
Modified:
erp5/trunk/products/ERP5Form/__init__.py
Added: erp5/trunk/products/ERP5Form/AudioField.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/AudioField.py?rev=42907&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Form/AudioField.py (added)
+++ erp5/trunk/products/ERP5Form/AudioField.py [utf8] Tue Feb 1 20:16:37 2011
@@ -0,0 +1,73 @@
+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
+
Added: erp5/trunk/products/ERP5Form/VideoField.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/VideoField.py?rev=42907&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Form/VideoField.py (added)
+++ erp5/trunk/products/ERP5Form/VideoField.py [utf8] Tue Feb 1 20:16:37 2011
@@ -0,0 +1,90 @@
+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
+
Modified: erp5/trunk/products/ERP5Form/__init__.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/__init__.py?rev=42907&r1=42906&r2=42907&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Form/__init__.py [utf8] (original)
+++ erp5/trunk/products/ERP5Form/__init__.py [utf8] Tue Feb 1 20:16:37 2011
@@ -156,6 +156,13 @@ def initialize( context ):
FieldRegistry.registerField(HyperLinkField.HyperLinkField,
'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
context.registerHelp()
# register field help for all fields
Added: erp5/trunk/products/ERP5Form/testAudioField.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/testAudioField.py?rev=42907&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Form/testAudioField.py (added)
+++ erp5/trunk/products/ERP5Form/testAudioField.py [utf8] Tue Feb 1 20:16:37 2011
@@ -0,0 +1,71 @@
+##############################################################################
+#
+# Copyright (c) 2011 Nexedi SARL and Contributors. All Rights Reserved.
+# Gabriel Lima <ciberglo at 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
+
Added: erp5/trunk/products/ERP5Form/testVideoField.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/testVideoField.py?rev=42907&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Form/testVideoField.py (added)
+++ erp5/trunk/products/ERP5Form/testVideoField.py [utf8] Tue Feb 1 20:16:37 2011
@@ -0,0 +1,73 @@
+##############################################################################
+#
+# Copyright (c) 2011 Nexedi SARL and Contributors. All Rights Reserved.
+# Gabriel Lima <ciberglo at 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
+
More information about the Erp5-report
mailing list