Exemple #1
0
    def update(self):
        context=aq_inner(self.context)
        contextUrl=context.absolute_url()
        navroot=self.getRoot()
        navrootPath="/".join(navroot.getPhysicalPath())
        portal_properties=getToolByName(self.context, "portal_properties")
        use_view_types=portal_properties.site_properties.typesUseViewActionInListings

        query={}
        query["path"]=dict(query=navrootPath, depth=1)
        query["portal_type"]=typesToList(context)
        query["sort_on"]="getObjPositionInParent"
        query["sort_order"]="asc"
        query["is_default_page"]=False

        catalog=getToolByName(context, "portal_catalog")
        results=[{"id" : brain.id,
                  "title" : brain.Title,
                  "url" : "%s/view" % brain.getURL() if brain.portal_type in use_view_types else brain.getURL(),
                  "class" : None}
                 for brain in catalog.searchResults(query)
                 if not brain.exclude_from_nav]
        current=[(len(result["url"]), result["id"]) for result in results
                 if contextUrl.startswith(result["url"])]
        current.sort()
        if current:
            current=current[0][1]
            for result in results:
                if result["id"]==current:
                    result["class"]="current"
                    break

        self.tabs=results
        self.home_url=navroot.absolute_url()
 def items(self):
     if hasattr(self, '_items'):
         return self._items
     ret = list()
     context = aq_inner(self.context)
     brains = self.context.portal_catalog({
         'portal_type': typesToList(self.context),
         'sort_on': 'getObjPositionInParent',
         'path': {
             'query': '/'.join(self.context.getPhysicalPath()),
             'depth': 1,
         },
         'Language': 'all',
     })
     # plone_layout not available in plone3
     #layout = getMultiAdapter((context, self.request), name=u'plone_layout')
     for brain in brains:
         icon = getMultiAdapter((self.context, self.request, brain),
                                IContentIcon)
         #icon = layout.getIcon(brain)
         uid = brain.UID
         if not uid:
             # don't display items without UID
             continue
         cut = self.request.cookies.get('__fct') == uid
         ret.append(nav_item(item_id(uid),
                             icon.url,
                             brain.Title and brain.Title or brain.id,
                             brain.is_folderish, 
                             self._item_selected(brain.getURL()),
                             brain.review_state,
                             cut,
                             default_type_css(brain.portal_type)))
     self._items = ret
     return ret
Exemple #3
0
    def __call__(self):
        context = self.context

        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        query = {}

        # Construct the path query

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

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        if not currentPath.startswith(rootPath):
            query['path'] = {'query': rootPath, 'depth': 1}
        else:
            query['path'] = {'query': currentPath, 'navtree': 1}

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        return query
    def __call__(self):
        context = self.context

        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        query = {}

        # Construct the path query

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

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        if not currentPath.startswith(rootPath):
            query['path'] = {'query': rootPath, 'depth': 1}
        else:
            query['path'] = {'query': currentPath, 'navtree': 1}

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        return query
 def __call__(self, *args, **kwargs):
     ctx = self.context
     url = None
     if not self.permitted():
         types_to_list = utils.typesToList(ctx)
         plt = getToolByName(self.context, "portal_languages")
         pref_lang = plt.getPreferredLanguage()
         ctx = self.find_endpoint(ctx, pref_lang, types_to_list)
     url = ctx.absolute_url()
     if ctx.defaultView() == "traverse_view":
         if not self.permitted(context=ctx):
             # Not allowed to list folder contents. Show fallback.
             url = "%s/%s" % (url, NON_TRAVERSE_FALLBACK_VIEW)
         else:
             # List folder contents permitted. Show folder_contents.
             url = "%s/folder_contents" % url
             messages = IStatusMessage(self.request)
             messages.addStatusMessage(
                 _(
                     "traverse_view-statusmessage",
                     u"""This is a traverse view. Users who are not allowed to
                       see the folder listing are redirected to the first
                       subitem in this directory.""",
                 ),
                 type="info",
             )
     raise Redirect(url)
    def __init__(self, context, portlet):
        self.context = context
        self.portlet = portlet

        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        # Acquire a custom nav query if available
        customQuery = getattr(context, 'getCustomNavQuery', None)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        # Construct the path query
        root = uuidToObject(portlet.root_uid)
        if root is not None:
            rootPath = '/'.join(root.getPhysicalPath())
        else:
            rootPath = getNavigationRoot(context)
        currentPath = '/'.join(context.getPhysicalPath())

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        if currentPath != rootPath and not currentPath.startswith(rootPath + '/'):
            query['path'] = {'query': rootPath, 'depth': 1}
        else:
            query['path'] = {'query': currentPath, 'navtree': 1}

        topLevel = portlet.topLevel
        if topLevel and topLevel > 0:
            query['path']['navtree_start'] = topLevel + 1

        # XXX: It'd make sense to use 'depth' for bottomLevel, but it doesn't
        # seem to work with EPI.

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        # Filter on workflow states, if enabled
        registry = getUtility(IRegistry)
        navigation_settings = registry.forInterface(
            INavigationSchema,
            prefix="plone"
        )
        if navigation_settings.filter_on_workflow:
            query['review_state'] = navigation_settings.workflow_states_to_show

        self.query = query
