Exemplo n.º 1
0
def getSubsiteRoot(context, relativeRoot=None):
    """Get the path to the root of the navigation tree. If context or one of
    its parents until (but not including) the portal root implements
    ISubsiteEnhanced, return this.

    Otherwise, if an explicit root is set in navtree_properties or given as
    relativeRoot, use this. If the property is not set or is set to '/', use
    the portal root.
    """

    portal_url = getToolByName(context, 'portal_url')

    if not relativeRoot:
        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')
        relativeRoot = navtree_properties.getProperty('root', None)

    portal = portal_url.getPortalObject()
    obj = context
    while (not ISubsiteEnhanced.providedBy(obj)
           and aq_base(obj) is not aq_base(portal)):
        # XXX a bit ugly: if this method is called with a context from inside
        # the portal_factory, we cannot use the parent() method, as it calls
        # aq_parent on aq_inner of the object. This directly returns the main
        # portal
        if IFactoryTool.providedBy(obj):
            obj = aq_parent(obj)
        else:
            obj = utils.parent(obj)
    if (ISubsiteEnhanced.providedBy(obj)
        and aq_base(obj) is not aq_base(portal)):
        return '/'.join(obj.getPhysicalPath())

    rootPath = relativeRoot
    portalPath = portal_url.getPortalPath()
    # contextPath = '/'.join(context.getPhysicalPath())

    if rootPath:
        if rootPath == '/':
            return portalPath
        else:
            if len(rootPath) > 1 and rootPath[0] == '/':
                return portalPath + rootPath
            else:
                return portalPath

    # Fall back on the portal root
    if not rootPath:
        return portalPath
Exemplo n.º 2
0
    def url(self):
        """
        Return the url to the main FOP site for this member state

        This is set on the canonical member state only
        """
        context = self.context
        request = self.request
        osha_view = getMultiAdapter((context, request), name=u'oshaview')
        subsite_root = context.restrictedTraverse(osha_view.subsiteRootPath())

        # if the context isn't a subsite then subsite_root will be the
        # portal root
        if not ISubsiteEnhanced.providedBy(subsite_root):
            return

        canonical_member_state = subsite_root.getCanonical()
        try:
            right_portlets = assignment_mapping_from_key(
                canonical_member_state, 'plone.rightcolumn', CONTEXT_CATEGORY,
                "/".join(canonical_member_state.getPhysicalPath())
                )
        except ComponentLookupError:
            return
        if "fop-main-site" in right_portlets.keys():
            return right_portlets["fop-main-site"].url
Exemplo n.º 3
0
 def getCurrentSubsite(self):
     """ returns the subsite in the current path if we are inside one.
         None otherwise """
     PARENTS = self.request.PARENTS
     for parent in PARENTS:
         if ISubsiteEnhanced.providedBy(parent):
             return parent
     return None
Exemplo n.º 4
0
    def languages(self):
        context = aq_inner(self.context)
        results = super(OSHALanguageSelector, self).languages()
        supported_langs = [v['code'] for v in results]
        missing = set([str(c) for c in supported_langs])
        translations = self._translations(missing)
        # On the main portal, we want to be able to filter out unwanted
        # languages needes for subsites
        oshaview = getMultiAdapter((self.context, self.request), name='oshaview')
        subsite_path = oshaview.subsiteRootPath()
        potential_subsite = self.context.restrictedTraverse(subsite_path)
        append_path = self._findpath(context.getPhysicalPath(),
                                     self.request.get('PATH_INFO', ''))
        formvariables = self._formvariables(self.request.form)
        _checkPermission = getSecurityManager().checkPermission

        # only interesting on the main portal
        # or on subsites without their own language tool
        if not ISubsiteEnhanced.providedBy(potential_subsite) \
            or (ISubsiteEnhanced.providedBy(potential_subsite) \
                and not getattr(aq_base(potential_subsite), 'portal_languages', None)):
            portal_properties = getToolByName(self.context, 'portal_properties')
            site_properties = getattr(portal_properties, 'site_properties')
            languages_on_main_site = getattr(site_properties, 'languages_on_main_site', None)
            if languages_on_main_site:
                results = [x for x in results if x['code'] in languages_on_main_site]

        # Starting here, we just copy from LinguaPlone
        non_viewable = set()
        for data in results:
            code = str(data['code'])
            data['translated'] = code in translations.keys()
            set_language = '?set_language=%s' % code

            try:
                appendtourl = '/'.join(append_path)
                if self.set_language:
                    appendtourl += '?' + make_query(formvariables,
                                                    dict(set_language=code))
                elif formvariables:
                    appendtourl += '?' + make_query(formvariables)
            except UnicodeError:
                appendtourl = '/'.join(append_path)
                if self.set_language:
                    appendtourl += set_language

            if data['translated']:
                trans, direct, has_view_permission = translations[code]
                if not has_view_permission:
                    # shortcut if the user cannot see the item
                    non_viewable.add((data['code']))
                    continue

                state = getMultiAdapter((trans, self.request),
                        name='plone_context_state')
                if direct:
                    data['url'] = state.canonical_object_url() + appendtourl
                else:
                    data['url'] = state.canonical_object_url() + set_language
            else:
                has_view_permission = bool(_checkPermission('View', context))
                # Ideally, we should also check the View permission of default
                # items of folderish objects.
                # However, this would be expensive at it would mean that the
                # default item should be loaded as well.
                #
                # IOW, it is a conscious decision to not take in account the
                # use case where a user has View permission a folder but not on
                # its default item.
                if not has_view_permission:
                    non_viewable.add((data['code']))
                    continue

                state = getMultiAdapter((context, self.request),
                        name='plone_context_state')
                try:
                    data['url'] = state.canonical_object_url() + appendtourl
                except AttributeError:
                    data['url'] = context.absolute_url() + appendtourl

        # filter out non-viewable items
        results = [r for r in results if r['code'] not in non_viewable]
        return results
