Пример #1
0
    def get_static_links(self):
        """
        Return sidebar links from portal_actions.
        """
        from plone.app.contenttypes.utils import replace_link_variables_by_paths
        from Products.CMFPlone.utils import safe_unicode

        main_nav_links = []
        root = api.portal.get_navigation_root(self.context)
        for brain in api.content.find(root.fp.main_nav, depth=1, portal_type={'query': ['Link']},
                                      sort_on='getObjPositionInParent'):
            if brain.Title == 'Home':
                continue
            link = brain.getObject()
            url = replace_link_variables_by_paths(self.context, link.remoteUrl)
            if not url.endswith('/'):
                url += '/'
            entry = {
                "uid": brain.UID,
                "url": url,
                "title": safe_unicode(brain.Title),
                "icon": self.get_icon('star'),
            }
            main_nav_links.append(entry)

        links = self.context.portal_actions.listFilteredActionsFor(self.context)  # noqa: 501
        sidebar_links = links.get('sidebar_links', [])
        return sidebar_links + main_nav_links
    def absolute_target_url(self):
        """Compute the absolute target URL."""
        url = self.context.remoteUrl

        if self._url_uses_scheme(NON_RESOLVABLE_URL_SCHEMES):
            # For non http/https url schemes, there is no path to resolve.
            return url

        if url.startswith('.'):
            # we just need to adapt ../relative/links, /absolute/ones work
            # anyway -> this requires relative links to start with ./ or
            # ../
            context_state = self.context.restrictedTraverse(
                '@@plone_context_state'
            )
            url = '/'.join([
                context_state.canonical_object_url(),
                url
            ])
        else:
            url = replace_link_variables_by_paths(self.context, url)
            if not (url.startswith('http://') or url.startswith('https://')):
                url = self.request.physicalPathToURL(url)

        return url
Пример #3
0
    def absolute_target_url(self):
        """Compute the absolute target URL."""
        url = self.context.remoteUrl

        if self._url_uses_scheme(NON_RESOLVABLE_URL_SCHEMES):
            # For non http/https url schemes, there is no path to resolve.
            return url

        remote_url_utils = getMultiAdapter(
            (self.context, self.request),
            name=u'remote_url_utils',
        )
        path = '/'.join(self.context.getPhysicalPath())

        if url.startswith('.'):
            # ./ ../ ../../
            url = remote_url_utils.remote_url_transform(
                path,
                url,
            )
        else:
            url = replace_link_variables_by_paths(self.context, url)
            url = remote_url_utils.remote_url_transform(
                path,
                url,
            )
        if not url.startswith(('http://', 'https://')):
            portal_state = self.context.restrictedTraverse(
                '@@plone_portal_state',
            )
            url = '{0}{1}'.format(portal_state.portal_url(), url)
        return url
Пример #4
0
 def get_remote_url(self):
     """
     Resolve uid and return ref absolute url
     """
     if ILink.providedBy(self.context):
         value = getattr(self.context, "remoteUrl", "")
     else:
         value = self.context.getRemoteUrl
     if not value:
         return ""
     if value.startswith("http"):
         # it isn't an internal link, so we can return it
         return value
     path = replace_link_variables_by_paths(context=self.context, url=value)
     match = RESOLVEUID_RE.match(path)
     if match:
         uid, suffix = match.groups()
         return uuidToURL(uid)
     else:
         portal = api.portal.get()
         try:
             ref_obj = portal.restrictedTraverse(path, None)
             if ref_obj:
                 return ref_obj.absolute_url()
         except Exception:
             return ""
     return ""
Пример #5
0
 def url(self):
     """Returns the url with link variables replaced.
     """
     url = replace_link_variables_by_paths(
         self.context,
         self.context.remoteUrl
     )
     return url
Пример #6
0
    def url(self):
        """Returns the url with link variables replaced.
        """

        parent = self.context.aq_parent

        url = replace_link_variables_by_paths(self.context,
                                              parent.absolute_url())
        return url
