Beispiel #1
0
def get_content_links(obj):
    refs = set()
    if ILayoutAware.providedBy(obj):
        behavior_data = ILayoutAware(obj)
        # get data from tile data
        annotations = IAnnotations(obj)
        for key in annotations.keys():
            if key.startswith(ANNOTATIONS_KEY_PREFIX):
                data = annotations[key]
                refs |= get_tile_data_links(obj, data)
        if not behavior_data.contentLayout and behavior_data.content:
            dom = fromstring(behavior_data.content)
            for el in dom.cssselect('.mosaic-text-tile .mosaic-tile-content'):
                links = extractLinks(tostring(el))
                refs |= li.getObjectsFromLinks(obj, links)
    try:
        # scan more than just this we probably should...
        value = obj.text.raw
        links = extractLinks(value)
        refs |= li.getObjectsFromLinks(obj, links)
    except AttributeError:
        pass

    if getattr(obj, 'image'):
        if IReferenceNamedImage.providedBy(obj.image):
            sub_obj = uuidToObject(obj.image.reference)
            if sub_obj:
                objid = get_ref(obj)
                if objid:
                    refs.add(RelationValue(objid))
    return refs
Beispiel #2
0
 def is_deco_enabled(self):
     try:
         from plone.app.blocks.layoutbehavior import ILayoutAware
         if ILayoutAware.providedBy(self.context):
             return True
     except:
         pass
     return False
Beispiel #3
0
 def is_deco_enabled(self):
     try:
         from plone.app.blocks.layoutbehavior import ILayoutAware
         if ILayoutAware.providedBy(self.context):
             return True
     except:
         pass
     return False
Beispiel #4
0
    def add_body_classes(self,
                         original_context,
                         context,
                         request,
                         tree,
                         result,
                         raw=False):
        '''
        Dynamically add useful body classes for theming and JS.
        '''
        body_classes = ''
        if raw:
            # this is a content layout likely
            plone_layout = queryMultiAdapter((original_context, request),
                                             name='plone_layout')
            if plone_layout:
                body_classes += ' ' + plone_layout.bodyClass(None, None)
        else:
            content_body = body_xpath(result)
            if len(content_body) > 0:
                body_classes += ' ' + content_body[0].attrib.get('class', '')

        body = body_xpath(tree)[0]
        from plone.app.blocks.layoutbehavior import ILayoutAware
        if ILayoutAware.providedBy(context):
            body_classes += ' template-layout'
            adapted = ILayoutAware(context, None)
            if adapted is not None:
                layout = getattr(adapted, 'contentLayout', None)
                if layout:
                    # Transform ++contentlayout++default/document.html
                    # into layout-default-document
                    names = LAYOUT_NAME.findall(layout)
                    if len(names) == 1:
                        body_classes += ' layout-' + names[0].replace('/', '-')
                else:
                    body_classes += ' layout-custom'

        try:
            body_classes += ' selected-layout-%s ' % original_context.getLayout(
            )  # noqa
        except Exception:
            pass
        classes = '%s %s' % (body.attrib.get('class', ''), body_classes)
        body.attrib['class'] = classes

        plone_view = queryMultiAdapter((original_context, request),
                                       name='plone')
        if plone_view:
            try:
                body.attrib.update(plone_view.patterns_settings())
            except AttributeError:
                plone_view = queryMultiAdapter((context, request),
                                               name='plone')
                if plone_view:
                    body.attrib.update(plone_view.patterns_settings())
Beispiel #5
0
def is_mosaic_edit_form(request):
    try:
        if (ILayoutAware.providedBy(request.PUBLISHED.context)
                and IDexterityEditForm.providedBy(request.PUBLISHED)
                and request.PUBLISHED.context.getLayout() == 'layout_view'
                and request.PUBLISHED.__name__ == 'edit'):
            return True
    except:
        pass
    return False
Beispiel #6
0
    def get_field_data(self):
        from plone.dexterity.interfaces import IDexterityFTI
        from plone.behavior.interfaces import IBehaviorAssignable

        data = {}

        schema = getUtility(IDexterityFTI,
                            name=self.obj.portal_type).lookupSchema()
        for name, field in getFieldsInOrder(schema):
            data[name] = getattr(self.obj, name, None)

        behavior_assignable = IBehaviorAssignable(self.obj)
        for behavior in behavior_assignable.enumerateBehaviors():
            binst = behavior.interface(self.obj)
            bdata = {}
            for name, field in getFieldsInOrder(behavior.interface):
                bdata[name] = getattr(binst, name, None)
            data[behavior.interface.__identifier__] = bdata

        if ILayoutAware.providedBy(self.obj):
            from plone.tiles.data import ANNOTATIONS_KEY_PREFIX
            from plone.app.blocks.utils import getLayout
            from repoze.xmliter.utils import getHTMLSerializer
            from plone.app.blocks import tiles
            from plone.app.blocks import gridsystem
            from lxml.html import tostring
            tdata = {}
            annotations = IAnnotations(self.obj, {})
            for key in annotations.keys():
                if key.startswith(ANNOTATIONS_KEY_PREFIX):
                    adata = annotations[key]
                    tdata[key] = adata
            data['tile_data'] = tdata

            req = site.REQUEST
            layout = getLayout(self.obj)
            dom = getHTMLSerializer(layout)

            try:
                tiles.renderTiles(req,
                                  dom.tree,
                                  site=site,
                                  baseURL=self.obj.absolute_url() +
                                  '/layout_view')
            except TypeError:
                tiles.renderTiles(req,
                                  dom.tree,
                                  baseURL=self.obj.absolute_url() +
                                  '/layout_view')
            gridsystem.merge(req, dom.tree)

            data['rendered_layout'] = tostring(dom.tree)

        return data
Beispiel #7
0
    def render(self):
        context, request = self.context, self.request
        tile = getMultiAdapter((context, request), name=u'plone.deco_toolbar')

        tile_body = ''
        tree = html.fromstring(tile.index())
        for el in tree.body.getchildren():
            tile_body += html.tostring(el)

        if ILayoutAware.providedBy(self.context):
            return u'<div style="display:none;" ' + \
                    u'data-iframe="toolbar">%s</div>' % (tile_body)
        else:
            return u''
Beispiel #8
0
    def render(self):
        context, request = self.context, self.request
        tile = getMultiAdapter((context, request), name=u'plone.deco_toolbar')

        tile_body = ''
        tree = html.fromstring(tile.index())
        for el in tree.body.getchildren():
            tile_body += html.tostring(el)

        if ILayoutAware.providedBy(self.context):
            return u'<div style="display:none;" ' + \
                    u'data-iframe="toolbar">%s</div>' % (tile_body)
        else:
            return u''
Beispiel #9
0
 def has_layout(self):
     return ILayoutAware.providedBy(self.context)