Пример #1
0
def showdir(req, node, publishwarn="auto", markunpublished=False, sortfield=None, item_count=None, all_nodes=None, faultyidlist=[]):
    global g_nodes
    if publishwarn == "auto":
        homedirs = current_user.home_dir.all_children_by_query(q(Container))
        publishwarn = node in homedirs
    nodes = node.content_children # XXX: ?? correct
    make_search_content = get_make_search_content_function(req)
    paths = get_accessible_paths(node, q(Node).prefetch_attrs())
    if make_search_content:
        content_or_error = make_search_content(req, paths)
        if content_or_error:
            if isinstance(content_or_error, NoSearchResult):
                nodes = []
            else:
                nodes = content_or_error.node_query

    if sortfield is None:
        sortfield = req.params.get('sortfield')
    if not sortfield:
        sortfield = node.get("sortfield")
    if nodes:
        if sortfield and sortfield != "off":
            nodes = edit_sort_by_fields(nodes, sortfield).all()
        else:
            nodes = edit_sort_by_fields(nodes, "id").all()
    # set g_nodes to be used by shownav which must be called after showdir
    g_nodes[req.request_number] = nodes
    page = int(req.params.get('page', 1))
    return shownodelist(req, nodes, page, publishwarn=publishwarn, markunpublished=markunpublished, dir=node,
                        item_count=item_count, all_nodes=all_nodes, faultyidlist=faultyidlist)
Пример #2
0
def showdir(req, node, publishwarn="auto", markunpublished=False, sortfield=None, item_count=None, all_nodes=None, faultyidlist=[]):
    global g_nodes
    if publishwarn == "auto":
        homedirs = current_user.home_dir.all_children_by_query(q(Container))
        publishwarn = node in homedirs
    nodes = node.content_children # XXX: ?? correct
    make_search_content = get_make_search_content_function(req)
    paths = get_accessible_paths(node, q(Node).prefetch_attrs())
    if make_search_content:
        content_or_error = make_search_content(req, paths)
        if content_or_error:
            if isinstance(content_or_error, NoSearchResult):
                nodes = []
            else:
                nodes = content_or_error.node_query

    if sortfield is None:
        sortfield = req.params.get('sortfield')
    if not sortfield:
        sortfield = node.get("sortfield")
    if nodes:
        if sortfield and sortfield != "off":
            nodes = edit_sort_by_fields(nodes, sortfield).all()
        else:
            nodes = edit_sort_by_fields(nodes, "id").all()
    # set g_nodes to be used by shownav which must be called after showdir
    g_nodes[req.request_number] = nodes
    page = int(req.params.get('page', 1))
    return shownodelist(req, nodes, page, publishwarn=publishwarn, markunpublished=markunpublished, dir=node,
                        item_count=item_count, all_nodes=all_nodes, faultyidlist=faultyidlist)
Пример #3
0
def get_ids_from_req(req):
    from web.edit.edit_common import g_nodes
    nid = req.params.get("src", req.params.get("id"))
    if nid:
        node = q(Node).get(nid)
        nodes = node.content_children  # XXX: ?? correct
        make_search_content = get_make_search_content_function(req)
        paths = get_accessible_paths(node, q(Node).prefetch_attrs())
        if make_search_content:
            nodes = g_nodes[req.request_number]
        ids = [str(n.id) for n in nodes]
        return ids
Пример #4
0
def get_ids_from_req(req):
    from web.edit.edit_common import g_nodes
    nid = req.params.get("src", req.params.get("id"))
    if nid:
        node = q(Node).get(nid)
        nodes = node.content_children  # XXX: ?? correct
        make_search_content = get_make_search_content_function(req)
        paths = get_accessible_paths(node, q(Node).prefetch_attrs())
        if make_search_content:
            nodes = g_nodes[req.request_number]
        ids = [str(n.id) for n in nodes]
        return ids
Пример #5
0
    def html(self, req):
        show_node_big = ensure_unicode_returned(self._node.show_node_big, name="show_node_big of %s" % self._node)
        style_name = self.full_style_name or DEFAULT_FULL_STYLE_NAME
        node_html = getFormatedString(show_node_big(req, style_name))

        if not self.paths:
            # self.node may be result of a query and/or element of a contentlist, in this case
            # self.paths is not set - try to recalculate paths
            self.paths = get_accessible_paths(self.node, q(Node).prefetch_attrs())
        
        if self.paths:
            occurences_html = render_content_occurences(self.node, req, self.paths)
        else:
            occurences_html = u""

        return node_html + occurences_html
