Example #1
0
 def batch_target(self, path, b_page):
     query = make_query(
         b_page=str(b_page),
         filter=self.filter_term,
         sort=self.sort_column,
         order=self.sort_order)
     return safe_decode(make_url(self.request, path=path, query=query))
Example #2
0
 def sort_target(self, sort, order):
     query = make_query(
         filter=self.filter_term,
         b_page=self.current_page,
         sort=sort,
         order=order)
     return safe_decode(make_url(self.request, node=self.model, query=query))
Example #3
0
    def items_for(self, model, breakpoint=None):
        items = list()
        for node in LocationIterator(model):
            title = node.metadata.title
            if title:
                title = safe_decode(title)
            items.append(
                {
                    "title": title,
                    "url": self.item_url(node),
                    "target": self.item_target(node),
                    "selected": False,
                    "id": node.name,
                    "default_child": node.properties.default_child,
                }
            )
            if node is breakpoint:
                break
        items.reverse()
        ret = list()
        count = len(items)
        for i in range(count):
            default_child = items[i]["default_child"]
            if default_child and i < count - 1 and default_child == items[i + 1]["id"]:
                continue
            ret.append(items[i])

        # XXX: this is crap!
        if not breakpoint:
            ret[0]["title"] = "Home"

        ret[-1]["selected"] = True
        return ret
Example #4
0
 def fillchildren(self, model, path, tree):
     """XXX: consider cone.app.interfaces.INavigationLeaf
     """
     curpath = None
     if path:
         curpath = path[0]
     default_child = None
     if model.properties.default_child:
         if not curpath or curpath == model.properties.default_child:
             default_child = model[model.properties.default_child]
     if default_child and default_child.properties.hide_if_default:
         model = default_child
         default_child = None
         if path:
             path = path[1:]
             if path:
                 curpath = path[0]
     if default_child:
         if not curpath:
             curpath = model.properties.default_child
     for key in model:
         node = model[key]
         if not has_permission("view", node, self.request):
             continue
         if not node.properties.get("in_navtree"):
             continue
         title = node.metadata.title
         if title:
             title = safe_decode(title)
         url = make_url(self.request, node=node)
         query = make_query(contenttile=node.properties.default_content_tile)
         target = make_url(self.request, node=node, query=query)
         curnode = curpath == key and True or False
         icon = node_icon(self.request, node)
         css = ""
         if IWorkflowState.providedBy(node):
             css = "state-%s" % node.state
         child = self.navtreeitem(title, url, target, nodepath(node), icon, css)
         child["showchildren"] = curnode
         if curnode:
             child["selected"] = True
             if default_child:
                 self.fillchildren(default_child, path[1:], child)
             else:
                 self.fillchildren(node, path[1:], child)
         else:
             selected_path = nodepath(self.model)
             if default_child:
                 selected_path.append(default_child.name)
             selected = False
             if selected_path == nodepath(node):
                 selected = True
             child["selected"] = selected
         tree["children"].append(child)
Example #5
0
    def make_url(self, params, path=None, include_view=False):
        """Create URL considering ``query_whitelist``.

        :param params: Dictionary with query parameters.
        :param path: Optional model path, if ``None``, path gets taken from
            ``self.model``
        :param include_view: Boolean whether to include
            ``self.related_view`` to URL.
        :return: URL as string.
        """
        return safe_decode(
            make_url(self.request,
                     path=path,
                     node=None if path else self.model,
                     resource=self.related_view if include_view else None,
                     query=self.make_query(params)))
Example #6
0
    def make_url(self, params, path=None, include_view=False):
        """Create URL considering ``query_whitelist``.

        :param params: Dictionary with query parameters.
        :param path: Optional model path, if ``None``, path gets taken from
            ``self.model``
        :param include_view: Boolean whether to include
            ``self.related_view`` to URL.
        :return: URL as string.
        """
        return safe_decode(make_url(
            self.request,
            path=path,
            node=None if path else self.model,
            resource=self.related_view if include_view else None,
            query=self.make_query(params)))
Example #7
0
 def filter_target(self):
     query = make_query(dict(sort=self.sort_column, order=self.sort_order))
     return safe_decode(make_url(self.request, node=self.model, query=query))
Example #8
0
 def contenttile(self):
     path = u"/".join([safe_decode(it) for it in self.model.path if it])
     ajax_continue(self.request, [AjaxPath(path)])
     return get_action_context(self.request).scope