Пример #1
0
 def afterSetUp(self):
     data = getFile('image.gif').read()
     item = DummyContent()
     item.image = NamedImage(data, 'image/gif', u'image.gif')
     self.app._setOb('item', item)
     self.item = self.app.item
     self.scaling = ImageScaling(self.app.item, None)
Пример #2
0
 def setUp(self):
     data = getFile('image.png').read()
     item = DummyContent()
     item.image = NamedImage(data, 'image/png', u'image.png')
     self.layer['app']._setOb('item', item)
     self.item = self.layer['app'].item
     self.scaling = ImageScaling(self.item, None)
Пример #3
0
 def testCreateHighPixelDensityScaleWithoutData(self):
     item = DummyContent()
     scaling = ImageScaling(item, None)
     scaling.getHighPixelDensityScales = lambda: [{
         'scale': 2,
         'quality': 66
     }]
     foo = scaling.scale('image', width=100, height=80)
     self.assertFalse(hasattr(foo, 'srcset'))
 def logo(self):
     logo = self.getItems()
     if not logo:
         return None
     if getattr(logo, 'image_sizes', None):
         sizes = logo.image_sizes['base']
         return {
             'id':
             logo.getId,
             'content':
             '<img width="%s" height="%s" title="%s" alt="%s" src="%s"/>' %
             (str(sizes[0]), str(
                 sizes[1]), logo.Description, logo.Title, logo.getPath())
         }
     else:
         logo = logo.getObject()
         if has_dx and IImage.providedBy(logo):
             return {
                 'id':
                 logo.id,
                 'content':
                 ImageScaling(logo,
                              self.request).tag(title=logo.Description())
             }
         elif hasattr(logo, 'tag'):
             return {
                 'id': logo.id,
                 'content': logo.tag(title=logo.Description())
             }
         elif has_dx and IDocument.providedBy(logo):
             return {
                 'id': logo.id,
                 'content': logo.text and logo.text.raw or ''
             }
         elif hasattr(logo, 'getText'):
             return {'id': logo.id, 'content': logo.getText()}
         elif logo.portal_type == 'FlashMovie':
             return {
                 'id':
                 logo.id,
                 'content':
                 ObjectView(logo, self.request,
                            'flashmovie_macro_flashobject.pt')
             }
     return None
Пример #5
0
    def testScaledJpegImageQuality(self):
        """Test image quality setting for jpeg images.
        Image quality not available for PNG images.
        """
        data = getFile('image.jpg').read()
        item = DummyContent()
        item.image = NamedImage(data, 'image/png', u'image.jpg')
        scaling = ImageScaling(item, None)

        # scale an image, record its size
        foo = scaling.scale('image', width=100, height=80)
        size_foo = foo.data.getSize()
        # let's pretend p.a.imaging set the scaling quality to "really sloppy"
        gsm = getGlobalSiteManager()
        qualitySupplier = DummyQualitySupplier()
        gsm.registerUtility(qualitySupplier.getQuality, IScaledImageQuality)
        wait_to_ensure_modified()
        # now scale again
        bar = scaling.scale('image', width=100, height=80)
        size_bar = bar.data.getSize()
        # first one should be bigger
        self.assertTrue(size_foo > size_bar)
Пример #6
0
 def testCreateScaleWithoutData(self):
     item = DummyContent()
     scaling = ImageScaling(item, None)
     foo = scaling.scale('image', width=100, height=80)
     self.assertEqual(foo, None)
Пример #7
0
 def __new__(cls, context, request):
     parent = aq_parent(context)
     if IImageScaleTraversable.providedBy(parent):
         return ImageScaling(parent, request)
     return None
    def getSolgemaBandeaux(self):
        bandeaux = self.getItems()
        bandeauxList = []
        base_ajax_content_load = self.request.get('ajax_content_load')
        base_ajax_load = self.request.get('ajax_load')
        setattr(self.request, 'ajax_content_load', 1)
        setattr(self.request, 'ajax_load', 1)
        for bandeau in bandeaux:
            bdict = {}
            if getattr(bandeau, 'image_sizes', None):
                height = str(bandeau.image_sizes['base'][1])
                url = str(bandeau.getPath() + '/image')
                try:
                    title = str(bandeau.Description)
                except:
                    try:
                        title = str(bandeau.Description.encode('utf-8'))
                    except:
                        try:
                            title = str(bandeau.Description.decode('utf-8'))
                        except:
                            title = safe_unicode(bandeau.Description)
                if getattr(bandeau, 'bannerImageLink', ''):
                    link = str(self.context.absolute_url() + '/resolveuid/' +
                               bandeau.bannerImageLink)
                else:
                    link = None
                repeat = getattr(bandeau, 'backgroundRepeat', None)
                if not repeat:
                    repeat = 'no-repeat'
                repeat = str(repeat)
                align = getattr(bandeau, 'backgroundAlign', None)
                if not align:
                    align = 'left'
                align = str(align)
                cssClass = 'bandeau_image'
                cssStyle = 'position:relative;'
                if getattr(bandeau, 'backgroundExtend', False):
                    cssClass += ' backgroundExtend'
                if getattr(bandeau, 'backgroundFixed', False):
                    cssClass += ' backgroundFixed'
                if len(bandeauxList) == 0:
                    cssClass += ' ' + bandeau.id.replace(
                        '.', '_') + ' carousel-banner-content selected'
                    cssStyle += ' display:block;'
                else:
                    cssClass += ' ' + bandeau.id.replace(
                        '.', '_') + ' carousel-banner-content'
                    cssStyle += ' display:none;'

                if link:
                    backgrounddiv = '<a style="display:block; height:%spx; width:100%%; background:transparent url(%s) %s %s top;" title="%s" class="%s" href="%s"></a>' % (
                        height, url, repeat, align, title, cssClass, link)
                else:
                    backgrounddiv = '<div style="height:%spx; width:100%%; background:transparent url(%s) %s %s top;" title="%s" class="%s"></div>' % (
                        height, url, repeat, align, title, cssClass)