Пример #6
0
    def html(self, req):
        show_node_big = ensure_unicode_returned(self._node.show_node_big, name="show_node_big of %s" % self._node)
        style_name = self.full_style_name or DEFAULT_FULL_STYLE_NAME
        node_html = getFormatedString(show_node_big(req, style_name))

        if not self.paths:
            # self.node may be result of a query and/or element of a contentlist, in this case
            # self.paths is not set - try to recalculate paths
            self.paths = get_accessible_paths(self.node, q(Node).prefetch_attrs())
        
        if self.paths:
            occurences_html = render_content_occurences(self.node, req, self.paths)
        else:
            occurences_html = u""

        return node_html + occurences_html
Пример #7
0
def render_content(node, req, render_paths=True, show_id=None):
    make_search_content = get_make_search_content_function(req)

    if render_paths and node is not None:
        paths = get_accessible_paths(node, q(Node).prefetch_attrs())
    else:
        paths = None

    if make_search_content is None:
        content_or_error = make_node_content(node, req, paths)
    else:
        content_or_error = make_search_content(req, paths)

    
    cache_duration = content_or_error.cache_duration
    if cache_duration:
        req.reply_headers["Cache-Control"] = "max-age=" + str(cache_duration)
    else:
        req.reply_headers["Cache-Control"] = "no-cache"

    if isinstance(content_or_error, NodeNotAccessible):
        req.setStatus(content_or_error.status)
        return render_content_error(content_or_error.error, lang(req))

    if isinstance(content_or_error, StartpageNotAccessible):
        req.setStatus(content_or_error.status)
        return render_startpage_error(node, lang(req))

    content = content_or_error
    
    if "raw" in req.args:
        content_nav_html = ""
    else:
        node = content.node
        logo = content.logo
        select_style_link = content.select_style_link
        print_url = content.print_url
        styles = content.content_styles
        content_nav_html = render_content_nav(req, node, logo, styles, select_style_link, print_url, paths)


    if isinstance(show_id, list) and hasattr(content, 'show_id'):
        show_id.append(content.show_id)
    content_html = content_nav_html + "\n" + content.html(req)
    return content_html
Пример #8
0
def render_content(node, req, render_paths=True, show_id=None):
    make_search_content = get_make_search_content_function(req)

    if render_paths and node is not None:
        paths = get_accessible_paths(node, q(Node).prefetch_attrs())
    else:
        paths = None

    if make_search_content is None:
        content_or_error = make_node_content(node, req, paths)
    else:
        content_or_error = make_search_content(req, paths)

    
    cache_duration = content_or_error.cache_duration
    if cache_duration:
        req.reply_headers["Cache-Control"] = "max-age=" + str(cache_duration)
    else:
        req.reply_headers["Cache-Control"] = "no-cache"

    if isinstance(content_or_error, NodeNotAccessible):
        req.setStatus(content_or_error.status)
        return render_content_error(content_or_error.error, lang(req))

    if isinstance(content_or_error, StartpageNotAccessible):
        req.setStatus(content_or_error.status)
        return render_startpage_error(node, lang(req))

    content = content_or_error
    
    if "raw" in req.args:
        content_nav_html = ""
    else:
        node = content.node
        logo = content.logo
        select_style_link = content.select_style_link
        print_url = content.print_url
        styles = content.content_styles
        content_nav_html = render_content_nav(req, node, logo, styles, select_style_link, print_url, paths)


    if isinstance(show_id, list) and hasattr(content, 'show_id'):
        show_id.append(content.show_id)
    content_html = content_nav_html + "\n" + content.html(req)
    return content_html
Пример #9
0
def test_get_accessible_paths_multiple(session, req, root, home_root, collections, content_node):
    node = content_node
    
    root.children.append(collections)
    path_nodes_1 = append_chain_of_containers(2, collections)
    path_nodes_2 = append_chain_of_containers(3, collections)
    
    path_nodes_1[-1].content_children.append(content_node)
    path_nodes_2[-1].content_children.append(content_node)
    
    make_node_public(path_nodes_2[1], "read")
    session.flush()
    
    # only one path should be found because the guest user cannot see the nodes in path_nodes_1
    paths = get_accessible_paths(node) 
    assert len(paths) == 1
    path = paths[0]
    assert len(path) == 3
    
    # first node of path_nodes_2 is the collections root, the tested function omits this node because it's not public
    assert path == path_nodes_2[1:]
Пример #10
0
def test_get_accessible_paths_multiple(session, req, root, home_root,
                                       collections, content_node):
    node = content_node

    root.children.append(collections)
    path_nodes_1 = append_chain_of_containers(2, collections)
    path_nodes_2 = append_chain_of_containers(3, collections)

    path_nodes_1[-1].content_children.append(content_node)
    path_nodes_2[-1].content_children.append(content_node)

    make_node_public(path_nodes_2[1], "read")
    session.flush()

    # only one path should be found because the guest user cannot see the nodes in path_nodes_1
    paths = get_accessible_paths(node)
    assert len(paths) == 1
    path = paths[0]
    assert len(path) == 3

    # first node of path_nodes_2 is the collections root, the tested function omits this node because it's not public
    assert path == path_nodes_2[1:]