Esempio n. 1
0
 def get_items(self):
     """
     Get folder contents and return.
     """
     context = self.context
     root_nav = api.portal.get_registry_record(
         name='collective.sidebar.root_nav',
         default=False,
     )
     if root_nav:
         context = api.portal.get_navigation_root(context)
     contents = []
     if IFolderish.providedBy(context):
         contents = context.getFolderContents()
     else:
         try:
             parent = context.aq_parent
             contents = parent.getFolderContents()
         except Exception:
             pass
     items = []
     for item in contents:
         if self.check_item(item):
             data = {
                 'title': item.Title,
                 'title_cropped': crop(item.Title, 100),
                 'url': item.getURL(),
             }
             items.append(data)
     return items
Esempio n. 2
0
 def get_show(self):
     """
     Get link to current folder.
     """
     if self.get_back() and IFolderish.providedBy(self.context):
         data = {
             'title': self.context.Title(),
             'title_cropped': crop(self.context.Title(), 100),
             'url': self.context.absolute_url(),
             'type': 'link-folder',
         }
         return data
Esempio n. 3
0
 def test_crop(self):
     from collective.sidebar.utils import crop
     self.assertEqual(crop(u'just text', 6), u'just...')
     self.assertEqual(crop(u'just text', 100), u'just text')
     self.assertEqual(crop(u'.sonderzeichen:,;', 15), u'sonderzeichen...')
     self.assertEqual(crop(u'.sonderzeichen:,;', 18), u'.sonderzeichen:,;')
     self.assertEqual(crop(u'12345678910', 5), u'12345...')
     self.assertEqual(crop(u'This should be:cropping', 20), u'This should be...')  # noqa
Esempio n. 4
0
    def get_items(self):
        """
        Get folder contents and return.
        """
        context = self.context
        root_nav = api.portal.get_registry_record(
            name='collective.sidebar.root_nav',
            default=False,
        )
        view_types = api.portal.get_registry_record(
            name='plone.types_use_view_action_in_listings'
        )

        # root level navigation is enabled in settings
        if root_nav:
            context = api.portal.get_navigation_root(context)

        # context is folderish, list content
        if IFolderish.providedBy(context):
            # context is an endpoint, list parents content
            if INavigationEndpoint.providedBy(context):
                context = context.aq_parent
        else:
            # context is an item, list parents content
            context = context.aq_parent

        contents = list()

        # Can not remember what edgecase we catch here.
        try:
            contents = context.getFolderContents()
        except Exception:  # noqa: 902
            pass

        items = list()
        for item in contents:
            if self.check_item(item):
                item_type = 'link-item'
                url = item.getURL()
                if item.portal_type in view_types:
                    url = url + '/view'
                if item.is_folderish and self.contains_items(item):
                    item_type = 'link-folder'
                data = {
                    'title': item.Title,
                    'title_cropped': crop(item.Title, 100),
                    'url': url,
                    'type': item_type,
                }
                items.append(data)
        return items