def treeview_children(self, id='#', ignore_id=None, allowed_content_types=None): """ id must be "#" or something like "workspace_3__document_8" """ if id == '#': return self.treeview_root() ignore_item_ids = [int(ignore_id)] if ignore_id else [] workspace, content = convert_id_into_instances(id) viewable_content_types = [] if allowed_content_types: viewable_content_types = allowed_content_types.split(',') else: viewable_content_types = self._get_treeviewable_content_types_or_none( ) contents = ContentApi(tmpl_context.current_user).get_child_folders( content, workspace, [], ignore_item_ids, viewable_content_types) # This allow to show contents and folders group by type sorted_contents = ContentApi.sort_content(contents) dictified_contents = Context(CTX.MENU_API).toDict(sorted_contents, 'd') return dictified_contents
def test_sort_by_content_type(self): c1 = Content() c1.label = 'AAAA' c1.type = 'file' c2 = Content() c2.label = 'BBBB' c2.type = 'folder' items = [c1, c2] sorteds = ContentApi.sort_content(items) eq_(sorteds[0], c2, 'value is {} instead of {}'.format(sorteds[0].content_id, c2.content_id)) eq_(sorteds[1], c1, 'value is {} instead of {}'.format(sorteds[1].content_id, c1.content_id))
def test_sort_by_label_or_filename(self): c1 = Content() c1.label = 'ABCD' c1.type = 'file' c2 = Content() c2.label = '' c2.type = 'file' c2.file_name = 'AABC' c3 = Content() c3.label = 'BCDE' c3.type = 'file' items = [c1, c2, c3] sorteds = ContentApi.sort_content(items) eq_(sorteds[0], c2) eq_(sorteds[1], c1) eq_(sorteds[2], c3)
def test_sort_by_content_type(self): c1 = Content() c1.label = 'AAAA' c1.type = 'file' c2 = Content() c2.label = 'BBBB' c2.type = 'folder' items = [c1, c2] sorteds = ContentApi.sort_content(items) eq_( sorteds[0], c2, 'value is {} instead of {}'.format(sorteds[0].content_id, c2.content_id)) eq_( sorteds[1], c1, 'value is {} instead of {}'.format(sorteds[1].content_id, c1.content_id))
def treeview_children(self, id='#', ignore_id=None, allowed_content_types = None): """ id must be "#" or something like "workspace_3__document_8" """ if id=='#': return self.treeview_root() ignore_item_ids = [int(ignore_id)] if ignore_id else [] workspace, content = convert_id_into_instances(id) viewable_content_types = [] if allowed_content_types: viewable_content_types = allowed_content_types.split(',') else: viewable_content_types = self._get_treeviewable_content_types_or_none() contents = ContentApi(tmpl_context.current_user).get_child_folders(content, workspace, [], ignore_item_ids, viewable_content_types) # This allow to show contents and folders group by type sorted_contents = ContentApi.sort_content(contents) dictified_contents = Context(CTX.MENU_API).toDict(sorted_contents, 'd') return dictified_contents