def getImage(self, **kwargs):
     """ Returns a random image (catalog brain)
     """
     provider = IImages(self.context)
     images = provider.getImages(**kwargs)
     if not len(images):
         return None
     return images[random.randint(0, len(images) - 1)]
Esempio n. 2
0
 def images(self):
     items = []
     provider = IImages(self.context)
     images = provider.getImages(component=self.component)
     for image in images:
         obj = image.getObject()
         img = IImage(obj)
         item = {'caption': img.getCaption(),
                 'img': img.getImageURL(self.img_size),}
         items.append(item)
     return items
 def get_visible_images(self):
     """If user can manage images then display all images. otherwise display
     only images that are marked as 'show'."""
     images = IImages(self.context)
     mship = getToolByName(self.context, 'portal_membership')
     if mship.checkPermission(MANAGE_PERMISSION, self.context):
         # return images directly contained in this Article
         return images.getImages()
     else:
         # return images directly contained in this Article (self.context)
         # but filter out those that don't have this component (self.component)
         # in their 'component' field -> this meands that the Image is hidden
         # for this component
         return images.getImages(component=self.component)
 def images(self):
     provider = IImages(self.context)
     manageable = interfaces.IManageable(self.context)
     mship = getToolByName(self.context, 'portal_membership')
     if interfaces.IArticleEditView.providedBy(self.view) and mship.checkPermission(MANAGE_PERMISSION, self.context):
         items = provider.getImages()
     else:
         items = provider.getImages(component=self.component)
     items = manageable.getList(items, self.component)
     for item in items:
         img = IImage(item['obj'])
         item.update({'caption': img.getCaption(),
                      'img': img.getImage(self.thumb_size),
                      'url': img.getImageURL(self.img_size),
                      'class': item.has_key('show') and item['show'] and 'hidden' or ''})
     return items
Esempio n. 5
0
 def images(self):
     provider = IImages(self.context)
     manageable = interfaces.IManageable(self.context)
     mship = getToolByName(self.context, 'portal_membership')
     if mship.checkPermission(MANAGE_PERMISSION, self.context):
         items = provider.getImages()
     else:
         items = provider.getImages(component=self.component)
     items = manageable.getList(items, self.component)
     for item in items:
         img = IImage(item['obj'])
         item.update({'title': img.getCaption(),
                      'img': img.getImageURL(self.thumb_size),
                      'description': item['brain'].Description,
                      'class': self.css_class})
         if item.has_key('show') and item['show']:
             item['class'] += ' hidden'
     return items
    def images(self):
        provider = IImages(self.context)
        manageable = interfaces.IManageable(self.context)
        mship = getToolByName(self.context, 'portal_membership')
        canManage = interfaces.IArticleEditView.providedBy(self.view) and mship.checkPermission(MANAGE_PERMISSION, self.context)
        if canManage:
            items = provider.getImages()
        else:
            items = provider.getImages(component=self.component)

        items = manageable.getList(items, self.component)
        i = 0
        l = len(items)
        relAttribute = self._getProperty('gallery_rel_attribute','lightbox')

        for item in items:
            img = IImage(item['obj'])
            item.update({'caption': img.getCaption(),
                         'class': self._class(item['brain'], i, l),
                         'img': img.getImage(self.thumb_size),
                         'description': item['brain'].Description,
                         'rel': None,
                         'url': None,
                         'viewUrl': None})
            if item.has_key('show') and item['show']:
                item['class'] += ' hidden'
            if (self.maxItems and i>=self.maxItems) and not canManage:
                item['class'] += ' invisible'
            w, h = item['obj'].getSize()
            tw, th = img.getSize(self.thumb_size)
            if (tw < w and tw > 0) or (th < h and th > 0):
                item['rel'] = '%s[%s]' % (relAttribute, self.css_class)
                item['url'] = img.getImageURL(size="popup")
                item['viewUrl'] = item['obj'].absolute_url()+ '/view'
            i += 1
        return items