Example #1
0
    def thumbnail(self, context=None, size='thumbnail'):
        if not context:
            context = self.context

        for key, doc in context.items():
            if not IImage.providedBy(doc):
                continue

            scale = getMultiAdapter((doc, self.request), name=u'scale')
            thumb = scale.publishTraverse(self.request, size)
            if thumb.getSize():
                return zapi.absoluteURL(doc, self.request)
        return ''
Example #2
0
    def thumbnail(self, context=None, size='thumbnail', from_parent=False):
        if not context:
            context = self.context

        for key, doc in context.items():
            if key == 'icon.png':
                continue
            if not IImage.providedBy(doc):
                continue

            scale = getMultiAdapter((doc, self.request), name=u'scale')
            try:
                thumb = scale.publishTraverse(self.request, size)
            except Exception, err:
                thumb = ''
            if thumb and thumb.getSize():
                return zapi.absoluteURL(doc, self.request)
Example #3
0
    def _cleanup(self, **kwargs):
        """ Cleanup thumbs
        """
        index = 0
        now = datetime.now(bucharest)
        logger.info('cleanup old images started ...')
        geQuery = Le('stiam.ro.effective', now)
        query = SearchQuery(geQuery)
        brains = query.apply()

        intids = queryUtility(IIntIds)
        if not intids:
            logger.warn('No intids utility. Cleanup aborted.')
            return index

        for docid in brains:
            try:
                doc = intids.getObject(docid)
            except KeyError, err:
                logger.exception(err)
                continue

            for image in doc.values():
                if not IImage.providedBy(image):
                    continue

                if IBlobImage.providedBy(image):
                    continue

                try:
                    del doc[image.__name__]
                except Exception, err:
                    logger.exception(err)
                    continue

                index += 1
                # Transaction commit
                if index % 20 == 0:
                    logger.info('Commit transaction %s', index)
                    transaction.commit()