Exemple #7
0
    def __init__(self, context, data):
        self.context = context
        self.data = data

        portal_properties = getToolByName(context, "portal_properties")
        navtree_properties = getattr(portal_properties, "navtree_properties")

        # Acquire a custom nav query if available
        customQuery = getattr(context, "getCustomNavQuery", None)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        # Construct the path query
        root = get_root(context, data.root_path)
        if root is not None:
            rootPath = "/".join(root.getPhysicalPath())
        else:
            rootPath = getNavigationRoot(context)

        currentPath = "/".join(context.getPhysicalPath())

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        if currentPath != rootPath and not currentPath.startswith(rootPath +
                                                                  "/"):
            query["path"] = {"query": rootPath, "depth": 1}
        else:
            query["path"] = {"query": currentPath, "navtree": 1}

        topLevel = data.topLevel
        if topLevel and topLevel > 0:
            query["path"]["navtree_start"] = topLevel + 1

        # XXX: It'd make sense to use 'depth' for bottomLevel, but it doesn't
        # seem to work with EPI.

        # Only list the applicable types
        query["portal_type"] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty("sortAttribute", None)
        if sortAttribute is not None:
            query["sort_on"] = sortAttribute
            sortOrder = navtree_properties.getProperty("sortOrder", None)
            if sortOrder is not None:
                query["sort_order"] = sortOrder

        # Filter on workflow states, if enabled
        registry = getUtility(IRegistry)
        navigation_settings = registry.forInterface(INavigationSchema,
                                                    prefix="plone")
        if navigation_settings.filter_on_workflow:
            query["review_state"] = navigation_settings.workflow_states_to_show

        self.query = query
Exemple #8
0
    def __init__(self, context, portlet):
        self.context = context
        self.portlet = portlet

        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        # Acquire a custom nav query if available
        customQuery = getattr(context, 'getCustomNavQuery', None)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        # Construct the path query
        root = uuidToObject(portlet.root_uid)
        if root is not None:
            rootPath = '/'.join(root.getPhysicalPath())
        else:
            rootPath = getNavigationRoot(context)
        currentPath = '/'.join(context.getPhysicalPath())

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        if currentPath != rootPath and not currentPath.startswith(rootPath +
                                                                  '/'):
            query['path'] = {'query': rootPath, 'depth': 1}
        else:
            query['path'] = {'query': currentPath, 'navtree': 1}

        topLevel = portlet.topLevel
        if topLevel and topLevel > 0:
            query['path']['navtree_start'] = topLevel + 1

        # XXX: It'd make sense to use 'depth' for bottomLevel, but it doesn't
        # seem to work with EPI.

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        # Filter on workflow states, if enabled
        registry = getUtility(IRegistry)
        navigation_settings = registry.forInterface(INavigationSchema,
                                                    prefix="plone")
        if navigation_settings.filter_on_workflow:
            query['review_state'] = navigation_settings.workflow_states_to_show

        self.query = query
    def __init__(self, context, portlet):
        self.context = context
        self.portlet = portlet
        
        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')
        
        portal_url = getToolByName(context, 'portal_url')
        
        # Acquire a custom nav query if available
        customQuery = getattr(context, 'getCustomNavQuery', None)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        # Construct the path query

        rootPath = getNavigationRoot(context, relativeRoot=portlet.root)
        currentPath = '/'.join(context.getPhysicalPath())

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        if not currentPath.startswith(rootPath):
            query['path'] = {'query' : rootPath, 'depth' : 1}
        else:
            query['path'] = {'query' : currentPath, 'navtree' : 1}

        topLevel = portlet.topLevel or navtree_properties.getProperty('topLevel', 0)
        if topLevel and topLevel > 0:
             query['path']['navtree_start'] = topLevel + 1

        # XXX: It'd make sense to use 'depth' for bottomLevel, but it doesn't
        # seem to work with EPI.

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        # Filter on workflow states, if enabled
        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty('wf_states_to_show', ())

        ############# Added by expanding navigation
        query['path']['navtree']=''
        query['path']['query']=''
        ############# End added

        self.query = query
Exemple #10
0
    def __init__(self, context, portlet):
        self.context = context
        self.portlet = portlet

        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        portal_url = getToolByName(context, 'portal_url')

        portal_languages = getToolByName(context, 'portal_languages')

        # Acquire a custom nav query if available
        customQuery = getattr(context, 'getCustomNavQuery', None)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}
        #import pdb;pdb.set_trace()
        # Construct the path query
        preferred_path = "/%s" % portal_languages.getPreferredLanguage()

        rootPathX = getNavigationRoot(context, relativeRoot=portlet.root)
        rootPathY = getNavigationRoot(context, relativeRoot=preferred_path)

        rootPath = portal_url.getPortalPath()+preferred_path

        print "X: portlet.root based. rootPath: %s, portlet.root: %s" %(rootPathX, portlet.root)
        print "Y: preferred_path based. rootPath: %s, preferred_path: %s" %(rootPathY, preferred_path)
        print "Current: rootPath+preferred_path: %s %s" %(rootPath, preferred_path)

        currentPath = '/'.join(context.getPhysicalPath())

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        query['path'] = {'query' : rootPath, 'navtree' : 1, 'navtree_start': 1}

        topLevel = portlet.topLevel or navtree_properties.getProperty('topLevel', 0)
        topLevel = 0

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        # Filter on workflow states, if enabled
        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty('wf_states_to_show', ())

        self.query = query
