Ejemplo n.º 1
0
    def render(self, context, instance, placeholder):
        request = context['request']
        language = request.toolbar.language if DJANGO_CMS_35 else request.LANGUAGE_CODE
        site = Site.objects.get_current()

        path_column = 'node__path' if DJANGO_CMS_35 else 'path'
        node_column = 'node__depth' if DJANGO_CMS_35 else 'depth'

        pages = Page.objects.public().published(site=site).order_by(path_column) \
            .filter(login_required=False, **{node_column + '__gte': instance.min_depth}) \
            .filter(title_set__language=language) \
            .distinct()

        if instance.max_depth:
            pages = pages.filter(**{node_column + '__lte': instance.max_depth})
        if instance.in_navigation is not None:
            pages = pages.filter(in_navigation=instance.in_navigation)

        context['instance'] = instance
        context['pages'] = pages

        if DJANGO_CMS_35:
            from cms.models.pagemodel import TreeNode
            nodes = [page.node for page in pages.select_related('node')]
            annotated_nodes = TreeNode.get_annotated_list_qs(nodes)
            annotated_pages = [(pages[x], annotated_nodes[x][1]) for x in range(0, len(nodes))]
        else:
            annotated_pages = Page.get_annotated_list_qs(pages)

        context['annotated_pages'] = annotated_pages

        return context
Ejemplo n.º 2
0
    def render(self, context, instance, placeholder):
        site = Site.objects.get_current()
        pages = Page.objects.public().published(site=site).order_by('path') \
            .filter(depth__gte=instance.min_depth, login_required=False) \
            .distinct()
        if instance.max_depth:
            pages = pages.filter(depth__lte=instance.max_depth)
        if instance.in_navigation is not None:
            pages = pages.filter(in_navigation=instance.in_navigation)

        context['instance'] = instance
        context['pages'] = pages
        context['annotated_pages'] = Page.get_annotated_list_qs(pages)

        return context