#                bandeauxList.append({'id':bandeau.id, 'content':bandeau.tag(title=bandeau.Description())})
                bdict = {
                    'id': bandeau.id,
                    'content': backgrounddiv,
                    'cssClass': cssClass,
                    'cssStyle': cssStyle,
                    'url': url,
                    'link': link,
                    'align': align,
                    'repeat': repeat
                }
            else:
                bandeau = bandeau.getObject()
                if (has_dx and IImage.providedBy(bandeau)) or hasattr(
                        bandeau, 'tag'):
                    if hasattr(bandeau, 'getHeight'):
                        height = bandeau.getHeight()
                    else:
                        height = ImageScaling(bandeau,
                                              self.request).scale().height
                    if has_dx and IImage.providedBy(bandeau):
                        url = bandeau.absolute_url()
                    else:
                        url = str(bandeau.absolute_url() + '/image')
                    title = bandeau.title
                    bkg = IBackgroundContent(bandeau, None)
                    repeat = getattr(bkg, 'backgroundRepeat', None)
                    if not repeat:
                        repeat = 'no-repeat'
                    align = getattr(bkg, 'backgroundAlign', None)
                    if not align:
                        align = 'left'
                    align = str(align)
                    cssClass = 'bandeau_image'
                    cssStyle = 'position:relative;'
                    if getattr(bkg, 'backgroundExtend', False):
                        cssClass += ' backgroundExtend'
                    if getattr(bkg, 'backgroundFixed', False):
                        cssClass += ' backgroundFixed'
                    if len(bandeauxList) == 0:
                        cssClass += ' ' + bandeau.id.replace(
                            '.', '_') + ' carousel-banner-content selected'
                        cssStyle += ' display:block;'
                    else:
                        cssClass += ' ' + bandeau.id.replace(
                            '.', '_') + ' carousel-banner-content'
                        cssStyle += ' display:none;'

                    if getattr(bkg, 'bannerImageLink', ''):
                        link = str(self.context.absolute_url() +
                                   '/resolveuid/' + bkg.bannerImageLink)
                    else:
                        link = None
                    if link:
                        backgrounddiv = '<a style="display:block; height:%spx; width:100%%; background:transparent url(%s) %s %s top;" title="%s" class="%s" href="%s"></a>' % (
                            height, url, repeat, align, title, cssClass, link)
                    else:
                        backgrounddiv = '<div style="height:%spx; width:100%%; background:transparent url(%s) %s %s top;" title="%s" class="%s"></div>' % (
                            height, url, repeat, align, title, cssClass)
                    bdict = {
                        'id': bandeau.id,
                        'content': backgrounddiv,
                        'cssClass': cssClass,
                        'cssStyle': cssStyle,
                        'url': url,
                        'link': link,
                        'align': align,
                        'repeat': repeat
                    }
                elif has_dx and IDocument.providedBy(bandeau):
                    bdict['id'] = bandeau.id
                    bdict['content'] = bandeau.text and bandeau.text.raw or ''
                elif hasattr(bandeau,
                             'getText') and not bandeau.portal_type in [
                                 'Topic', 'Collection'
                             ]:
                    try:
                        bdict['id'] = bandeau.id
                        bdict['content'] = bandeau.getText()
                    except:
                        raise ValueError('error with: ' + str(bandeau))
                elif bandeau.portal_type == 'Collage':
                    bdict['id'] = bandeau.id
                    bdict['content'] = ObjectView(bandeau, self.request,
                                                  'collage_renderer.pt')
                elif bandeau.portal_type == 'FlashMovie':
                    bdict['id'] = bandeau.id
                    bdict['content'] = ObjectView(
                        bandeau, self.request,
                        'flashmovie_macro_flashobject.pt')
                elif bandeau.portal_type == 'Folder':
                    bdict['id'] = bandeau.id
                    bdict['content'] = ObjectView(bandeau, self.request,
                                                  'folder_renderer.pt')
                else:
                    bdict['id'] = bandeau.id
                    bdict['content'] = bandeau()
            bandeauxList.append(bdict)
        if not base_ajax_content_load:
            delattr(self.request, 'ajax_content_load')
        if not base_ajax_load:
            delattr(self.request, 'ajax_load')
        return bandeauxList