Exemple #11
0
    def getRootTabs(self):
        """See interface"""
        context = aq_inner(self.context)

        portal_catalog = getToolByName(context, 'portal_catalog')
        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        # Build result dict
        result = []

        # check whether tabs autogeneration is turned on
        if not self.isGeneratedTabs():
            return result

        query = {}
        rootPath = getNavigationRoot(context)
        query['path'] = {'query' : rootPath, 'depth' : 1}
        query['portal_type'] = utils.typesToList(context)

        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute

            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty(
                'wf_states_to_show', [])

        query['is_default_page'] = False

        if not self.isNotFoldersGenerated():
            query['is_folderish'] = True

        # Get ids not to list and make a dict to make the search fast
        idsNotToList = navtree_properties.getProperty('idsNotToList', ())
        excludedIds = {}
        for id in idsNotToList:
            excludedIds[id]=1

        rawresult = portal_catalog.searchResults(**query)

        # now add the content to results
        for item in rawresult:
            if not excludedIds.has_key(item.getId):
                id, item_url = get_view_url(item)
                data = {'name'       : utils.pretty_title_or_id(context, item),
                        'id'         : id,
                        'url'        : item_url,
                        'description': item.Description,
                        'exclude_from_nav' : item.exclude_from_nav}
                result.append(data)

        return result
    def __init__(self, context, portlet):
        self.context = context
        self.portlet = portlet

        portal_url = getToolByName(context, 'portal_url')
        portal = portal_url.getPortalObject()
        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')
        pm = getToolByName(portal,'portal_membership')
        user = pm.getAuthenticatedMember()
        
        # Acquire a custom nav query if available
        customQuery = getattr(context, 'getCustomNavQuery', None)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        # Construct the path query
        if hasattr(portlet, 'root'):
            root = portlet.root
        else:
            root = uuidToObject(portlet.root_uid)
        rootPath = getNavigationRoot(context, relativeRoot=root)
        currentPath = '/'.join(context.getPhysicalPath())

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        query['path'] = {'query' : rootPath, 'depth' : 2}

        topLevel = portlet.topLevel or navtree_properties.getProperty('topLevel', 0)
        if topLevel and topLevel > 0:
             query['path']['navtree_start'] = topLevel + 1

        # XXX: It'd make sense to use 'depth' for bottomLevel, but it doesn't
        # seem to work with EPI.

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        # Filter on workflow states, if enabled
        if not user or not user.has_permission('List folder contents', self.context):
            if navtree_properties.getProperty('enable_wf_state_filtering', False):
                query['review_state'] = navtree_properties.getProperty('wf_states_to_show', ())

        self.query = query
    def getsubtab(self, context, tab):
        query = {}
        result = []
        portal_properties = getToolByName(context, "portal_properties")
        portal_catalog = getToolByName(context, "portal_catalog")
        navtree_properties = getattr(portal_properties, "navtree_properties")
        site_properties = getattr(portal_properties, "site_properties")

        rootPath = getNavigationRoot(context)
        xpath = "/".join([rootPath, tab["id"]])
        if "path" in tab:
            xpath = tab["path"]
        query["path"] = {"query": xpath, "depth": 1}

        query["portal_type"] = utils.typesToList(context)

        sortAttribute = navtree_properties.getProperty("sortAttribute", None)
        if sortAttribute is not None:
            query["sort_on"] = sortAttribute

            sortOrder = navtree_properties.getProperty("sortOrder", None)
            if sortOrder is not None:
                query["sort_order"] = sortOrder

        if navtree_properties.getProperty("enable_wf_state_filtering", False):
            query["review_state"] = navtree_properties.getProperty("wf_states_to_show", [])

        # Get ids not to list
        idsNotToList = navtree_properties.getProperty("idsNotToList", ())
        excludedIds = {}
        for id in idsNotToList:
            excludedIds[id] = 1

        rawresult = portal_catalog.searchResults(**query)

        # now add the content to results
        for item in rawresult:
            if not (excludedIds.has_key(item.getId) or item.exclude_from_nav):
                id, item_url = get_view_url(item)
                data = {
                    "name": utils.pretty_title_or_id(context, item),
                    "id": item.getId,
                    "url": item_url,
                    "description": item.Description,
                    "current": "",
                    "path": item.getPath(),
                }
                if self.current_url.startswith(item_url):
                    data["current"] = "selected"
                data["subtabs"] = self.getsubtab(self.context, data)
                result.append(data)
        return result
    def getsubtab(self, context, tab):
        query = {}
        result = []
        portal_properties = getToolByName(context, 'portal_properties')
        portal_catalog = getToolByName(context, 'portal_catalog')
        navtree_properties = getattr(portal_properties, 'navtree_properties')
        site_properties = getattr(portal_properties, 'site_properties')

        rootPath = getNavigationRoot(context)
        dpath = '/'.join([rootPath, tab['id']])
        query['path'] = {'query': dpath, 'depth': 1}

        query['portal_type'] = utils.typesToList(context)

        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute

            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty(
                'wf_states_to_show', [])

        query['is_default_page'] = False

        if site_properties.getProperty('disable_nonfolderish_sections', False):
            query['is_folderish'] = True

        # Get ids not to list and make a dict to make the search fast
        idsNotToList = navtree_properties.getProperty('idsNotToList', ())
        excludedIds = {}
        for id in idsNotToList:
            excludedIds[id] = 1

        rawresult = portal_catalog.searchResults(**query)

        # now add the content to results
        for item in rawresult:
            if not (excludedIds.has_key(item.getId) or item.exclude_from_nav):
                id, item_url = get_view_url(item)
                data = {
                    'name': utils.pretty_title_or_id(context, item),
                    'id': item.getId,
                    'url': item_url,
                    'description': item.Description
                }
                result.append(data)
        return result
    def getsubtab(self, context, tab):
        query = {}
        result = []
        portal_properties = getToolByName(context, "portal_properties")
        portal_catalog = getToolByName(context, "portal_catalog")
        navtree_properties = getattr(portal_properties, "navtree_properties")
        site_properties = getattr(portal_properties, "site_properties")

        rootPath = getNavigationRoot(context)
        dpath = "/".join([rootPath, tab["id"]])
        query["path"] = {"query": dpath, "depth": 1}

        query["portal_type"] = utils.typesToList(context)

        sortAttribute = navtree_properties.getProperty("sortAttribute", None)
        if sortAttribute is not None:
            query["sort_on"] = sortAttribute

            sortOrder = navtree_properties.getProperty("sortOrder", None)
            if sortOrder is not None:
                query["sort_order"] = sortOrder

        if navtree_properties.getProperty("enable_wf_state_filtering", False):
            query["review_state"] = navtree_properties.getProperty("wf_states_to_show", [])

        query["is_default_page"] = False

        if site_properties.getProperty("disable_nonfolderish_sections", False):
            query["is_folderish"] = True

        # Get ids not to list and make a dict to make the search fast
        idsNotToList = navtree_properties.getProperty("idsNotToList", ())
        excludedIds = {}
        for id in idsNotToList:
            excludedIds[id] = 1

        rawresult = portal_catalog.searchResults(**query)

        # now add the content to results
        for item in rawresult:
            if not (excludedIds.has_key(item.getId) or item.exclude_from_nav):
                id, item_url = get_view_url(item)
                data = {
                    "name": utils.pretty_title_or_id(context, item),
                    "id": item.getId,
                    "url": item_url,
                    "description": item.Description,
                }
                result.append(data)
        return result
