Exemple #1
0
    def test_tolist(self, root):
        from kotti.views.util import nodes_tree

        a, aa, ab, ac, aca, acb = create_contents(root)
        tree = nodes_tree(DummyRequest(), context=a)
        assert [ch for ch in tree.tolist()] == [a, aa, ab, ac, aca, acb]

        tree = nodes_tree(DummyRequest(), context=ac)
        assert [ch for ch in tree.tolist()] == [ac, aca, acb]
Exemple #2
0
    def test_tolist(self, db_session):
        from kotti.views.util import nodes_tree

        a, aa, ab, ac, aca, acb = create_contents()
        tree = nodes_tree(DummyRequest(), context=a)
        assert [ch for ch in tree.tolist()] == [a, aa, ab, ac, aca, acb]

        tree = nodes_tree(DummyRequest(), context=ac)
        assert [ch for ch in tree.tolist()] == [ac, aca, acb]
Exemple #3
0
def render_tree_navigation(context, request):
    tree = nodes_tree(request)
    return {
        'tree': {
            'children': [tree],
        },
    }
Exemple #4
0
def render_tree_navigation(context, request):
    tree = nodes_tree(request)
    return {
        'tree': {
            'children': [tree],
            },
        }
Exemple #5
0
def view_collection(context, request):
    tree = nodes_tree(request, context=context)
    return { 
            'tree': {
                'children': [tree],
                }
            }
Exemple #6
0
def view_collection(context, request):
    tree = nodes_tree(request, context=context)
    return {
        'tree': {
            'children': [tree],
        }
    }
Exemple #7
0
    def test_ordering(self):
        from kotti.views.util import nodes_tree

        a, aa, ab, ac, aca, acb = create_contents()
        a.children.insert(1, a.children.pop(0))
        tree = nodes_tree(DummyRequest())
        assert [ch.position for ch in tree.children[0].children] == [0, 1, 2]
        assert [ch.id for ch in tree.children[0].children] == [ab.id, aa.id, ac.id]
Exemple #8
0
def render_tree_navigation(context, request):
    """ Renders the navigation view.

    :result: Dictionary passed to the template for rendering.
    :rtype: dict
    """
    tree = nodes_tree(request)
    return {"tree": {"children": [tree]}}
Exemple #9
0
def render_tree_navigation(context, request):
    """ Renders the navigation view.

    :result: Dictionary passed to the template for rendering.
    :rtype: dict
    """
    tree = nodes_tree(request)
    return {"tree": {"children": [tree]}}
Exemple #10
0
    def _all_children(self, context, permission="view"):
        """ Recursively get all children of the given context.

        :result: List with all children of a given context.
        :rtype: list
        """
        tree = nodes_tree(self.request, context=context, permission=permission)
        return tree.tolist()[1:]
Exemple #11
0
    def _all_children(self, context, permission='view'):
        """ Recursively get all children of the given context.

        :result: List with all children of a given context.
        :rtype: list
        """
        tree = nodes_tree(self.request, context=context, permission=permission)
        return tree.tolist()[1:]
Exemple #12
0
    def test_ordering(self, root):
        from kotti.views.util import nodes_tree

        a, aa, ab, ac, aca, acb = create_contents(root)
        a.children.insert(1, a.children.pop(0))
        tree = nodes_tree(DummyRequest())
        assert [ch.position for ch in tree.children[0].children] == [0, 1, 2]
        assert [ch.id for ch in tree.children[0].children] == [ab.id, aa.id, ac.id]
Exemple #13
0
    def test_it(self):
        from kotti.views.util import nodes_tree

        a, aa, ab, ac, aca, acb = create_contents()
        aa.in_navigation = False  # nodes_tree doesn't care
        tree = nodes_tree(DummyRequest())
        assert tree.id == a.__parent__.id
        assert [ch.name for ch in tree.children] == [a.name]
        assert [ch.id for ch in tree.children[0].children] == [aa.id, ab.id, ac.id]
Exemple #14
0
    def test_it(self, root):
        from kotti.views.util import nodes_tree

        a, aa, ab, ac, aca, acb = create_contents(root)
        aa.in_navigation = False  # nodes_tree doesn't care
        tree = nodes_tree(DummyRequest())
        assert tree.id == a.__parent__.id
        assert [ch.name for ch in tree.children] == [a.name]
        assert [ch.id for ch in tree.children[0].children] == [aa.id, ab.id, ac.id]
Exemple #15
0
 def view(self):
     if self.context.children:
         tree = nodes_tree(self.request, self.context)
         return {
             'tree': {
                 'children': [tree],
                 },
             }
     else:
         return {}