Пример #7
0
    def __call__(self):
        if self.field.getName() != "remoteUrl":
            return super(TextLineFieldSerializer, self).__call__()
        value = self.get_value()

        path = replace_link_variables_by_paths(context=self.context, url=value)
        match = RESOLVEUID_RE.match(path)
        if match:
            uid, suffix = match.groups()
            value = uuidToURL(uid)
        else:
            portal = getMultiAdapter((self.context, self.context.REQUEST),
                                     name="plone_portal_state").portal()
            ref_obj = portal.restrictedTraverse(path, None)
            if ref_obj:
                value = ref_obj.absolute_url()

        return json_compatible(value)
 def get_remote_url(self):
     if ILink.providedBy(self.context):
         value = getattr(self.context, "remoteUrl", "")
     else:
         value = self.context.getRemoteUrl
     if not value:
         return ""
     path = replace_link_variables_by_paths(context=self.context, url=value)
     match = RESOLVEUID_RE.match(path)
     if match:
         uid, suffix = match.groups()
         return uuidToURL(uid)
     else:
         portal = getMultiAdapter(
             (self.context, self.context.REQUEST), name="plone_portal_state"
         ).portal()
         ref_obj = portal.restrictedTraverse(path, None)
         if ref_obj:
             return ref_obj.absolute_url()
     return value
    def absolute_target_url(self):
        """Compute the absolute target URL."""
        url = self.context.remoteUrl

        if self._url_uses_scheme(NON_RESOLVABLE_URL_SCHEMES):
            # For non http/https url schemes, there is no path to resolve.
            return url

        if url.startswith('.'):
            # we just need to adapt ../relative/links, /absolute/ones work
            # anyway -> this requires relative links to start with ./ or
            # ../
            context_state = self.context.restrictedTraverse(
                '@@plone_context_state')
            url = '/'.join([context_state.canonical_object_url(), url])
        else:
            url = replace_link_variables_by_paths(self.context, url)
            if not (url.startswith('http://') or url.startswith('https://')):
                url = self.request.physicalPathToURL(url)

        return url
    def absolute_target_url(self):
        """Compute the absolute target URL."""
        if self.context.remoteUrl.startswith('.'):
            # we just need to adapt ../relative/links, /absolute/ones work
            # anyway -> this requires relative links to start with ./ or
            # ../
            context_state = self.context.restrictedTraverse(
                '@@plone_context_state'
            )
            url = '/'.join([
                context_state.canonical_object_url(),
                self.context.remoteUrl
            ])
        else:
            url = replace_link_variables_by_paths(
                self.context,
                self.context.remoteUrl
            )
            if not (url.startswith('http://') or url.startswith('https://')):
                url = self.request.physicalPathToURL(url)

        return url
Пример #11
0
    def __call__(self):
        if self.field.getName() != "remoteUrl":
            return super().__call__()
        value = self.get_value()

        # Expect that all internal links will have resolveuid
        if value and "resolveuid" in value:
            return uid_to_url(value)

        # Fallback in case we still have a variable in there
        path = replace_link_variables_by_paths(context=self.context, url=value)
        portal = getMultiAdapter((self.context, self.context.REQUEST),
                                 name="plone_portal_state").portal()
        # We should traverse unrestricted, just in case that the path to the object
        # is not all public, we should be able to reach it by finger pointing
        ref_obj = portal.unrestrictedTraverse(path, None)
        if ref_obj:
            value = ref_obj.absolute_url()
            return json_compatible(value)
        else:
            # The URL does not point to an existing object, so just return the value
            # without value interpolation
            return json_compatible(value.replace("${portal_url}", ""))
Пример #12
0
def getRemoteUrl(obj):
    return replace_link_variables_by_paths(obj, obj.remoteUrl)
Пример #13
0
 def get_link_action(self, link):
     context = aq_inner(self.context)
     link_action = replace_link_variables_by_paths(context, link)
     return link_action
