Esempio n. 1
0
def migrateActionsAndLayoutNames(portal_setup):
    portal_url = getToolByName(portal_setup, 'portal_url')
    portal = portal_url.getPortalObject()
    catalog = getToolByName(portal_setup, 'portal_catalog')
    query = {}
    query['portal_type'] = ['Image', 'Paragraph']
    results = catalog(query)
    for b in results:
        obj = aq_inner(b.getObject()).aq_explicit
        blockconf = IBlockConfig(obj)
        layout = blockconf.image_layout
        migrate_layout = {'half': 'middle',
                          'squarish': 'small',
                          'full': 'full',
                          'thumbnail': 'small',
                          '25': 'small',
                          '33': 'middle',
                          '50': 'full',
                          'no-image': 'no-image'}
        if layout and layout not in ['small', 'middle', 'full']:
            blockconf.image_layout = migrate_layout[layout]

    obsoleteactions = ['sl-25', 'sl-33', 'sl-50', 'sl-squarish']
    image_actions = portal.portal_types.Image._cloneActions()
    for a in image_actions:
        if a.id in obsoleteactions:
            image_actions.remove(a)
    portal.portal_types.Image._actions = image_actions

    return 'migration done'
Esempio n. 2
0
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)
Esempio n. 3
0
    def setDesignInterface(self, name, blocks=[]):
        """ sets the new view interface """

        context = self.context
        context_expl = aq_inner(self.context).aq_explicit

        if not blocks:
            #remove grid infos
            if hasattr(context_expl, 'align_to_grid'):
                context.manage_changeProperties({'align_to_grid': '0'})

            if name not in VIEW_INTERFACES_MAP:
                new = VIEW_INTERFACES_MAP['normal']
            else:
                new = VIEW_INTERFACES_MAP[name]
            #remove current design interface
            for iface in VIEW_INTERFACES_MAP.values():
                if iface.providedBy(context):
                    noLongerProvides(context, iface)
            #set the new one
            alsoProvides(context, new)
            context.reindexObject(idxs=['object_provides'])

        #set init interfaces on blocks
        ifaces = []
        if name in INIT_INTERFACES_MAP:
            ifaces = INIT_INTERFACES_MAP[name]

        contents = blocks and blocks or context.getFolderContents(
            {'object_provides': BLOCK_INTERFACES},
            full_objects=True)

        for obj in contents:
            #remove given block heights
            blockconf = IBlockConfig(obj)
            blockconf.block_height = None

            #remove all related Interfaces
            for i in COLUMN_INTERFACES_MAP.values() + \
                SLOT_INTERFACES_MAP.values():

                if i.providedBy(obj):
                    noLongerProvides(obj, i)

            for iface in ifaces:
                alsoProvides(obj, iface)
            obj.reindexObject(idxs=['object_provides'])

            #calc new images sizes and store them
            try:
                converter = getUtility(IBlockControl, name='block-layout')
            except ComponentLookupError:
                pass
            converter.update(context, obj, obj.REQUEST)

        if not blocks:
            return self.request.RESPONSE.redirect(context.absolute_url())
Esempio n. 4
0
 def __call__(self, uid=None, layout="", viewname=""):
     rc = getToolByName(self.context, 'reference_catalog')
     if uid and layout:
         uid = uid.replace('uid_', '')
         block = rc.lookupObject(uid)
         converter = getUtility(IBlockControl, name='block-layout')
         converter.update(self.context,
                          block,
                          self.request,
                          layout=layout,
                          viewname=viewname
                         )
         blockconfig = IBlockConfig(block)
         viewname = blockconfig.get_viewname()
         self.block_view = queryMultiAdapter(
             (block, self.request), name='block_view-%s' % viewname)
         #fallback
         if self.block_view is None:
             self.block_view = queryMultiAdapter((block, self.request),
                                                 name='block_view')
         return self.template()
Esempio n. 5
0
    def renderBlockProvider(self, context):
        #logger.info('sl viewlet renderer not cached')
        view = self
        block = context
        request = self.request

        blockconf = IBlockConfig(context)
        name = blockconf.viewlet_manager

        #Paragraph is our example, this content type has no ViewletManager
        #so it should use simplelayout.base.block
        default = 'block'
        prefix = 'simplelayout.base'
        #first time we have to generate the viewletManager name.
        #so we have the possibility to change the manager later.
        if name is None:

            #now build the viewletManager name from given prefix and
            #block.__class__.__name__ (ClassName)
            name = '%s.%s' % (prefix, block.__class__.__name__)
            blockconf.viewlet_manager = name

        provider = None
        counter = 0
        while provider is None and counter < 10:
            provider = zope.component.queryMultiAdapter(
                (block, request, view), cp_interfaces.IContentProvider, name)
            counter += 1
            if provider is None:
                name = '%s.%s' % (prefix, default)

        #if provider is still None
        if provider is None:
            return 'Something is wrong - pls debug'

        addTALNamespaceData(provider, block)
        provider.update()
        return provider.render()
Esempio n. 6
0
    def get_image_latex(self, floatable):
        image = self.context.getImage()

        if not image or image.get_size() == 0:
            return ''

        image_layout = IBlockConfig(self.context).image_layout
        caption = self.context.getImageCaption()
        generator = ImageLaTeXGenerator(self.context, self.layout)

        return generator(image,
                         image_layout,
                         floatable=floatable,
                         caption=caption)
Esempio n. 7
0
    def setBlockHeights(self, uids=[], left=[], right=[]):
        """
        usage: needs a list of uid, height pairs...
        if the uid of a block is missing, the height attribute of this
        block will be deleted
        """
        # XXX:
        # Don't understand, why the varname:list, will shown as
        # varname:list[]
        # I just make this work, but it needs to be fixed

        uids = self.request.get('uids:list[]', [])
        # In case if only one block is available
        if not isinstance(uids, list):
            uids = [uids]
        left = self.request.get('left:list[0][]', [])
        right = self.request.get('right:list[0][]', [])

        # create a dict
        _d = {}
        real_uids = [u.replace('uid_', '') for u in uids]

        if right or left:
            for uid, height in [right] + [left]:
                _d[uid.replace('uid_', '')] = height

        for uid in real_uids:
            block = self.context.reference_catalog.lookupObject(uid)
            blockconf = IBlockConfig(block)
            if uid in _d.keys():
                #set height
                blockconf.block_height = _d[uid]
            else:
                #remove heights
                blockconf.block_height = None
        return 1
Esempio n. 8
0
    def update(self, parent, block, request, **kwargs):
        self.block = block
        #we store everything in annotations
        blockconf = IBlockConfig(block)
        layout = kwargs.get('layout', '')
        viewname = kwargs.get('viewname', '')
        if not layout:
            layout = request.get('layout', '')

        fieldname = request.get('fieldname', '')

        if not fieldname:
            fieldname = 'image'
        
        #This allows us to change the view without changing the imagelayout.
        if layout != '' and layout != 'dummy-dummy':
            blockconf.image_layout = layout
        
        #This allows us to change the imagelayout without reseting the view.
        if viewname != '' and viewname != 'dummy':
            blockconf.viewname = viewname
        #This is a fallback for old actions which switch to the default view without defining a viewname.
        elif (layout == '' or layout == 'dummy-dummy') and (viewname != '' and viewname == 'dummy'):
            blockconf.viewname = 'block_view'
Esempio n. 9
0
 def render(self):
     image = self.context.getImage()
     image_layout = IBlockConfig(self.context).image_layout
     caption = self.context.Description()
     generator = ImageLaTeXGenerator(self.context, self.layout)
     return generator(image, image_layout, floatable=False, caption=caption)