Repository: digitalfabrik/integreat-cms

Issue:
Page filter subpages not shown
### Describe the Bug
When filtering for pages which are not root-pages, these subpages will not be shown in the page tree view.


### Steps to Reproduce
1. Filter on the page view for any page which is not a root-page

### Expected Behavior
All matching pages are shown


### Actual Behavior
Only the root pages (and matching subpages of the root pages) get shown




Discussion:

Resolving patch:
diff --git a/src/cms/templatetags/page_filters.py b/src/cms/templatetags/page_filters.py
--- a/src/cms/templatetags/page_filters.py
+++ b/src/cms/templatetags/page_filters.py
@@ -19,3 +19,40 @@ def get_last_root_page(pages):
     """
     root_pages = list(filter(lambda p: not p.parent, pages))
     return root_pages[-1] if root_pages else None
+
+
+@register.simple_tag
+def get_depth_in(node, pageset):
+    """
+    This tag returns the depth of node whithin the tree/pages in pageset.
+
+    :param node : the page
+    :type node : ~cms.models.pages.page.Page
+
+    :param pageset: The pages (all pages or pages chosen by filter)
+    :type pageset: list [ ~cms.models.pages.page.Page ]
+
+    :return: the depth of node whithin the tree/pages in pageset
+    :rtype: int
+    """
+    if not node.parent in pageset:
+        return 0
+    return node.depth - get_highest_anscentor_in(node, pageset).depth
+
+
+def get_highest_anscentor_in(node, pageset):
+    """
+    This tag returns the highest (farthest) anscestor of node whithin the tree/pages in pageset.
+
+    :param node : the page
+    :type node : ~cms.models.pages.page.Page
+
+    :param pageset: The pages (all pages or pages chosen by filter)
+    :type pageset: list [ ~cms.models.pages.page.Page ]
+
+    :return: the highest (farthest) anscestor of node whithin the tree/pages in pageset
+    :rtype:  ~cms.models.pages.page.Page
+    """
+    if node.parent in pageset:
+        return get_highest_anscentor_in(node.parent, pageset)
+    return node
diff --git a/src/cms/templatetags/tree_filters.py b/src/cms/templatetags/tree_filters.py
--- a/src/cms/templatetags/tree_filters.py
+++ b/src/cms/templatetags/tree_filters.py
@@ -32,4 +32,4 @@ def get_children(node):
     :return: The list of all the node's children's ids
     :rtype: list [ int ]
     """
-    return [child.id for child in node.children.all()]
+    return [child.id for child in node.get_children()]
diff --git a/src/cms/views/pages/page_tree_view.py b/src/cms/views/pages/page_tree_view.py
--- a/src/cms/views/pages/page_tree_view.py
+++ b/src/cms/views/pages/page_tree_view.py
@@ -10,7 +10,7 @@
 from ...constants import translation_status
 from ...decorators import region_permission_required, permission_required
 from ...forms import PageFilterForm
-from ...models import Region, Language
+from ...models import Region, Language, Page
 from .page_context_mixin import PageContextMixin
 
 logger = logging.getLogger(__name__)
@@ -118,7 +118,8 @@ def page_filter(page):
                             return translation_status.OUTDATED in selected_status
                         return translation_status.UP_TO_DATE in selected_status
 
-                    pages = list(filter(page_filter, pages))
+                    pages = map(lambda p: p.id, list(filter(page_filter, pages)))
+                    pages = Page.objects.filter(id__in=pages).order_by()
         else:
             filter_form = PageFilterForm()
             filter_form.changed_data.clear()


Test patch: