Browse Source

Merge pull request #109 from buxx/beta_1.0_fix_107

Bastien Sevajol 8 years ago
parent
commit
a98237fd00
2 changed files with 29 additions and 5 deletions
  1. 11 5
      tracim/tracim/controllers/content.py
  2. 18 0
      tracim/tracim/lib/content.py

+ 11 - 5
tracim/tracim/controllers/content.py View File

712
 
712
 
713
         fake_api = Context(CTX.FOLDER).toDict(fake_api_content)
713
         fake_api = Context(CTX.FOLDER).toDict(fake_api_content)
714
 
714
 
715
-        fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(
716
-            folder.get_valid_children([ContentType.Folder,
717
-                                       ContentType.File,
718
-                                       ContentType.Page,
719
-                                       ContentType.Thread]))
715
+        sub_items = content_api.get_children(
716
+            parent_id=folder.content_id,
717
+            content_types=[
718
+                ContentType.Folder,
719
+                ContentType.File,
720
+                ContentType.Page,
721
+                ContentType.Thread,
722
+            ],
723
+
724
+        )
725
+        fake_api.sub_items = Context(CTX.FOLDER_CONTENT_LIST).toDict(sub_items)
720
 
726
 
721
         fake_api.content_types = Context(CTX.DEFAULT).toDict(
727
         fake_api.content_types = Context(CTX.DEFAULT).toDict(
722
             content_api.get_all_types())
728
             content_api.get_all_types())

+ 18 - 0
tracim/tracim/lib/content.py View File

464
 
464
 
465
         return resultset.all()
465
         return resultset.all()
466
 
466
 
467
+    def get_children(self, parent_id: int, content_types: list, workspace: Workspace=None) -> [Content]:
468
+        """
469
+        Return parent_id childs of given content_types
470
+        :param parent_id: parent id
471
+        :param content_types: list of types
472
+        :param workspace: workspace filter
473
+        :return: list of content
474
+        """
475
+        resultset = self._base_query(workspace)
476
+        resultset = resultset.filter(Content.type.in_(content_types))
477
+
478
+        if parent_id:
479
+            resultset = resultset.filter(Content.parent_id==parent_id)
480
+        if parent_id is False:
481
+            resultset = resultset.filter(Content.parent_id == None)
482
+
483
+        return resultset.all()
484
+
467
     # TODO find an other name to filter on is_deleted / is_archived
485
     # TODO find an other name to filter on is_deleted / is_archived
468
     def get_all_with_filter(self, parent_id: int=None, content_type: str=ContentType.Any, workspace: Workspace=None) -> [Content]:
486
     def get_all_with_filter(self, parent_id: int=None, content_type: str=ContentType.Any, workspace: Workspace=None) -> [Content]:
469
         assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE
487
         assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE