def migrate_sl_image_layout(old_object, new_object): block_layout_mapping = { 'small': { 'scale': 'sl_textblock_small', 'imagefloat': 'left'}, 'middle': { 'scale': 'sl_textblock_middle', 'imagefloat': 'left'}, 'full': { 'scale': 'sl_textblock_large', 'imagefloat': 'no-float'}, 'middle-right': { 'scale': 'sl_textblock_middle', 'imagefloat': 'right'}, 'small-right': { 'scale': 'sl_textblock_small', 'imagefloat': 'right'}, 'no-image': { 'scale': 'sl_textblock_small', 'imagefloat': 'left'}, } old_config = IBlockConfig(old_object) image_layout = old_config.get_image_layout() if not image_layout or image_layout == 'dummy-dummy-dummy': return new_config = IBlockConfiguration(new_object) cfg = new_config.load() cfg.update(block_layout_mapping[image_layout]) new_config.store(cfg)
def test_textblock_modified(self): contentpage = create(Builder('sl content page').titled(u'A page')) block = create(Builder('sl textblock').within(contentpage)) data = {'scale': 'mini'} modifier = getMultiAdapter((block, block.REQUEST), IBlockModifier) modifier.modify(data) conf = IBlockConfiguration(block).load() self.assertEquals('mini', conf.get('scale'))
def test_textblock_modified(self): contentpage = create(Builder("sl content page").titled(u"A page")) block = create(Builder("sl textblock").within(contentpage)) data = {"scale": "mini"} modifier = getMultiAdapter((block, block.REQUEST), IBlockModifier) modifier.modify(data) conf = IBlockConfiguration(block).load() self.assertEquals("mini", conf.get("scale"))
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 modify(self, data): image_scale = data.get('scale', None) image_float = data.get('imagefloat', None) conf = IBlockConfiguration(self.context) blockconf = conf.load() if image_scale: blockconf['scale'] = image_scale blockconf['imagefloat'] = image_float conf.store(blockconf) # necessary? return
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 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())
def test_config_is_recursive_persistent(self): config = IBlockConfiguration(create(Builder('sample block'))) config.store({'scale': 'mini'}) self.assert_recursive_persistence(config.load())
def setData(self, data, metadata): IBlockConfiguration(self.context).store(data)
def getData(self): return unwrap_persistence(IBlockConfiguration(self.context).load())
def test_config_is_recursive_persistent(self): config = IBlockConfiguration(create(Builder("sample block"))) config.store({"scale": "mini"}) self.assert_recursive_persistence(config.load())