Commits

Tino de Bruijn committed 918fe31

Initial, working, commit of cmsplugin-vimeo

  • Participants

Comments (0)

Files changed (10)

+syntax: glob
+
+*.pyc

cmsplugin_vimeo/MANIFEST.in

+include README
+include MANIFEST.in
+recursive-include cmsplugin_vimeo/templates *

cmsplugin_vimeo/README.rst

+=============================================
+django-cms plugin for embedding Vimeo video's
+=============================================
+
+Requirements
+============
+
+As it's a plugin for django-cms, you will need both ``django`` and ``django-cms``. You probably need ``django-cms>=2.0.2``.
+
+Install
+=======
+
+Download and run ``python setup.py install``.
+
+Settings
+========
+
+All settings are defaults. They can be overriden in the plugin adding form in 
+the cms. All settings default to the Vimeo defaults.
+
+CMS_VIMEO_DEFAULT_WIDTH
+    Sets the default width of the iframe. Defaults to: ``400``
+CMS_VIMEO_DEFAULT_HEIGHT
+    Sets the default height of the iframe. Defaults to: ``225``
+CMS_VIMEO_DEFAULT_AUTOPLAY
+    Wether a video should auto start on. Defaults to: ``False``
+CMS_VIMEO_DEFAULT_LOOP
+    Wether a video should loop. Defaults to: ``False``
+CMS_VIMEO_DEFAULT_SHOW_TITLE
+    Wether the title of the video should be shown (is only in the beginning). 
+    Defaults to: ``True``
+CMS_VIMEO_DEFAULT_SHOW_BYLINE
+    Wether the byline of the video should be shown (is only in the beginning). 
+    Defaults to: ``True``
+CMS_VIMEO_DEFAULT_SHOW_PORTRAIT
+    Wether the author icon of the video should be shown (is only in the 
+    beginning). Defaults to: ``True``

cmsplugin_vimeo/__init__.py

Empty file added.

cmsplugin_vimeo/cms_plugins.py

+from cms.plugin_base import CMSPluginBase
+from cms.plugin_pool import plugin_pool
+
+from cmsplugin_vimeo.models import Vimeo
+
+from django.utils.translation import ugettext as _
+
+class VimeoPlugin(CMSPluginBase):
+    model = Vimeo
+    name = _("Vimeo")
+    render_template = "cmsplugin_vimeo/embed.html"
+
+    def render(self, context, instance, placeholder):
+        context.update({
+            'object': instance,
+            'placeholder': placeholder
+        })
+        return context
+
+plugin_pool.register_plugin(VimeoPlugin)

cmsplugin_vimeo/models.py

+from django.db import models
+from django.utils.translation import ugettext as _
+from cms.models import CMSPlugin
+import settings
+
+class Vimeo(CMSPlugin):
+    video_id = models.PositiveIntegerField(_('Video id'), 
+        help_text=_('The video id is the number you see in the URL. e.g http://vimeo.com/17808185'),
+        max_length=60)
+    width = models.IntegerField(_('Width'), default=settings.CMS_VIMEO_DEFAULT_WIDTH)
+    height = models.IntegerField(_('Height'), default=settings.CMS_VIMEO_DEFAULT_HEIGHT)
+    autoplay = models.BooleanField(_('Autoplay'), default=settings.CMS_VIMEO_DEFAULT_AUTOPLAY)
+    loop = models.BooleanField(_('Loop'), default=settings.CMS_VIMEO_DEFAULT_LOOP)
+    show_title = models.BooleanField(default=settings.CMS_VIMEO_DEFAULT_SHOW_TITLE,
+        help_text=_('Whether to show the (clickable) title in the beginning of the movie'))
+    show_portrait = models.BooleanField(default=settings.CMS_VIMEO_DEFAULT_SHOW_PORTRAIT,
+        help_text=_('Whether to show the authors icon in the beginning of the movie'))
+    show_byline = models.BooleanField(default=settings.CMS_VIMEO_DEFAULT_SHOW_BYLINE,
+        help_text=_('Whether to show the authors name in the beginning of the movie'))
+
+    def __unicode__(self):
+        return u'<a href="http://vimeo.com/%s">http://vimeo.com/%s</a>' % (self.video_id, self.video_id)
+    __unicode__.allow_tags = True
+    
+    @property
+    def src(self):
+        return ("http://player.vimeo.com/video/%(video_id)d"
+            "?byline=%(show_byline)d"
+            "&portrait=%(show_portrait)d"
+            "&title=%(show_title)d"
+            "&autoplay=%(autoplay)d"
+            "&loop=%(loop)d") % self.__dict__

cmsplugin_vimeo/settings.py

+from django.conf import settings
+
+CMS_VIMEO_DEFAULT_WIDTH = getattr(settings, 'CMS_VIMEO_DEFAULT_WIDTH', 400)
+CMS_VIMEO_DEFAULT_HEIGHT = getattr(settings, 'CMS_VIMEO_DEFAULT_HEIGHT', 225)
+CMS_VIMEO_DEFAULT_AUTOPLAY = getattr(settings, 'CMS_VIMEO_DEFAULT_AUTOPLAY', False)
+CMS_VIMEO_DEFAULT_LOOP = getattr(settings, 'CMS_VIMEO_DEFAULT_LOOP', False)
+CMS_VIMEO_DEFAULT_SHOW_TITLE = getattr(settings, 'CMS_VIMEO_DEFAULT_SHOW_TITLE', True)
+CMS_VIMEO_DEFAULT_SHOW_PORTRAIT = getattr(settings, 'CMS_VIMEO_DEFAULT_SHOW_PORTRAIT', True)
+CMS_VIMEO_DEFAULT_SHOW_BYLINE = getattr(settings, 'CMS_VIMEO_DEFAULT_SHOW_BYLINE', True)

cmsplugin_vimeo/templates/cmsplugin_vimeo/embed.html

+<iframe 
+    src="{{ object.src }}" 
+    width="{{ object.width }}" 
+    height="{{ object.heigth }}" 
+    frameborder="0">
+</iframe>

cmsplugin_vimeo/tests.py

+"""
+Tests for the VimeoPlugin
+"""
+
+from django.test import TestCase
+from models import Vimeo
+
+class SimpleTest(TestCase):
+    def setUp(self):
+        self.video = Vimeo(video_id=17808185)
+        
+    def test_src(self):
+        """
+        Tests the src attribute is correct with default settings.
+        """
+        self.failUnlessEqual(self.video.src, ("http://player.vimeo.com/video/17808185"
+                                                "?byline=1"
+                                                "&portrait=1"
+                                                "&title=1"
+                                                "&autoplay=0"
+                                                "&loop=0"))
+
+
+from distutils.core import setup
+
+setup(
+    name='cmsplugin-vimeo',
+    version='0.1',
+    description="Plugin for embedding Vimeo video's in django-cms",
+    author='Tino de Bruijn',
+    author_email='tinodb@gmail.com',
+    url='http://bitbucket.org/tino/cmsplugin-vimeo/',
+    packages=['cmsplugin_vimeo'],
+    zip_safe=False,
+)