Ejemplo n.º 1
0
def fix_site_breadcrumbs(context):
    """ Hide SITE from breadcrumbs
    """
    logger.info('Hiding SITE and its translations from breadcrumbs...')
    portal_url = getToolByName(context, 'portal_url')
    portal = portal_url.getPortalObject()
    site = getattr(portal, 'SITE', None)

    if not site:
        logger.info('Nothing to do. Aborting...')
        return

    if not IHideFromBreadcrumbs.providedBy(site):
        logger.info('Applying IHideFromBreadcrumbs on SITE')
        alsoProvides(site, IHideFromBreadcrumbs)

    if not IHideBreadcrumbsViewlet.providedBy(site):
        logger.info('Applying IHideBreadcrumbsViewlet on SITE')
        alsoProvides(site, IHideBreadcrumbsViewlet)

    if not hasattr(site, 'getTranslations'):
        logger.info('No translations. Aborting...')
        return

    for lang in site.getTranslations():
        translation = site.getTranslation(lang)
        if not IHideFromBreadcrumbs.providedBy(translation):
            logger.info('Applying IHideFromBreadcrumbs on %s', lang)
            alsoProvides(translation, IHideFromBreadcrumbs)

        if not IHideBreadcrumbsViewlet.providedBy(translation):
            logger.info('Applying IHideBreadcrumbsViewlet on %s', lang)
            alsoProvides(translation, IHideBreadcrumbsViewlet)

    logger.info('Hiding SITE and its translations from breadcrumbs... DONE')
Ejemplo n.º 2
0
    def breadcrumbs(self):
        context = aq_inner(self.context)
        request = self.request
        container = utils.parent(context)

        name, item_url = get_view_url(context)

        if container is None:
            return ({
                'absolute_url': item_url,
                'Title': utils.pretty_title_or_id(context, context),
            },)

        view = getMultiAdapter((container, request), name='breadcrumbs_view')
        base = tuple(view.breadcrumbs())

        # Some things want to be hidden from the breadcrumbs
        if IHideFromBreadcrumbs.providedBy(context):
            return base

        rootPath = getNavigationRoot(context)
        itemPath = '/'.join(context.getPhysicalPath())

        # don't show default pages in breadcrumbs or pages above the navigation
        # root
        if not utils.isDefaultPage(context, request) \
           and not rootPath.startswith(itemPath):
            base += ({
                'absolute_url': item_url,
                'Title': utils.pretty_title_or_id(context, context),
            },)
        return base
Ejemplo n.º 3
0
    def breadcrumbs(self):
        context = self.context
        request = self.request
        parent = aq_parent(context)

        name, item_url = get_view_url(context)

        if parent is None:
            return ({'absolute_url': item_url,
                     'Title': utils.pretty_title_or_id(context, context), },)

        view = getMultiAdapter((parent, request), name='breadcrumbs_view')
        base = tuple(view.breadcrumbs())

        # Some things want to be hidden from breadcrumbs
        if IHideFromBreadcrumbs.providedBy(context):
            return base

        if base:
            item_url = '%s/%s' % (base[-1]['absolute_url'], name)
        else:
            item_url = '%s/%s' % (parent.absolute_url(), name)

        rootPath = getNavigationRoot(context)
        itemPath = '/'.join(context.getPhysicalPath())

        # Don't show default pages in breadcrumbs or pages above the navigation root
        if not utils.isDefaultPage(context, request) and not rootPath.startswith(itemPath):
            base += ({'absolute_url': item_url,
                      'Title': utils.pretty_title_or_id(context, context), },)

        return base