Exemple #16
0
    def __init__(self, context):
        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        # Acquire a custom nav query if available
        customQuery = getattr(context, 'getCustomNavQuery', None)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        # Construct the path query

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

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        if not currentPath.startswith(rootPath):
            query['path'] = {'query': rootPath, 'depth': 1}
        else:
            query['path'] = {'query': currentPath, 'navtree': 1}

        topLevel = navtree_properties.getProperty('topLevel', 0)
        if topLevel and topLevel > 0:
            query['path']['navtree_start'] = topLevel + 1

        # XXX: It'd make sense to use 'depth' for bottomLevel, but it doesn't
        # seem to work with EPI.

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        # Filter on workflow states, if enabled
        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = \
                navtree_properties.getProperty('wf_states_to_show', ())

        self.query = query
    def __init__(self, context):
        registry = getUtility(IRegistry)
        navigation_settings = registry.forInterface(INavigationSchema,
                                                    prefix="plone")

        # Acquire a custom nav query if available
        customQuery = getattr(context, 'getCustomNavQuery', None)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        # Construct the path query

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

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        if not currentPath.startswith(rootPath):
            query['path'] = {'query': rootPath, 'depth': 1}
        else:
            query['path'] = {'query': currentPath, 'navtree': 1}

        query['path']['navtree_start'] = 0

        # XXX: It'd make sense to use 'depth' for bottomLevel, but it doesn't
        # seem to work with EPI.

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navigation_settings.sort_tabs_on
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            if navigation_settings.sort_tabs_reversed:
                query['sort_order'] = 'desc'
            else:
                query['sort_order'] = 'asc'

        # Filter on workflow states, if enabled
        if navigation_settings.filter_on_workflow:
            query['review_state'] = navigation_settings.workflow_states_to_show

        self.query = query
    def __init__(self, context):
        registry = getUtility(IRegistry)
        navigation_settings = registry.forInterface(INavigationSchema,
                                                    prefix="plone")

        # Acquire a custom nav query if available
        customQuery = getattr(context, 'getCustomNavQuery', None)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        # Construct the path query

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

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        if not currentPath.startswith(rootPath):
            query['path'] = {'query': rootPath, 'depth': 1}
        else:
            query['path'] = {'query': currentPath, 'navtree': 1}

        query['path']['navtree_start'] = 0

        # XXX: It'd make sense to use 'depth' for bottomLevel, but it doesn't
        # seem to work with EPI.

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navigation_settings.sort_tabs_on
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            if navigation_settings.sort_tabs_reversed:
                query['sort_order'] = 'desc'
            else:
                query['sort_order'] = 'asc'

        # Filter on workflow states, if enabled
        if navigation_settings.filter_on_workflow:
            query['review_state'] = navigation_settings.workflow_states_to_show

        self.query = query
    def getsubtabs(self,context,tab):
        query={}
        result=[]
        portal_properties = getToolByName(context, 'portal_properties')
        portal_catalog = getToolByName(context, 'portal_catalog')
        navtree_properties = getattr(portal_properties, 'navtree_properties')
        site_properties = getattr(portal_properties, 'site_properties')

        rootPath = getNavigationRoot(context)
        dpath='/'.join([rootPath,tab['id']])
        query['path'] = {'query' : dpath, 'depth' : 1}

        query['portal_type'] = utils.typesToList(context)

        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute

            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty('wf_states_to_show', [])

        query['is_default_page'] = False

        if site_properties.getProperty('disable_nonfolderish_sections', False):
            query['is_folderish'] = True

        # Get ids not to list and make a dict to make the search fast
        idsNotToList = navtree_properties.getProperty('idsNotToList', ())
        excludedIds = {}
        for id in idsNotToList:
            excludedIds[id]=1

        rawresult = portal_catalog.searchResults(**query)

        # now add the content to results
        for item in rawresult:
            if not (excludedIds.has_key(item.getId) or item.exclude_from_nav):
                id, item_url = get_view_url(item)
                data = {'name'      : utils.pretty_title_or_id(context, item),
                        'id'         : item.getId,
                        'url'        : item_url,
                        'description': item.Description}
                result.append(data)
        return result
Exemple #20
0
    def getRootTabs(self):
        """See interface"""
        context = aq_inner(self.context)

        portal_catalog = getToolByName(context, 'portal_catalog')
        portal_properties = self.portal_properties
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        # Build result dict
        result = []

        # check whether tabs autogeneration is turned on
        if not self.isGeneratedTabs():
            return result

        query = {}
        rootPath = getNavigationRoot(context)
        query['path'] = {'query': rootPath, 'depth': 1}
        query['portal_type'] = utils.typesToList(context)

        self._add_sort_option(query)

        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty(
                'wf_states_to_show', [])

        query['is_default_page'] = False

        if not self.isNotFoldersGenerated():
            query['is_folderish'] = True

        # Get ids not to list and make a dict to make the search fast
        idsNotToList = navtree_properties.getProperty('idsNotToList', ())
        excludedIds = {}
        for id in idsNotToList:
            excludedIds[id] = 1

        rawresult = portal_catalog.searchResults(**query)

        # now add the content to results
        for item in rawresult:
            if item.getId not in excludedIds:
                result.append(self.getItem(item))

        return result
    def getRootTabs(self):
        """See interface"""
        context = aq_inner(self.context)

        portal_catalog = getToolByName(context, 'portal_catalog')
        portal_properties = self.portal_properties
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        # Build result dict
        result = []

        # check whether tabs autogeneration is turned on
        if not self.isGeneratedTabs():
            return result

        query = {}
        rootPath = getNavigationRoot(context)
        query['path'] = {'query': rootPath, 'depth': 1}
        query['portal_type'] = utils.typesToList(context)

        self._add_sort_option(query)

        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty(
                'wf_states_to_show', [])

        query['is_default_page'] = False

        if not self.isNotFoldersGenerated():
            query['is_folderish'] = True

        # Get ids not to list and make a dict to make the search fast
        idsNotToList = navtree_properties.getProperty('idsNotToList', ())
        excludedIds = {}
        for id in idsNotToList:
            excludedIds[id] = 1

        rawresult = portal_catalog.searchResults(**query)

        # now add the content to results
        for item in rawresult:
            if item.getId not in excludedIds:
                result.append(self.getItem(item))

        return result
Exemple #22
0
    def update_items(self):
        """Find the items that are to be part of the navigation. 
        This is basically just a catalog search and then remove the items that are to be 
        excluded from navigation.
        """
        context = self.context
        catalog = getToolByName(context, "portal_catalog")
        portal_properties = getToolByName(context, "portal_properties")
        navtree_properties = getattr(portal_properties, "navtree_properties")

        # build query
        query = {}
        query["portal_type"] = utils.typesToList(context)
        # display viewlet only on 4th level and deeper (1st - zope itself, 2nd - plone site, 3d - root lingua plone folders (ru, de, etc.) )
        path = context.getPhysicalPath()
        if len(path) < 4:
            return []
        else:
            # 4th level container
            path = path[0:4]

        query["path"] = {"query": "/".join(path), "depth": 1}

        # Make sure the sorting is correct.
        sortAttribute = navtree_properties.getProperty("sortAttribute", None)
        if sortAttribute is not None:
            query["sort_on"] = sortAttribute

            sortOrder = navtree_properties.getProperty("sortOrder", None)
            if sortOrder is not None:
                query["sort_order"] = sortOrder

        # Do not include the default pages
        query["is_default_page"] = False

        results = catalog.searchResults(query)

        # Only add the items that are not excluded from navigation.
        brains = []
        for result in results:
            if not result.exclude_from_nav:
                brains.append(result)

        return brains
Exemple #23
0
    def update(self):
        context = aq_inner(self.context)
        contextUrl = context.absolute_url()
        navroot = self.getRoot()
        navrootPath = "/".join(navroot.getPhysicalPath())
        use_view_types = api.portal.get_registry_record(
            "plone.types_use_view_action_in_listings", default=[]
        )
        query = {}
        query["path"] = dict(query=navrootPath, depth=1)
        query["portal_type"] = typesToList(context)
        query["sort_on"] = "getObjPositionInParent"
        query["sort_order"] = "asc"
        query["is_default_page"] = False

        catalog = getToolByName(context, "portal_catalog")
        results = [
            {
                "id": brain.id,
                "title": brain.Title,
                "url": "%s/view" % brain.getURL()
                if brain.portal_type in use_view_types
                else brain.getURL(),
                "class": None,
            }
            for brain in catalog.searchResults(query)
            if not brain.exclude_from_nav
        ]
        current = sorted(
            [
                (len(result["url"]), result["id"])
                for result in results
                if contextUrl.startswith(result["url"])
            ]
        )
        if current:
            current = current[0][1]
            for result in results:
                if result["id"] == current:
                    result["class"] = "current"
                    break

        self.tabs = results
        self.home_url = navroot.absolute_url()
Exemple #24
0
 def typesToList(self):
     return utils.typesToList(self)
Exemple #25
0
 def typesToList(self):
     return utils.typesToList(self)
Exemple #26
0
    def __init__(self, context, portlet):
        #import pdb;pdb.set_trace()
        #base.__init__(self,context,portlet)
        self.context = context
        self.portlet = portlet

        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        portal_url = getToolByName(context, 'portal_url')

        # Acquire a custom nav query if available
        customQuery = getattr(context, 'getCustomNavQuery', None)
        #if customQuery is None:
        #    customQuery = {'path':{'query':'/'.join(context.getPhysicalPath()),'depth':1},'portal_type':'Space'}
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        # Construct the path query

        rootPath = getNavigationRoot(context, relativeRoot=portlet.root)
        currentPath = '/'.join(context.getPhysicalPath())


        #custom implementation starts here
        currentObject = self.context
        parentList = currentObject.aq_chain
        parentspace = None
        found = 0

        try:
            for type in parentList:
                if type.portal_type == 'Space' and type.meta_type == 'Space':
                    parentspace = type
                    found = 1
                if found == 1:
                    break
        except AttributeError:
                pass

        rootObject = self.context.portal_url.getPortalObject()

        objNavtree = 1
        if parentspace <> None:
            parentList.reverse()
            pos_parentspace = parentList.index(parentspace)
            pos_root = parentList.index(rootObject)
            objNavtree = pos_parentspace - pos_root
            parentList.reverse()

        isMemberFolder = False
        members = rootObject.Members

        if parentspace is None:
            if members in parentList:
                isMemberFolder = True
                parentList.reverse()
                objNavtree = 2
                parentList.reverse()
        #custom implementation ends here.

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.        
        #import pdb;pdb.set_trace()
        if not currentPath.startswith(rootPath):
            if not rootPath.endswith('/Members'):
                query['path'] = {'query' : rootPath, 'depth' : 1}
            else:
                query['path'] = {'query' : rootPath, 'depth' : 0}
            if portlet.root == '/' + members.id and self.context == rootObject and len(self.context.REQUEST.steps) > 0 and self.context.REQUEST.steps[-1] in ('author','personalize_form',):                
                traverse_subpath = self.context.REQUEST.traverse_subpath
                if len(traverse_subpath) > 0:
                    userid = traverse_subpath[0]                    
                else:
                    currentuser = getSecurityManager().getUser()
                    if currentuser <> None:
                        userid = currentuser.getId()
                if userid <> None:
                    currentPath = "/".join(rootObject.getPhysicalPath()) + "/" + members.id + "/" + userid
                    query['path'] = {'query': currentPath, 'navtree': 2}
        elif parentspace <> None:
            query['path'] = {'query': currentPath, 'navtree': objNavtree}
        elif isMemberFolder == True:
            if self.context == members:
                query['path'] = {'query' : currentPath, 'depth' : 0}
            else:
                query['path'] = {'query': currentPath, 'navtree': objNavtree}        
        else:
            query['path'] = {'query' : currentPath, 'navtree' : 1}

        if parentspace <> None:
            pass
        else:
            topLevel = portlet.topLevel or navtree_properties.getProperty('topLevel', 0)
            if topLevel and topLevel > 0:
                query['path']['navtree_start'] = topLevel + 1

        # XXX: It'd make sense to use 'depth' for bottomLevel, but it doesn't
        # seem to work with EPI.

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        # Filter on workflow states, if enabled
        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty('wf_states_to_show', ())        
        #import pdb;pdb.set_trace()
        self.query = query
Exemple #27
0
    def __init__(self, context, portlet):
        self.context = context
        self.portlet = portlet

        portal_properties = utils.getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        portal_url = utils.getToolByName(context, 'portal_url')

        # Acquire a custom nav query if available
        customQuery = getattr(context, 'getCustomNavQuery', None)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        # Construct the path query
        root_uid = portlet.root_uid
        topLevel = portlet.topLevel

        if not root_uid:
            override_topLevel = getNavigationTopLevelObject(
                self.context, getSite())
            if override_topLevel:
                topLevel = override_topLevel.portlet_nav_topLevel
            folderRoot = getNavigationFolderObject(context, getSite())
            if folderRoot:
                root_uid = folderRoot.UID()

        root = uuidToObject(root_uid)
        if root is not None:
            rootPath = '/'.join(root.getPhysicalPath())
        else:
            rootPath = getNavigationRoot(context)
        currentPath = '/'.join(context.getPhysicalPath())

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.
        if portlet.displayAsSiteMap:
            siteMapDepth = portlet.siteMapDepth
            if topLevel and topLevel > 0:
                siteMapDepth = siteMapDepth + topLevel

            query['path'] = {'query': rootPath, 'depth': siteMapDepth}
        else:
            if not currentPath.startswith(rootPath):
                query['path'] = {'query': rootPath, 'depth': 1}
            else:
                query['path'] = {'query': currentPath, 'navtree': 1}

        if topLevel and topLevel > 0:
            query['path']['navtree_start'] = topLevel + 1
        # XXX: It'd make sense to use 'depth' for bottomLevel, but it doesn't
        # seem to work with EPI.

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        # Filter on workflow states, if enabled
        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty(
                'wf_states_to_show', ())

        self.query = query
    def __call__(self, *args, **kwargs):
        ctx = self.context
        wft = getToolByName(ctx, 'portal_workflow')
        types = utils.typesToList(ctx)
        url = None

        if not self.permitted:
            def find_endpoint(obj, lang):
                if not IFolder.providedBy(obj) and\
                        not IPloneSiteRoot.providedBy(obj):
                    return obj
                contents = obj.contentIds()
                # TODO: make list reversable
                for id in contents:
                    child = obj[id]
                    # try to get translation if LinguaPlone is installed, child
                    # is translatable and child language does not match lang
                    if LINGUA_PLONE_INSTALLED:
                        if ITranslatable.providedBy(child):
                            child_lang = child.Language()
                            # child lang can be empty string, only try to
                            # translate if explicit lang
                            if child_lang and child_lang != lang:
                                translation = child.getTranslation(lang)
                                if not translation:
                                    continue  # ...with next obj in folder
                                child = translation
                    # only traverse to published objects
                    try:
                        state = wft.getInfoFor(child, 'review_state')
                    except:
                        state = None
                    if not state == 'published':
                        continue
                    # only traverse to objects listed in typesToList
                    if child.portal_type not in types:
                        continue
                    # we've found a published object, which can be used as
                    # possible endpoint, except it has 'traverse_view' enabled
                    obj = child
                    if child.defaultView() == 'traverse_view':
                        obj = find_endpoint(child, lang)
                    break
                return obj
            plt = getToolByName(self.context, 'portal_languages')
            pref_lang = plt.getPreferredLanguage()
            ctx = find_endpoint(ctx, pref_lang)

        url = ctx.absolute_url()
        if ctx.defaultView() == 'traverse_view':
            if not self.permitted:
                # Not allowed to list folder contents. Show fallback.
                url = '%s/%s' % (url, NON_TRAVERSE_FALLBACK_VIEW)
            else:
                # List folder contents permitted. Show folder_contents.
                url = '%s/folder_contents' % url
                messages = IStatusMessage(self.request)
                messages.addStatusMessage(
                    _("traverse_view-statusmessage",
                      u"""This is a traverse view. Users who are not allowed to
                          see the folder listing are redirected to the first
                          subitem in this directory."""),
                     type="info")
        raise Redirect(url)
