Example #1
0
 def news_items(self, section=None, start=None, limit=5):
     desc_len = 160
     _items = []
     i = 0
     for item in self.context.news_items(section,
                                         start,
                                         limit,
                                         sort_on='created',
                                         sort_order='reverse'):
         i += 1
         if item.section:
             category = item.section.to_object.title
         else:
             category = None
         published = api.content.get_state(item) == 'published'
         _items.append(
             obj2dict(
                 item,
                 'id',
                 'title',
                 'absolute_url',
                 description=shorten(item.description, desc_len),
                 date=item.effective().strftime('%B %d, %Y'),
                 category=category,
                 counter=i,
                 can_edit=api.user.has_permission('Modify', obj=item),
                 published=published,
             ))
     return _items
Example #2
0
 def shorten(self, text):
     return shorten(text, length=256)
Example #3
0
 def test_text_shortener(self):
     text = utils.shorten(string_with_unicode, 20)
     self.assertEquals(text, string_with_unicode_shortened)
     text = utils.shorten(unicode_string, 20)
     self.assertEquals(text, unicode_string_shortened)
Example #4
0
 def shorten(self, text):
     return shorten(text, length=60)
Example #5
0
    def _get_my_groups_and_workspaces(self):
        """
            Find all the groups and all the workspaces the user is a member of.
            Since workspaces can also act as groups, only count those items
            as groups which are not also a workspace.
        """
        my_groups = plone_api.group.get_groups(username=self.context.username)
        # Sort the "normal" groups first
        my_groups = sorted(
            my_groups, key=lambda x: x is not None and x.id.find(':'))
        workspaces = {}
        groups = []
        portal = plone_api.portal.get()
        portal_url = portal.absolute_url()
        g_icon = '/++theme++ploneintranet.theme/generated/media/icon-group.svg'

        group_container = self.group_container
        group_url_template = '%s/{}' % (
            group_container.absolute_url() if group_container else ''
        )
        group_view_url_template = '%s/workspace-group-view?id={}' % (
            self.context.absolute_url()
        )
        # Don't show certain system groups
        group_filter = ['Members', 'AuthenticatedUsers', 'All Intranet Users']
        for group in my_groups:
            if not group:
                continue
            if group.id in group_filter:
                continue
            if group.getProperty('type', None) == 'workspace':
                # This is a groupspace
                uid = group.getProperty('uid')
                url = portal_url + group.getProperty('workspace_path')
                workspaces[uid] = dict(
                    url=url,
                    title=group.getProperty('title'),
                    description=group.getProperty('description'),
                )
            elif (
                ":" in group.id and len(group.id.split(':')[1]) >= 32 and
                group.id.split(':')[0] in AVAILABLE_GROUPS
            ):
                # Special group that denotes membership in a workspace
                id, uid = group.id.split(':')
                # If this workspaces has already been added via the
                # groupspaces behaviour, skip fetching the WS object.
                if uid in workspaces:
                    continue

                ws = plone_api.content.get(UID=uid)
                # User might not be allowed to access the ws
                if ws is None:
                    continue
                workspaces[uid] = dict(
                    url=ws.absolute_url(),
                    title=ws.title,
                    description=ws.description,
                )
            else:
                if group.id in group_container:
                    # a membrane group
                    url = group_url_template.format(group.id)
                else:
                    # "regular" group that is not a workspace
                    # or a membrane group
                    url = group_view_url_template.format(group.id)

                title = group.title or group.id
                img = portal_url + g_icon

                groups.append(dict(
                    id=group.id,
                    group=group,
                    url=url,
                    title=shorten(title, length=30),
                    img=img,
                ))

        self._my_groups = groups
        self._my_workspaces = workspaces.values()
Example #6
0
 def description(self, desc_len=160):
     return shorten(self.context.description, desc_len)