Exemple #16
0
def tile_content(context, request, url=None, size_x=None, use=None, custom_text=None, extra_style=None):
    if url is None and "url" in request.POST:
        url = request.POST["url"]
    if use is None and "use" in request.POST:
        use = request.POST["use"]
    if custom_text is None and "custom_text" in request.POST:
        custom_text = request.POST["custom_text"]
    if extra_style is None and "extra_style" in request.POST:
        extra_style = request.POST["extra_style"]
    if size_x is None and "size_x" in request.POST:
        size_x = request.POST["size_x"]

    if url == "" or url is None or url is False:
        request.content_url = None
        current_context = context
    else:
        resource = None
        app_url = request.application_url
        parsed_url = urlparse(url)
        base_url = "{}://{}".format(parsed_url.scheme, parsed_url.netloc)
        if app_url.startswith(base_url) or url.startswith("/"):
            try:
                resource = find_resource(context, parsed_url.path)
            except KeyError:
                return _(u"Can't find resource with path {0}.".format(parsed_url.path))

        request.image = None
        if resource is not None:
            current_context = resource
            if use == u"use_internal_image":
                tree = nodes_tree(request, context=resource).tolist()
                if tree:
                    resource_images = [obj for obj in tree if IImage.providedBy(obj)]
                    if resource_images:
                        request.image = resource_images[0]
            request.content_url = request.resource_url(resource)
            request.target = "_self"
        else:
            current_context = context
            request.content_url = url
            request.target = "_blank"

    request.view_name = "tile-view"
    request.size = 2
    if size_x:
        request.size = int(size_x) + 2
    request.use = None
    if use is not None:
        request.use = use
    request.extra_style = u""
    if extra_style is not None:
        request.extra_style = extra_style
    if custom_text is not None:
        request.custom_text = custom_text
    return render_view(current_context, request, name="tile-view")
Exemple #17
0
def render_tree_navigation(context, request):
    """ Renders the navigation view.

    :result: Dictionary passed to the template for rendering.
    :rtype: dict
    """

    # Import is needed in function scope to resolve circular imports caused by
    # compatibility imports in slots.py.
    from kotti.views.util import nodes_tree

    tree = nodes_tree(request)

    return {
        'tree': {
            'children': [tree],
        },
    }
Exemple #18
0
    def view(self):

        session = DBSession()

        # Posts, if we have them.

        order_by = Post.modification_date
        if not self.context.sort_order_is_ascending:
            order_by = Post.modification_date.desc()
        query = (session.query(Post)
                 .filter(Post.parent_id == self.context.id)
                 .order_by(order_by)
                )

        top_level_posts = query.all()

        post_counts_and_trees = []

        for post in top_level_posts:
            if post.children:
                tree = nodes_tree(self.request, post)
                post_count = len(tree.tolist())
            else:
                tree = (post)
                post_count = 1
            post_tree = {
                'tree': {
                    'children': [tree],
                    },
                }

            post_counts_and_trees.append((post_count, post, post_tree))

        # Votes, if we have them.

        votes = None

        vote_data = {}
        vote_data['Sum'] = 0
        vote_data['Count'] = 0
        vote_data['Plus'] = 0
        vote_data['Zero'] = 0
        vote_data['Minus'] = 0

        votes_and_vote_objs = []

        if self.context.votable:

            query = session.query(Vote).filter(
                    Vote.parent_id == self.context.id)

            votes = query.all()

            for vote in votes:

                vote_data['Sum'] += vote.vote
                vote_data['Count'] += 1

                if vote.vote > 0:
                    vote_data['Plus'] += 1
                elif vote.vote == 0:
                    vote_data['Zero'] += 1
                else:
                    vote_data['Minus'] += 1

                votes_and_vote_objs.append((vote.vote, vote, 'vote'))

            if votes_and_vote_objs:
                if self.context.sort_order_is_ascending:
                    votes_and_vote_objs = sorted(votes_and_vote_objs)
                else:
                    votes_and_vote_objs = sorted(votes_and_vote_objs, reverse=True)

        page = self.request.params.get('page', 1)

        settings = forum_settings()

        if settings['use_batching']:
            post_items = Batch.fromPagenumber(post_counts_and_trees,
                          pagesize=settings['pagesize'],
                          pagenumber=int(page))

        return {
            'api': template_api(self.context, self.request),
            'macros': get_renderer('templates/macros.pt').implementation(),
            'vote_items': votes_and_vote_objs,
            'vote_data': vote_data,
            'items': post_items,
            'settings': settings,
            }