コード例 #1
0
ファイル: summary.py プロジェクト: RedTurtle/redturtle.volto
 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 ""
コード例 #2
0
    def test_fix_interface_for_link(self):
        self.obj.portal_type = 'Link'
        self.catalog.reindexObject(self.obj)

        self.portal.restrictedTraverse('fix_base_classes')()

        self.assertTrue(ILink.providedBy(self.obj))
コード例 #3
0
    def test_fix_interface_for_link(self):
        self.obj.portal_type = 'Link'
        self.catalog.reindexObject(self.obj)

        self.portal.restrictedTraverse('fix_base_classes')()

        self.assertTrue(ILink.providedBy(self.obj))
コード例 #4
0
 def test_factory(self):
     fti = queryUtility(
         IDexterityFTI,
         name='Link'
     )
     factory = fti.factory
     new_object = createObject(factory)
     self.assertTrue(ILink.providedBy(new_object))
コード例 #5
0
 def test_factory(self):
     fti = queryUtility(
         IDexterityFTI,
         name='Link'
     )
     factory = fti.factory
     new_object = createObject(factory)
     self.assertTrue(ILink.providedBy(new_object))
コード例 #6
0
 def is_printable(self):
     if ILink.providedBy(self.context):
         return False
     if IFile.providedBy(self.context):
         return IIconifiedPreview(self.context).is_convertible()
     if IImage.providedBy(self.context):
         return True
     return True
コード例 #7
0
ファイル: test_migration.py プロジェクト: mingtak/prome
 def test_link_is_migrated(self):
     from Products.ATContentTypes.content.link import ATLink
     from plone.app.contenttypes.migration.migration import LinkMigrator
     from plone.app.contenttypes.interfaces import ILink
     at_link = self.createATCTobject(ATLink, 'link')
     migrator = self.get_migrator(at_link, LinkMigrator)
     migrator.migrate()
     new_link = self.portal['link']
     self.assertTrue(ILink.providedBy(new_link))
     self.assertTrue(at_link is not new_link)
コード例 #8
0
 def test_link_is_migrated(self):
     from plone.app.contenttypes.migration.migration import LinkMigrator
     from plone.app.contenttypes.interfaces import ILink
     self.portal.invokeFactory('Link', 'link')
     at_link = self.portal['link']
     applyProfile(self.portal, 'plone.app.contenttypes:default')
     migrator = self.get_migrator(at_link, LinkMigrator)
     migrator.migrate()
     dx_link = self.portal['link']
     self.assertTrue(ILink.providedBy(dx_link))
     self.assertTrue(dx_link is not at_link)
コード例 #9
0
ファイル: test_migration.py プロジェクト: mingtak/prome
 def test_link_content_is_migrated(self):
     from plone.app.contenttypes.migration.migration import LinkMigrator
     from plone.app.contenttypes.interfaces import ILink
     from Products.ATContentTypes.content.link import ATLink
     at_link = self.createATCTobject(ATLink, 'link')
     field = at_link.getField('remoteUrl')
     field.set(at_link, 'http://plone.org')
     migrator = self.get_migrator(at_link, LinkMigrator)
     migrator.migrate()
     new_link = self.portal['link']
     self.assertTrue(ILink.providedBy(new_link.link))
     self.assertEqual(new_link.link.remoteUrl, u'http://plone.org')
コード例 #10
0
 def test_link_content_is_migrated(self):
     from plone.app.contenttypes.migration.migration import LinkMigrator
     from plone.app.contenttypes.interfaces import ILink
     self.portal.invokeFactory('Link', 'link')
     at_link = self.portal['link']
     field = at_link.getField('remoteUrl')
     field.set(at_link, 'http://plone.org')
     applyProfile(self.portal, 'plone.app.contenttypes:default')
     migrator = self.get_migrator(at_link, LinkMigrator)
     migrator.migrate()
     dx_link = self.portal['link']
     self.assertTrue(ILink.providedBy(dx_link.link))
     self.assertEqual(dx_link.link.remoteUrl, u'http://plone.org')
コード例 #11
0
    def GET(self):
        """ Return the links from Menu Gestion folder and Menu ControlPanel """
        language = self.params['language']
        portal = api.portal.get()

        resultsGestion = {}
        try:
            path = portal['gestion']['menu'][language]  # fixed en code... always in this path
            folders = api.content.find(context=path, portal_type=('Folder', 'privateFolder'), depth=1)
            found = True
        except:
            # 'Menu Gestion not configured or Language not found.'
            resultsGestion = ''
            found = False

        if found:
            # Links from gestion folder
            for folder in folders:
                resultsGestion[folder.Title] = []
                menufolder = folder.getObject().items()
                for item in menufolder:
                    if ILink.providedBy(item[1]):
                        menuLink = dict(url=item[1].remoteUrl,
                                        title=item[1].title,
                                        )
                        resultsGestion[folder.Title].append(menuLink)

            if not resultsGestion:
                # 'No Menu Gestion configured in this Site.'
                resultsGestion = ''

        registry = getUtility(IRegistry)
        settings = registry.forInterface(IUlearnControlPanelSettings, check=False)

        # Links from controlpanel
        resultsControlPanel = []
        if settings.quicklinks_table:
            for item in settings.quicklinks_table:
                quickLink = dict(title=item['text'],
                                 url=item['link'],
                                 icon=item['icon'],
                                 )
                resultsControlPanel.append(quickLink)

        if not resultsControlPanel:
            # 'Menu Quicklinks not configured in the ControlPanel.'
            resultsControlPanel = ''

        values = {'Menu_Gestion': resultsGestion, 'Menu_Controlpanel': resultsControlPanel}

        return ApiResponse(values)
コード例 #12
0
    def test_migrate_class_also_updates_provided_interfaces_info(self):
        if getFSVersionTuple() > (5, ):
            from plone.app.contenttypes.content import Link
            from plone.app.contenttypes.interfaces import ILink
            from plone.app.contenttypes.interfaces import IDocument
        else:
            from Products.ATContentTypes.content.link import ATLink as Link
            from Products.ATContentTypes.interfaces import IATLink as ILink
            from Products.ATContentTypes.interfaces import IATDocument as IDocument

        obj = create(Builder('document'))
        self.assertTrue(IDocument.providedBy(obj))
        self.assertFalse(ILink.providedBy(obj))

        class Step(UpgradeStep):
            def __call__(self):
                self.migrate_class(obj, Link)

        Step(self.portal_setup)
        self.assertFalse(IDocument.providedBy(obj),
                         'Document interface not removed in migration')
        self.assertTrue(ILink.providedBy(obj),
                        'Link interface not added in migration')
コード例 #13
0
 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
コード例 #14
0
 def test_adding(self):
     self.portal.invokeFactory(
         'Link',
         'doc1'
     )
     self.assertTrue(ILink.providedBy(self.portal['doc1']))
コード例 #15
0
 def test_adding(self):
     self.portal.invokeFactory('Link', 'doc1')
     self.assertTrue(ILink.providedBy(self.portal['doc1']))
コード例 #16
0
 def test_adding_l2(self):
     self.assertTrue(ILink.providedBy(self.l2))
コード例 #17
0
ファイル: staticpages.py プロジェクト: liqd/adhocracy.plone
    def staticpages_single(self):
        """saticpages/single View

        Context: INavigationRoot content

        Get parameter:

            * lang: language folder, multiple allowed to set fallback, required
            * path: path to item relative to the lang folder

        Traverse to the content under lang/path and return the rendered html
        of the default view.

        @return: JSON dictionary with html representation

        """
        item = None
        view = None
        link = None
        response_data = {}
        lang = u''
        data = self._get_data()
        if data['langs'] == [] or data['path'] == '':
            raise KeyError
        if data['path'].startswith("author/")\
                or data['path'].startswith("sitemap"):
            view = self.context.restrictedTraverse(data['path'])
        else:
            for lang in data['langs']:
                try:
                    item = self.context\
                        .restrictedTraverse("/".join([lang, data['path']]))
                    lang = lang
                    if item is not None:
                        break
                except (KeyError, TraversalError):
                    pass
            if item is None:
                raise KeyError
        if ILink.providedBy(item):
            link = item
            item = None
        response_data['lang'] = lang
        response_data['private'] = False

        html = ''
        tree = None
        redirect_url = u''
        if link:
            portal_state = link.restrictedTraverse("@@plone_portal_state")
            if "${navigation_root_url}" in link.remoteUrl:
                navigation_root_url = portal_state.navigation_root_url()
                redirect_url = link.remoteUrl.replace("${navigation_root_url}",
                                                      navigation_root_url)
            elif "${portal_url}" in link.remoteUrl:
                portal_url = portal_state.portal_url()
                redirect_url = link.remoteUrl.replace("${portal_url}",
                                                      portal_url)
            else:
                redirect_url = link.remoteUrl
        if view:
            html = view()
        if item:
            default_page_view = getMultiAdapter((item, self.request),
                                                name="default_page")
            default_page = default_page_view.getDefaultPage()
            item = item[default_page] if default_page else item

            viewname = item.getLayout() or item.getDefaultLayout()
            view = None
            try:
                view = getMultiAdapter((item, self.request), name=viewname)
            except ComponentLookupError:
                viewname = 'view'
                view = getMultiAdapter((item, self.request), name=viewname)
            view.request.URL = item.absolute_url() + "/" + viewname
            view.request.response.setHeader('Content-Type', 'text/html')
            view.request['plone.app.blocks.enabled'] = True
            html_no_tiles = view()
            parser = etree.HTMLParser()
            tree = etree.parse(StringIO(html_no_tiles), parser)
            renderTiles(view.request, tree)
            html = etree.tostring(tree.getroot(), method="html",
                                  pretty_print=True)

        soup = BeautifulSoup(html)

        css_classes_soup = soup.body['class'] if soup.body else None
        response_data['css_classes'] = css_classes_soup\
            if css_classes_soup else []
        column_r_soup = soup.find(id='portal-column-two')
        response_data['column_right'] = column_r_soup.encode('utf-8').strip()\
            if column_r_soup else u''
        nav_soup = soup.find(id='portal-globalnav')
        response_data['nav'] = nav_soup.encode('utf-8').strip()\
            if nav_soup else u''

        content_soup = soup.find(id="content")
        remove_ids = ['plone-document-byline']
        for id_ in remove_ids:
            tag = content_soup.find(id=id_) if content_soup else None
            if tag:
                tag.extract()
        remove_tags = ['script']
        for tag in remove_tags:
            tags_ = content_soup.find_all(tag) if content_soup else []
            for tag_ in tags_:
                tag_.extract()
        title_soup = content_soup.find(class_='documentFirstHeading')\
            if content_soup else None
        response_data['title'] = title_soup.extract().get_text().strip()\
            if title_soup else u''
        descr_soup = content_soup.find(class_='documentDescription')\
            if content_soup else None
        response_data['description'] = descr_soup.extract().get_text().strip()\
            if descr_soup else u''
        response_data['body'] = content_soup.encode("utf-8").strip()\
            if content_soup else u''
        response_data['redirect_url'] = redirect_url

        return response_data
コード例 #18
0
 def test_adding_l2(self):
     self.assertTrue(ILink.providedBy(self.l2))