Пример #14
0
    def getDoormatData(self):
        """ Return a dictionary like this:
        data = [
            {   'column_title: 'Column One',
                'column_sections: [
                {   'section_title': 'De Oosterpoort',
                    'section_links': [
                        {   'link_title': 'Some Title',
                            'link_url': 'http://some.whe.re',
                            'link_class': 'external-link',
                            'content': 'html content',
                            },
                        ]
                    },
                ]
            },
        ]
        """
        doormat = self.context
        data = []
        # Fetch Columns
        for column in doormat.listFolderContents():
            column_dict = {
                'column_title': column.Title(),
                'show_title': column.getShowTitle(),
                }
            column_sections = []
            sections = column.listFolderContents()

            # Fetch Categories from Column
            for section in sections:
                section_dict = {
                    'section_title': section.Title(),
                    'show_title': section.getShowTitle(),
                    }
                section_links = []
                objs = section.listFolderContents()

                # Loop over all link object in category
                for item in objs:
                    # Use the link item's title, not that of the linked content
                    title = item.Title()
                    text = ''
                    url = ''
                    link_class = ''

                    if item.portal_type == 'DoormatReference':
                        linked_item = item.getInternal_link()
                        if not linked_item:
                            continue
                        url = linked_item.absolute_url()
                    elif item.portal_type == "Link":
                        if item.meta_type.startswith('Dexterity'):
                            # A Dexterity-link
                            url = replace_link_variables_by_paths(
                                self.context,
                                item.remoteUrl
                            )
                        else:
                            # Link is an Archetypes link
                            url = item.getRemoteUrl
                        link_class = "external-link"
                    elif item.portal_type == "Document":
                        if item.meta_type.startswith('Dexterity'):
                            # A Dexterity-link
                            text = item.text.output
                        else:
                            text = item.getText()
                    elif item.portal_type == "DoormatCollection":
                        if item.getCollection().portal_type == "Topic":
                            results = self.getCollection(item)

                            # Add links from collections
                            for nitem in results:
                                obj = nitem.getObject()

                                if (item.showTime):
                                    title = self.localizedTime(obj.modified())\
                                        + ' - ' + obj.title
                                else:
                                    title = obj.title

                                section_links.append({
                                    'content': '',
                                    'link_url': obj.absolute_url(),
                                    'link_title': title,
                                    'link_class': 'collection-item',
                                    })

                            # Add the read more link if it is specified
                            if item.getShowMoreLink():
                                section_links.append({
                                    'content': '',
                                    'link_url': item.getShowMoreLink(
                                        ).absolute_url(),
                                    'link_title': item.showMoreText,
                                    'link_class': 'read-more'
                                })

                            continue
                        elif item.getCollection().portal_type == "Collection":
                            results = self.getCollection(item)

                            # Add links from collections
                            for nitem in results:
                                obj = nitem.getObject()

                                if (item.showTime):
                                    title = self.localizedTime(obj.modified())\
                                        + ' - ' + obj.title
                                else:
                                    title = obj.title

                                section_links.append({
                                    'content': '',
                                    'link_url': obj.absolute_url(),
                                    'link_title': title,
                                    'link_class': 'collection-item',
                                    })

                            # Add the read more link if it is specified
                            if item.getShowMoreLink():
                                section_links.append({
                                    'content': '',
                                    'link_url': item.getShowMoreLink(
                                        ).absolute_url(),
                                    'link_title': item.showMoreText,
                                    'link_class': 'read-more'
                                })

                            continue
                        else:
                            url = ''
                            text = ("%s: This is not a collection, but a %s "
                                    ":-)" % (
                                        item.id,
                                        item.getCollection().portal_type))

                    if not (text or url):
                        continue

                    link_dict = {
                        'content': text,
                        'link_url': url,
                        'link_title': title,
                        'link_class': link_class,
                        }
                    section_links.append(link_dict)
                section_dict['section_links'] = section_links
                column_sections.append(section_dict)
            column_dict['column_sections'] = column_sections
            data.append(column_dict)
        return data