Ejemplo n.º 4
0
    def breadcrumbs(self):
        context = aq_inner(self.context)
        request = self.request
        container = utils.parent(context)
        try:
            name, item_url = get_view_url(context)
        except AttributeError:
            print context
            raise

        if container is None:
            return ({'absolute_url': item_url,
                     'Title': utils.pretty_title_or_id(context, context),
                    },)

        view = getMultiAdapter((container, request), name='breadcrumbs_view')
        base = tuple(view.breadcrumbs())

        # Some things want to be hidden from the breadcrumbs
        if IHideFromBreadcrumbs.providedBy(context):
            return base

        rootPath = getNavigationRoot(context)
        itemPath = '/'.join(context.getPhysicalPath())

        # don't show default pages in breadcrumbs or pages above the navigation root
        if not utils.isDefaultPage(context, request) and not rootPath.startswith(itemPath):
            base += ({'absolute_url': _checkPermission('View', context) and item_url or None,
                      'Title': utils.pretty_title_or_id(context, context),
                     },)

        return base
Ejemplo n.º 5
0
    def get_chains(self):
        repository = []
        chain = []
        for obj in aq_chain(self.context):
            if INavigationRoot.providedBy(obj):
                break

            if IHideFromBreadcrumbs.providedBy(obj):
                continue

            if ISQLObjectWrapper.providedBy(obj):
                data = obj.get_breadcrumb()
            else:
                data = {
                    'absolute_url': obj.absolute_url(),
                    'title': obj.Title(),
                    'css_class': get_css_class(obj, type_icon_only=True)
                }

            if self.is_part_of_repo(obj):
                repository.append(data)
            else:
                chain.append(data)

        chain.reverse()
        return repository, chain
Ejemplo n.º 6
0
    def get_chains(self):
        repository = []
        chain = []
        for obj in aq_chain(self.context):
            if INavigationRoot.providedBy(obj):
                break

            if IHideFromBreadcrumbs.providedBy(obj):
                continue

            if ISQLObjectWrapper.providedBy(obj):
                data = obj.get_breadcrumb()
            else:
                data = {
                    'absolute_url': obj.absolute_url(),
                    'title': obj.Title(),
                    'css_class': get_css_class(obj, type_icon_only=True)
                }

            if self.is_part_of_repo(obj):
                repository.append(data)
            else:
                chain.append(data)

        chain.reverse()

        return repository, chain
Ejemplo n.º 7
0
    def breadcrumbs(self):
        real_context = aq_inner(self.context)
        request_path = self.request.get('PATH_INFO', '')

        if 'VirtualHostBase' in request_path:
            path = ('',) + re.search(r'VirtualHostBase/\w+/.*?/(.*?)/VirtualHostRoot/(.*)', request_path).groups()

            request_path = '/'.join(path)
        context_path = '/'.join(real_context.getPhysicalPath())

        if request_path == context_path:
            context = real_context
        else:
            self.context.plone_log(request_path)
            parent_path = request_path[:request_path.rfind('/')]
            self.context.plone_log(parent_path)
            context = self.context.restrictedTraverse(parent_path)
        request = self.request
        container = utils.parent(context)

        name, item_url = get_view_url(context)

        if container is None:
            return (
                {'absolute_url': item_url,
                 'Title': utils.pretty_title_or_id(context, context), },
            )

        view = getMultiAdapter((container, request), name='breadcrumbs_view')
        base = tuple(view.breadcrumbs())

        # Some things want to be hidden from the breadcrumbs
        if IHideFromBreadcrumbs.providedBy(context):
            return base

        if base:
            item_url = '%s/%s' % (base[-1]['absolute_url'], name)

        rootPath = getNavigationRoot(context)
        itemPath = '/'.join(context.getPhysicalPath())

        # don't show default pages in breadcrumbs or pages above the navigation
        # root
        if not utils.isDefaultPage(context, request) \
                and not rootPath.startswith(itemPath):
            base += ({'absolute_url': item_url,
                      'Title': utils.pretty_title_or_id(context, context), },
                     )

        if request_path != context_path:
            name, item_url = get_view_url(real_context)
            base += ({'absolute_url': item_url,
                      'Title': utils.pretty_title_or_id(real_context, real_context), },
                     )

        return base
        return True
