Thursday, April 21, 2011

Singing & Dancing User Manual

This is a very brief post about the User Manual for Singing & Dancing, the newsletter product for Plone, being available on our WebTide website.

The manual can be found at: http://www.webtide.co.za/how-to/singing-dancing-user-manual

The purpose of this post is to create an easy, central discussion about any changes that you would like to see made to the manual. Feel free to make any comments below.

Wednesday, April 13, 2011

How to adapt your product to collective.flowplayer

I've been struggling to adapt an existing product to collective.flowplayer, so I decided to write a how-to on what I've achieved. collective.flowplayer makes use of adapters and because the are the 'Zope 3 way' and I've never used them before, I thought this is an opportune time for me to get a handle on them.

The product I'm working on has file and folder content types defined for it's own purpose. I would like to adapt these two content types to collective.flowplayer to render video and audio files.

I have one content type for a file (FTFile) and one for a folder (FTFolder).  FTFile does not inherit from ATFile, so I added the IFileContent interface:

  <five:implements
      class="Products.freedomtoaster.Content.FTFile.FTFile"
      interface="Products.ATContentTypes.interface.IFileContent"
      />


I added Video and Audio adaptors to FTFile:
  <adapter
    for="Products.freedomtoaster.Content.interfaces.IFTFile"
    provides="collective.flowplayer.interfaces.IVideo"
    factory="collective.flowplayer.media.VideoInfoAdapter"
  />
  <adapter
    for="Products.freedomtoaster.Content.interfaces.IFTFile"
    provides="collective.flowplayer.interfaces.IAudio"
    factory="collective.flowplayer.media.AudioInfo"
  />


and subscribers:
  <subscriber
      for="Products.freedomtoaster.Content.interfaces.IFTFile
           Products.Archetypes.interfaces.IObjectInitializedEvent"
      handler="collective.flowplayer.events.ChangeFileView"
  />
  <subscriber
      for="Products.freedomtoaster.Content.interfaces.IFTFile
           Products.Archetypes.interfaces.IObjectEditedEvent"
      handler="collective.flowplayer.events.ChangeFileView"
  />


I also had to drop to lower case the 'File' field on the FTFile schema.

An this is where I things got messy. FTFile has it's our browser view template that is rendered within a custom main_template that uses JQuery to layout the folders and files in columns.  I therefore had to change the following in the FTFile browser view class:
  • added a method 'href' that returns the url + '/at_download/file'
  • added a mehtod 'getEmbedCode' that returns the html for flowplayer, modified to autostart and not show controls
In the FTFile template, I used the 2 methods above to render the flowplayer object based on file.pt in collective.flowplayer

And somehow it works. On reflection, I am now of the opinion that my life would have been easier if I refactored FTFile to adapt to ATFile first.