Exemple #29
0
    def topLevelTabs(self, actions=None, category='portal_tabs'):
        context = aq_inner(self.context)

        portal_catalog = getToolByName(context, 'portal_catalog')
        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')
        site_properties = getattr(portal_properties, 'site_properties')

        # Build result dict
        result = []
        # first the actions
        if actions is not None:
            for actionInfo in actions.get(category, []):
                data = actionInfo.copy()
                data['name'] = data['title']
                result.append(data)

        # check whether we only want actions
        if site_properties.getProperty('disable_folder_sections', False):
            return result

        customQuery = getattr(context, 'getCustomNavQuery', False)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        rootPath = getNavigationRoot(context)
        query['path'] = {'query': rootPath, 'depth': 1}

        query['portal_type'] = utils.typesToList(context)

        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute

            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty(
                'wf_states_to_show', [])

        query['is_default_page'] = False

        if site_properties.getProperty('disable_nonfolderish_sections', False):
            query['is_folderish'] = True

        # Get ids not to list and make a dict to make the search fast
        idsNotToList = navtree_properties.getProperty('idsNotToList', ())
        excludedIds = {}
        for id in idsNotToList:
            excludedIds[id] = 1

        rawresult = portal_catalog.searchResults(**query)

        # now add the content to results
        for item in rawresult:
            if not (excludedIds.has_key(item.getId) or item.exclude_from_nav):
                id, item_url = get_view_url(item)
                data = {
                    'name': utils.pretty_title_or_id(context, item),
                    'id': item.getId,
                    'url': item_url,
                    'description': item.Description
                }
                result.append(data)
        return result
Exemple #30
0
    def topLevelTabs(self, actions=None, category='portal_tabs'):
        context = aq_inner(self.context)

        portal_catalog = getToolByName(context, 'portal_catalog')
        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')
        site_properties = getattr(portal_properties, 'site_properties')

        # Build result dict
        result = []
        # first the actions
        if actions is not None:
            for actionInfo in actions.get(category, []):
                data = actionInfo.copy()
                data['name'] = data['title']
                result.append(data)

        # check whether we only want actions
        if site_properties.getProperty('disable_folder_sections', False):
            return result

        customQuery = getattr(context, 'getCustomNavQuery', False)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        rootPath = getNavigationRoot(context)
        query['path'] = {'query' : rootPath, 'depth' : 1}

        query['portal_type'] = utils.typesToList(context)

        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute

            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty('wf_states_to_show', [])

        query['is_default_page'] = False
        
        if site_properties.getProperty('disable_nonfolderish_sections', False):
            query['is_folderish'] = True

        # Get ids not to list and make a dict to make the search fast
        idsNotToList = navtree_properties.getProperty('idsNotToList', ())
        excludedIds = {}
        for id in idsNotToList:
            excludedIds[id]=1

        rawresult = portal_catalog.searchResults(**query)

        # now add the content to results
        for item in rawresult:
            if not (excludedIds.has_key(item.getId) or item.exclude_from_nav):
                id, item_url = get_view_url(item)
                data = {'name'      : utils.pretty_title_or_id(context, item),
                        'id'         : id,
                        'url'        : item_url,
                        'description': item.Description}
                result.append(data)
        return result
Exemple #31
0
    def build(self, context, request):
        context = aq_inner(context)

        # If we are at a default page use the folder as context for the navtree
        container = aq_parent(context)
        isp = queryMultiAdapter((container, request),
                                name="default_page",
                                default=None)
        if isp is not None and isp.isDefaultPage(context):
            context = container

        contextPath = "/".join(context.getPhysicalPath())
        contextPathLen = len(contextPath)
        parentDepth = (contextPath.count("/") - 1)
        navrootPath = "/".join(getNavigationRoot(context).getPhysicalPath())

        query = {}
        query["path"] = dict(query=contextPath,
                             navtree=True,
                             navtree_start=navrootPath.count("/"))
        query["portal_type"] = typesToList(context)
        query["sort_on"] = "getObjPositionInParent"
        query["sort_order"] = "asc"

        catalog = getToolByName(context, "portal_catalog")
        results = catalog.searchResults(query)
        cache = {}
        cache[navrootPath] = {
            "current": False,
            "currentParent": True,
            "children": []
        }
        for brain in results:
            path = brain.getPath()
            pathLen = len(path)
            parentPath = path.rsplit("/", 1)[0]
            ancestor = current = currentParent = False
            if path == contextPath:
                current = True
            elif contextPathLen > pathLen:
                ancestor = contextPath.startswith(path + "/")
                currentParent = ancestor and path.count("/") == parentDepth

            if brain.exclude_from_nav and not currentParent:
                continue

            oldNode = cache.get(path, None)
            node = {
                "brain": brain,
                "path": path,
                "current": current,
                "currentParent": currentParent,
                "ancestor": ancestor
            }

            oldNode = cache.get(path, None)
            if oldNode is not None:
                oldNode.update(node)
                node = oldNode
            else:
                node["children"] = []
                cache[path] = node

            parentNode = cache.get(parentPath, None)
            if parentNode is None:
                parentNode = cache[parentPath] = dict(children=[node])
            else:
                parentNode["children"].append(node)
            node["parent"] = parentNode

        self.tree = cache
        self.root = cache[navrootPath]
Exemple #32
0
    def build(self, context, request):
        context=aq_inner(context)

        # If we are at a default page use the folder as context for the navtree
        container=aq_parent(context)
        isp=queryMultiAdapter((container, request), name="default_page", default=None)
        if isp is not None and isp.isDefaultPage(context):
            context=container

        contextPath="/".join(context.getPhysicalPath())
        contextPathLen=len(contextPath)
        parentDepth=(contextPath.count("/")-1)
        navrootPath="/".join(getNavigationRoot(context).getPhysicalPath())

        query={}
        query["path"]=dict(query=contextPath,
                           navtree=True,
                           navtree_start=navrootPath.count("/"))
        query["portal_type"]=typesToList(context)
        query["sort_on"]="getObjPositionInParent"
        query["sort_order"]="asc"

        catalog=getToolByName(context, "portal_catalog")
        results=catalog.searchResults(query)
        cache={}
        cache[navrootPath]={"current": False, "currentParent": True, "children": []}
        for brain in results:
            path=brain.getPath()
            pathLen=len(path)
            parentPath=path.rsplit("/", 1)[0]
            ancestor=current=currentParent=False
            if path==contextPath:
                current=True
            elif contextPathLen>pathLen:
                ancestor=contextPath.startswith(path+"/")
                currentParent=ancestor and path.count("/")==parentDepth

            if brain.exclude_from_nav and not currentParent:
                continue

            oldNode=cache.get(path, None)
            node={"brain": brain,
                  "path" : path,
                  "current" : current,
                  "currentParent" : currentParent,
                  "ancestor": ancestor }

            oldNode=cache.get(path, None)
            if oldNode is not None:
                oldNode.update(node)
                node=oldNode
            else:
                node["children"]=[]
                cache[path]=node

            parentNode=cache.get(parentPath, None)
            if parentNode is None:
                parentNode=cache[parentPath]=dict(children=[node])
            else:
                parentNode["children"].append(node)
            node["parent"]=parentNode


        self.tree=cache
        self.root=cache[navrootPath]
    def topLevelTabs(self, actions=None, category='portal_tabs'):
        
        context = aq_inner(self.context)

        portal_catalog = getToolByName(context, 'portal_catalog')
        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')
        site_properties = getattr(portal_properties, 'site_properties')

        # Build result dict
        result = []
        
        if PLONE_VERSION == 3:
            # BBB to Plone 3, different actions input signature
            # http://svn.plone.org/svn/plone/Plone/tags/3.3.5/Products/CMFPlone/browser/navigation.py
            # first the actions
            if actions is not None:
                for actionInfo in actions.get(category, []):
                    data = actionInfo.copy()
                    data['name'] = data['title']
                    result.append(data)            
        else:
        
            if actions is None:
                context_state = getMultiAdapter((context, self.request),
                                                name=u'plone_context_state')
                actions = context_state.actions(category)

            # first the actions
            if actions is not None:
                for actionInfo in actions:
                    data = actionInfo.copy()
                    data['name'] = data['title']
                    result.append(data)

        # check whether we only want actions
        if site_properties.getProperty('disable_folder_sections', False):
            return result

        customQuery = getattr(context, 'getCustomNavQuery', False)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}

        rootPath = getNavigationRoot(context)
        query['path'] = {'query' : rootPath, 'depth' : 1}

        query['portal_type'] = utils.typesToList(context)
        
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute

            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty('wf_states_to_show', [])

        query['is_default_page'] = False
        
        if site_properties.getProperty('disable_nonfolderish_sections', False):
            query['is_folderish'] = True

        # Get ids not to list and make a dict to make the search fast
        idsNotToList = navtree_properties.getProperty('idsNotToList', ())
        excludedIds = {}
        for id in idsNotToList:
            excludedIds[id]=1

        rawresult = portal_catalog.searchResults(**query)
                
        # apply mobile media filter for the results
        media_filter = queryUtility(IConvergenceMediaFilter, None)
        
        if media_filter is not None:
            strategy = media_filter.getContentMediaStrategy(self.context, self.request)        
            resolved_content_medias = media_filter.solveCatalogBrainContenMedia(self.context, rawresult)
        
        #import pdb ; pdb.set_trace()
        # now add the content to results
        for item in rawresult:
            
            if not (excludedIds.has_key(item.getId) or item.exclude_from_nav):
                id, item_url = get_view_url(item)
                data = {'name'      : utils.pretty_title_or_id(context, item),
                        'id'         : item.getId,
                        'url'        : item_url,
                        'description': item.Description}
        
                if media_filter is not None:
                    # Behavior with gomobile.convergence
                    media = resolved_content_medias[item]
                    if media_filter.checkMediaFilter(media, strategy):
                        result.append(data)
                else:
                    # The default behavior
                    result.append(data)                    
                                
        return result
Exemple #34
0
    def __init__(self, context, portlet):
        self.context = context
        self.portlet = portlet

        portal_properties = getToolByName(context, 'portal_properties')
        navtree_properties = getattr(portal_properties, 'navtree_properties')

        portal_url = getToolByName(context, 'portal_url')

        portal_languages = getToolByName(context, 'portal_languages')

        # Acquire a custom nav query if available
        customQuery = getattr(context, 'getCustomNavQuery', None)
        if customQuery is not None and utils.safe_callable(customQuery):
            query = customQuery()
        else:
            query = {}
        #import pdb;pdb.set_trace()
        # Construct the path query
        preferred_path = "/%s" % portal_languages.getPreferredLanguage()

        rootPathX = getNavigationRoot(context, relativeRoot=portlet.root)
        rootPathY = getNavigationRoot(context, relativeRoot=preferred_path)

        rootPath = portal_url.getPortalPath() + preferred_path

        print "X: portlet.root based. rootPath: %s, portlet.root: %s" % (
            rootPathX, portlet.root)
        print "Y: preferred_path based. rootPath: %s, preferred_path: %s" % (
            rootPathY, preferred_path)
        print "Current: rootPath+preferred_path: %s %s" % (rootPath,
                                                           preferred_path)

        currentPath = '/'.join(context.getPhysicalPath())

        # If we are above the navigation root, a navtree query would return
        # nothing (since we explicitly start from the root always). Hence,
        # use a regular depth-1 query in this case.

        query['path'] = {'query': rootPath, 'navtree': 1, 'navtree_start': 1}

        topLevel = portlet.topLevel or navtree_properties.getProperty(
            'topLevel', 0)
        topLevel = 0

        # Only list the applicable types
        query['portal_type'] = utils.typesToList(context)

        # Apply the desired sort
        sortAttribute = navtree_properties.getProperty('sortAttribute', None)
        if sortAttribute is not None:
            query['sort_on'] = sortAttribute
            sortOrder = navtree_properties.getProperty('sortOrder', None)
            if sortOrder is not None:
                query['sort_order'] = sortOrder

        # Filter on workflow states, if enabled
        if navtree_properties.getProperty('enable_wf_state_filtering', False):
            query['review_state'] = navtree_properties.getProperty(
                'wf_states_to_show', ())

        self.query = query