Ejemplo n.º 8
0
    def get_dashboard(self):
        write = False
        with api.env.adopt_roles(['Manager']):
            if 'dashboards' not in self.context.objectIds():
                write = True
                api.content.create(type='Folder',
                                   title='Dashboards',
                                   id='dashboards',
                                   container=self.context,
                                   exclude_from_nav=True)
            dashboards = self.context['dashboards']
            if not IHideFromBreadcrumbs.providedBy(dashboards):
                alsoProvides(dashboards, IHideFromBreadcrumbs)
            if api.content.get_state(
                    obj=dashboards,
                    default='Unknown') not in ('published',
                                               'publish_internally'):
                write = True
                publish_content(dashboards)

        member = api.user.get_current()
        user_id = member.getId()
        if user_id not in dashboards.objectIds():
            with api.env.adopt_roles(['Manager']):
                write = True
                # first make sure it is in allowed types...
                pts = api.portal.get_tool('portal_types')
                Folder = pts['Folder']
                if 'Dashboard' not in Folder.allowed_content_types:
                    allowed = list(Folder.allowed_content_types)
                    allowed.append('Dashboard')
                    Folder.allowed_content_types = tuple(allowed)

                aspect = ISelectableConstrainTypes(dashboards)
                if (aspect.getConstrainTypesMode() != 1 or
                    ['Dashboard'] != aspect.getImmediatelyAddableTypes()):
                    aspect.setConstrainTypesMode(1)
                    aspect.setImmediatelyAddableTypes(['Dashboard'])

                api.content.create(type='Dashboard',
                                   title='Dashboard',
                                   id=user_id,
                                   container=dashboards,
                                   exclude_from_nav=True)

        dashboard = dashboards[user_id]
        if dashboard.getOwner().getId() != user_id:
            with api.env.adopt_roles(['Manager']):
                write = True
                dashboard.changeOwnership(member.getUser(), recursive=False)
                dashboard.reindexObjectSecurity()
        if write:
            alsoProvides(self.request, IDisableCSRFProtection)

        return dashboard
Ejemplo n.º 9
0
def dmsdocument_removed(mail, event):
    """Delete subfolder if empty"""
    # If we are just after link_integrity check, we don't do anything...
    # Not working
    # if mail.REQUEST.get('_link_integrity_check_', False):
    #     mail.REQUEST.set('_link_integrity_check_', False)
    #     return
    parent = mail.__parent__
    # confirmed = mail.REQUEST.get('HTTP_REFERER').endswith('delete_confirmation?')
    if False and IHideFromBreadcrumbs.providedBy(parent) and not parent.objectIds():
        api.content.delete(obj=parent)
Ejemplo n.º 10
0
def breadcrumbs(self):

    def getTitle(context):

        try:
            if hasattr(context, 'hasProperty'):
                if context.hasProperty('short_breadcrumb'):
                    alt_title = context.getProperty('short_breadcrumb')
                    if alt_title:
                        return alt_title
        except TypeError:
            pass

        return utils.pretty_title_or_id(context, context)        

    context = aq_inner(self.context)
    request = self.request
    container = utils.parent(context)

    name, item_url = get_view_url(context)

    if container is None:
        return ({'absolute_url': item_url,
                    'Title': getTitle(context),},
                )

    view = getMultiAdapter((container, request), name='breadcrumbs_view')
    base = tuple(view.breadcrumbs())

    # Some things want to be hidden from the breadcrumbs
    if IHideFromBreadcrumbs.providedBy(context):
        return base

    if base:
        item_url = '%s/%s' % (base[-1]['absolute_url'], name)

    rootPath = getNavigationRoot(context)
    itemPath = '/'.join(context.getPhysicalPath())

    # don't show default pages in breadcrumbs or pages above the navigation root
    if not utils.isDefaultPage(context, request) and not rootPath.startswith(itemPath):
        base += ({'absolute_url': item_url,
                    'Title': getTitle(context), },
                )

    return base
Ejemplo n.º 11
0
def breadcrumbs(self):
    context = aq_inner(self.context)
    request = self.request
    container = utils.parent(context)

    name, item_url = get_view_url(context)

    if container is None:
        return ({
            'absolute_url': item_url,
            'Title': utils.pretty_title_or_id(context, context),
        }, )

    view = getMultiAdapter((container, request), name='breadcrumbs_view')
    base = tuple(view.breadcrumbs())

    # Some things want to be hidden from the breadcrumbs
    if IHideFromBreadcrumbs.providedBy(context):
        return base

    if base:
        item_url = '%s/%s' % (base[-1]['absolute_url'], name)

    rootPath = getNavigationRoot(context)
    itemPath = '/'.join(context.getPhysicalPath())

    # don't show default pages in breadcrumbs or pages above the navigation
    # root

    installed = packages_installed()
    if 'genweb.organs' in installed:
        if (not utils.isDefaultPage(context, request) or context.portal_type == 'genweb.organs.organsfolder') \
                and not rootPath.startswith(itemPath):
            base += ({
                'absolute_url': item_url,
                'Title': utils.pretty_title_or_id(context, context),
            }, )
    else:
        if not utils.isDefaultPage(
                context, request) and not rootPath.startswith(itemPath):
            base += ({
                'absolute_url': item_url,
                'Title': utils.pretty_title_or_id(context, context),
            }, )

    return base
Ejemplo n.º 12
0
 def breadcrumbs(self):
     if not INoBarcelonetaLayer.providedBy(self.request):
         # We are in the CMS, so we want the default.
         view = getMultiAdapter((self.context, self.request),
                                name='orig_breadcrumbs_view')
         return tuple(view.breadcrumbs())
     context = aq_inner(self.context)
     context_path = '/'.join(context.getPhysicalPath())
     root_path = getNavigationRoot(context)
     if context_path == root_path:
         # We are the navigation root.
         return ()
     # We now iteratively look for a parent and check if this is
     # the navigation root.
     chain = aq_chain(context)
     for index, parent in enumerate(chain):
         try:
             parent_path = '/'.join(parent.getPhysicalPath())
         except AttributeError:
             # This is probably the root request object, so we
             # somehow did not find a suitable parent.
             return ()
         if parent_path == root_path:
             # We have found the root.
             break
         # The parent is not yet the navigation root, so set the
         # item and try the next parent in the chain.
         item = parent
     # Get the interesting part of the chain.
     chain = list(reversed(chain[:index]))
     # Some things want to be hidden from the breadcrumbs.
     chain = [
         elem for elem in chain if not IHideFromBreadcrumbs.providedBy(elem)
     ]
     # Restrict to the wanted maximum of levels
     chain = chain[:self.levels]
     crumbs = []
     for item in chain:
         crumbs.append({
             'absolute_url': item.absolute_url(),
             'Title': utils.pretty_title_or_id(item, item)
         })
     return tuple(crumbs)
Ejemplo n.º 13
0
    def breadcrumbs(self):
        context = aq_inner(self.context)
        request = self.request
        container = utils.parent(context)

        name, item_url = get_view_url(context)

        if container is None:
            return ({
                'absolute_url': item_url,
                'Title': utils.pretty_title_or_id(context, context),
                'ct_class': 'contenttype-{}'.format(context.portal_type)
            }, )

        view = getMultiAdapter((container, request), name='breadcrumbs_view')
        base = tuple(view.breadcrumbs())

        # Some things want to be hidden from the breadcrumbs
        if IHideFromBreadcrumbs.providedBy(context):
            return base

        if base:
            item_url = '%s/%s' % (base[-1]['absolute_url'], name)

        rootPath = getNavigationRoot(context)
        itemPath = '/'.join(context.getPhysicalPath())

        # don't show default pages in breadcrumbs or pages above the navigation
        # root
        if not utils.isDefaultPage(context, request) \
                and not rootPath.startswith(itemPath):
            portal_type = context.portal_type
            if base_hasattr(context, '_link_portal_type'):
                portal_type = context._link_portal_type
            base += ({
                'absolute_url': item_url,
                'Title': utils.pretty_title_or_id(context, context),
                'ct_class': 'contenttype-{}'.format(portal_type)
            }, )

        return base
    def breadcrumbs(self):
        context = aq_inner(self.context)
        request = self.request
        container = utils.parent(context)

        name, item_url = get_view_url(context)
        if container is None:
            return (
                {'absolute_url': item_url,
                 'Title': utils.pretty_title_or_id(context, context), },
                )

        view = getMultiAdapter((container, request), name='breadcrumbs_view')
        base = tuple(view.breadcrumbs())

        # Some things want to be hidden from the breadcrumbs
        if IHideFromBreadcrumbs.providedBy(context):
            return base

        if base:
            if container.portal_type == "Scheda" and utils.isDefaultPage(container, request):
                # if the parent is a Scheda and is set as default page, it
                # doesn't appears in the breadcrums, so we need to use context
                # absolute_url instead simple concatenation
                item_url = context.absolute_url()
            else:
                item_url = '%s/%s' % (base[-1]['absolute_url'], name)

        rootPath = getNavigationRoot(context)
        itemPath = '/'.join(context.getPhysicalPath())

        # don't show default pages in breadcrumbs or pages above the navigation
        # root
        if not utils.isDefaultPage(context, request) \
                and not rootPath.startswith(itemPath):
            base += (
                {'absolute_url': item_url,
                 'Title': utils.pretty_title_or_id(context, context), },
                )

        return base
Ejemplo n.º 15
0
 def breadcrumbs(self):
     path = self.request.get('path')
     portal = self.navigation_root
     if path is None:
         context = portal
     else:
         context = portal.restrictedTraverse(unquote(path))
     crumbs = []
     context = aq_inner(context)
     while context is not None:
         if not IHideFromBreadcrumbs.providedBy(context):
             crumbs.append({
                 'path': "/".join(context.getPhysicalPath()),
                 'url': context.absolute_url(),
                 'title': context.title_or_id()
             })
         if INavigationRoot.providedBy(context):
             break
         context = utils.parent(context)
     crumbs.reverse()
     return crumbs
Ejemplo n.º 16
0
 def breadcrumbs(self):
     path = self.request.get('path')
     portal = self.navigation_root
     if path is None:
         context = portal
     else:
         context = portal.restrictedTraverse(unquote(path))
     crumbs = []
     context = aq_inner(context)
     while context is not None:
         if not IHideFromBreadcrumbs.providedBy(context):
             crumbs.append({
                 'path': "/".join(context.getPhysicalPath()),
                 'url': context.absolute_url(),
                 'title': context.title_or_id()
                 })
         if INavigationRoot.providedBy(context):
             break
         context = utils.parent(context)
     crumbs.reverse()
     return crumbs
Ejemplo n.º 17
0
    def breadcrumbs(self):
        """ Breadcrumbs
        """
        if ISiteRoot.providedBy(self.context):
            return ()

        context = aq_inner(self.context)
        request = self.request
        container = utils.parent(context)

        try:
            name, item_url = get_view_url(context)
        except AttributeError:
            print context
            raise

        if container is None:
            return ({
                'absolute_url': item_url,
                'Title': utils.pretty_title_or_id(context, context),
            }, )

        view = getMultiAdapter((container, request), name='breadcrumbs_view')
        base = tuple(view.breadcrumbs())

        # Some things want to be hidden from the breadcrumbs
        if IHideFromBreadcrumbs.providedBy(context):
            return base

        if base:
            item_url = '%s/%s' % (base[-1]['absolute_url'], name)

        # don't show default pages in breadcrumbs
        if not utils.isDefaultPage(context, request):
            base += ({
                'absolute_url': item_url,
                'Title': utils.pretty_title_or_id(context, context),
            }, )

        return base
Ejemplo n.º 18
0
    def breadcrumbs(self):
        context = aq_inner(self.context)

        view_utils = Utils(self.context, self.request)

        crumbs = []
        while context is not None:
            if ISiteRoot.providedBy(context):
                break

            try:
                if utils.isDefaultPage(context, self.request):
                    context = utils.parent(context)
                    continue
            except AttributeError:
                break

            # Some things want to be hidden from the breadcrumbs
            if IHideFromBreadcrumbs.providedBy(context):
                context = utils.parent(context)
                continue

            item_url = view_utils.get_object_url(context)
            try:
                state = api.content.get_state(obj=context)
            except WorkflowException:
                state = None
            label = getattr(context, 'navigation_label', None)
            if not label:
                label = utils.pretty_title_or_id(context, context)
            crumbs.append({
                'absolute_url': item_url,
                'Title': label,
                'state': state
            })
            context = utils.parent(context)

        return list(reversed(crumbs))
Ejemplo n.º 19
0
    def breadcrumbs(self):
        """ Breadcrumbs
        """
        if ISiteRoot.providedBy(self.context):
            return ()

        context = aq_inner(self.context)
        request = self.request
        container = utils.parent(context)

        try:
            name, item_url = get_view_url(context)
        except AttributeError:
            print context
            raise

        if container is None:
            return ({'absolute_url': item_url,
                     'Title': utils.pretty_title_or_id(context, context),
                    },)

        view = getMultiAdapter((container, request), name='breadcrumbs_view')
        base = tuple(view.breadcrumbs())

        # Some things want to be hidden from the breadcrumbs
        if IHideFromBreadcrumbs.providedBy(context):
            return base

        if base:
            item_url = '%s/%s' % (base[-1]['absolute_url'], name)

        # don't show default pages in breadcrumbs
        if not utils.isDefaultPage(context, request):
            base += ({'absolute_url': item_url,
                      'Title': utils.pretty_title_or_id(context, context),
                     },)

        return base
Ejemplo n.º 20
0
    def breadcrumbs(self):
        context = aq_inner(self.context)
        request = self.request
        container = utils.parent(context)
        
        try:
            name, item_url = get_view_url(context)
        except AttributeError:
            print context
            raise


        if hasattr(context,"UID"):
            if callable(context.UID):
                theuid = context.UID()
            else:
                theuid = context.UID
        else:
            theuid = ''

        if container is None:
            return [{'absolute_url': item_url,
                     'Title': utils.pretty_title_or_id(context, context),
                     'applications':None,
                     'UID': theuid,
                     'portal_type': context.portal_type
                    }]

        view = getMultiAdapter((container, request), name='breadcrumbs_view')
        base = view.breadcrumbs()

        # Some things want to be hidden from the breadcrumbs
        if IHideFromBreadcrumbs.providedBy(context):
            return base

        if base:
            item_url = '%s/%s' % (base[-1]['absolute_url'], name)

        rootPath = getNavigationRoot(context)
        itemPath = '/'.join(context.getPhysicalPath())


        # don't show default pages in breadcrumbs or pages above the navigation root
        if not utils.isDefaultPage(context, request) and not rootPath.startswith(itemPath):            
            if not base:
                base = []

            tempapps = []
            tempobj = {}
            tempobj['absolute_url'] = item_url
            tempobj['Title'] = utils.pretty_title_or_id(context,context)
            tempobj['UID'] = theuid
            tempobj['portal_type'] = context.portal_type
            tempobj['applications'] = []
            
            
            try:
                if hasattr(context,'listApplications'):
                    tempobj['applications'] = context.listApplications()
            except AttributeError:
                pass            
            
            base.append(tempobj)            
        return base
Ejemplo n.º 21
0
 def show(self):
     if IHideFromBreadcrumbs.providedBy(self.context):
         return False
     return super(ActionsPanelViewletAllButTransitions, self).show()