Пример #15
0
    def getDoormatData(self):
        """ Return a dictionary like this:
        data = [
            {   'column_title: 'Column One',
                'column_sections: [
                {   'section_title': 'De Oosterpoort',
                    'section_links': [
                        {   'link_title': 'Some Title',
                            'link_url': 'http://some.whe.re',
                            'link_class': 'external-link',
                            'content': 'html content',
                            },
                        ]
                    },
                ]
            },
        ]
        """
        doormat = self.context
        data = []
        # Fetch Columns
        for column in doormat.listFolderContents():
            column_dict = {
                'column_title': column.Title(),
                'show_title': column.getShowTitle(),
            }
            column_sections = []
            sections = column.listFolderContents()

            # Fetch Categories from Column
            for section in sections:
                section_dict = {
                    'section_title': section.Title(),
                    'show_title': section.getShowTitle(),
                }
                section_links = []
                objs = section.listFolderContents()

                # Loop over all link object in category
                for item in objs:
                    # Use the link item's title, not that of the linked content
                    title = item.Title()
                    text = ''
                    url = ''
                    link_class = ''

                    if item.portal_type == 'DoormatReference':
                        linked_item = item.getInternal_link()
                        if not linked_item:
                            continue
                        url = linked_item.absolute_url()
                    elif item.portal_type == "Link":
                        if item.meta_type.startswith('Dexterity'):
                            # A Dexterity-link
                            url = replace_link_variables_by_paths(
                                self.context, item.remoteUrl)
                        else:
                            # Link is an Archetypes link
                            url = item.getRemoteUrl
                        link_class = "external-link"
                    elif item.portal_type == "Document":
                        if item.meta_type.startswith('Dexterity'):
                            # A Dexterity-link
                            text = item.text.output
                        else:
                            text = item.getText()
                    elif item.portal_type == "DoormatCollection":
                        if item.getCollection().portal_type == "Topic":
                            results = self.getCollection(item)

                            # Add links from collections
                            for nitem in results:
                                obj = nitem.getObject()

                                if (item.showTime):
                                    title = self.localizedTime(obj.modified())\
                                        + ' - ' + obj.title
                                else:
                                    title = obj.title

                                section_links.append({
                                    'content':
                                    '',
                                    'link_url':
                                    obj.absolute_url(),
                                    'link_title':
                                    title,
                                    'link_class':
                                    'collection-item',
                                })

                            # Add the read more link if it is specified
                            if item.getShowMoreLink():
                                section_links.append({
                                    'content':
                                    '',
                                    'link_url':
                                    item.getShowMoreLink().absolute_url(),
                                    'link_title':
                                    item.showMoreText,
                                    'link_class':
                                    'read-more'
                                })

                            continue
                        elif item.getCollection().portal_type == "Collection":
                            results = self.getCollection(item)

                            # Add links from collections
                            for nitem in results:
                                obj = nitem.getObject()

                                if (item.showTime):
                                    title = self.localizedTime(obj.modified())\
                                        + ' - ' + obj.title
                                else:
                                    title = obj.title

                                section_links.append({
                                    'content':
                                    '',
                                    'link_url':
                                    obj.absolute_url(),
                                    'link_title':
                                    title,
                                    'link_class':
                                    'collection-item',
                                })

                            # Add the read more link if it is specified
                            if item.getShowMoreLink():
                                section_links.append({
                                    'content':
                                    '',
                                    'link_url':
                                    item.getShowMoreLink().absolute_url(),
                                    'link_title':
                                    item.showMoreText,
                                    'link_class':
                                    'read-more'
                                })

                            continue
                        else:
                            url = ''
                            text = (
                                "%s: This is not a collection, but a %s "
                                ":-)" %
                                (item.id, item.getCollection().portal_type))

                    if not (text or url):
                        continue

                    link_dict = {
                        'content': text,
                        'link_url': url,
                        'link_title': title,
                        'link_class': link_class,
                    }
                    section_links.append(link_dict)
                section_dict['section_links'] = section_links
                column_sections.append(section_dict)
            column_dict['column_sections'] = column_sections
            data.append(column_dict)
        return data