Centrally settings Products.Carousel image widths in Plone

Another example to manipulate Products.Carousel. This script will update all carousel settings on the site to have new image width.. 

class SetCarouselWidths(BrowserView):
    """
    Set width to all carousels on the site.
    """

    def __call__(self):
        """

        """

        self.buffer = StringIO()

        print >> self.buffer, "Log output"

        brains = self.context.portal_catalog(portal_type="Folder")
        for b in brains:
            obj = b.getObject()
            if "carousel" in obj.objectIds():
                carousel = obj["carousel"]
                # Carousel installed on this folder
                settings = ICarouselSettings(carousel)
                print >> self.buffer, "Setting width for " + carousel.absolute_url()
                settings.width = 680

        print >> self.buffer, "All carousels updated"

        return self.buffer.getvalue()

ZCML:

<browser:page
  for="*"
  name="set_carousel_widths"
  permission="cmf.ManagePortal"
  class=".carousel.SetCarouselWidths"
  />

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+

Leave a Reply

Your email address will not be published. Required fields are marked *