Exemplo n.º 5
0
    def languages(self):
        context = aq_inner(self.context)
        results = super(OSHALanguageSelector, self).languages()
        supported_langs = [v['code'] for v in results]
        missing = set([str(c) for c in supported_langs])
        translations = self._translations(missing)
        # On the main portal, we want to be able to filter out unwanted
        # languages needes for subsites
        oshaview = getMultiAdapter((self.context, self.request),
                                   name='oshaview')
        subsite_path = oshaview.subsiteRootPath()
        potential_subsite = self.context.restrictedTraverse(subsite_path)
        append_path = self._findpath(context.getPhysicalPath(),
                                     self.request.get('PATH_INFO', ''))
        formvariables = self._formvariables(self.request.form)
        _checkPermission = getSecurityManager().checkPermission

        # only interesting on the main portal
        # or on subsites without their own language tool
        if not ISubsiteEnhanced.providedBy(potential_subsite) \
            or (ISubsiteEnhanced.providedBy(potential_subsite) \
                and not getattr(aq_base(potential_subsite), 'portal_languages', None)):
            portal_properties = getToolByName(self.context,
                                              'portal_properties')
            site_properties = getattr(portal_properties, 'site_properties')
            languages_on_main_site = getattr(site_properties,
                                             'languages_on_main_site', None)
            if languages_on_main_site:
                results = [
                    x for x in results if x['code'] in languages_on_main_site
                ]

        # Starting here, we just copy from LinguaPlone
        non_viewable = set()
        for data in results:
            code = str(data['code'])
            data['translated'] = code in translations.keys()
            set_language = '?set_language=%s' % code

            try:
                appendtourl = '/'.join(append_path)
                if self.set_language:
                    appendtourl += '?' + make_query(formvariables,
                                                    dict(set_language=code))
                elif formvariables:
                    appendtourl += '?' + make_query(formvariables)
            except UnicodeError:
                appendtourl = '/'.join(append_path)
                if self.set_language:
                    appendtourl += set_language

            if data['translated']:
                trans, direct, has_view_permission = translations[code]
                if not has_view_permission:
                    # shortcut if the user cannot see the item
                    non_viewable.add((data['code']))
                    continue

                state = getMultiAdapter((trans, self.request),
                                        name='plone_context_state')
                if direct:
                    data['url'] = state.canonical_object_url() + appendtourl
                else:
                    data['url'] = state.canonical_object_url() + set_language
            else:
                has_view_permission = bool(_checkPermission('View', context))
                # Ideally, we should also check the View permission of default
                # items of folderish objects.
                # However, this would be expensive at it would mean that the
                # default item should be loaded as well.
                #
                # IOW, it is a conscious decision to not take in account the
                # use case where a user has View permission a folder but not on
                # its default item.
                if not has_view_permission:
                    non_viewable.add((data['code']))
                    continue

                state = getMultiAdapter((context, self.request),
                                        name='plone_context_state')
                try:
                    data['url'] = state.canonical_object_url() + appendtourl
                except AttributeError:
                    data['url'] = context.absolute_url() + appendtourl

        # filter out non-viewable items
        results = [r for r in results if r['code'] not in non_viewable]
        return results
Exemplo n.º 6
0
 def isSubsite(self, site):
     return ISubsiteEnhanced.providedBy(site)