def test_data_setter(self):
     page = create(Builder('sl content page').titled(u'The Page'))
     block = create(
         Builder('sl textblock').titled(u'The Block').within(page))
     component = getAdapter(
         block,
         IDataCollector,
         name='ftw.simplelayout:SimplelayoutBlockAnnotations')
     component.setData({'scale': 'sl_textblock_small'}, {})
     self.assertEquals({'scale': 'sl_textblock_small'},
                       IBlockConfiguration(block).load())
示例#2
0
    def create_block(self, portlet, manager, type_):

        config = IPageConfiguration(self.new)
        normalizer = getUtility(IFileNameNormalizer).normalize
        if type_ == 'teaser':
            block = create(
                Builder('sl textblock').within(self.new).titled(
                    portlet.teasertitle).having(
                        text=RichTextValue(portlet.teaserdesc),
                        image=NamedBlobImage(filename=normalizer(
                            portlet.image.filename).decode('utf-8'),
                                             data=portlet.image.data)))

            blockconfig = IBlockConfiguration(block)
            blockconfigdata = blockconfig.load()
            blockconfigdata['scale'] = 'large'
            blockconfigdata['imagefloat'] = 'no-float'
            blockconfig.store(blockconfigdata)

            if portlet.internal_target:
                teaser = ITeaser(block)
                target = uuidToObject(portlet.internal_target)
                if target:
                    intids = getUtility(IIntIds)
                    teaser.internal_link = RelationValue(intids.getId(target))

        elif type_ == 'static':
            block = create(
                Builder('sl textblock').within(self.new).titled(
                    portlet.header).having(text=RichTextValue(portlet.text)))
        else:
            return

        uid = IUUID(block)

        page_state = config.load()
        if manager == 'ftw.subsite.front1':
            page_state['default'][0]['cols'][0]['blocks'].append({'uid': uid})
        elif manager == 'ftw.subsite.front2':
            page_state['default'][0]['cols'][1]['blocks'].append({'uid': uid})
        elif manager == 'ftw.subsite.front3':
            page_state['default'][0]['cols'][2]['blocks'].append({'uid': uid})
        elif manager == 'ftw.subsite.front4':
            page_state['default'][0]['cols'][3]['blocks'].append({'uid': uid})
        elif manager == 'ftw.subsite.front5':
            page_state['default'][1]['cols'][0]['blocks'].append({'uid': uid})
        elif manager == 'ftw.subsite.front6':
            page_state['default'][1]['cols'][1]['blocks'].append({'uid': uid})
        # Don't know where manager 7 belongs
        elif manager == 'ftw.subsite.front7':
            page_state['default'][1]['cols'][0]['blocks'].append({'uid': uid})

        config.store(page_state)
 def setData(self, data, metadata):
     IBlockConfiguration(self.context).store(data)
 def getData(self):
     return unwrap_persistence(IBlockConfiguration(self.context).load())