def _build_sibling_list_of_workspaces( self, workspace: Workspace, child_contents: [NodeTreeItem], select_active_workspace=False, all_workspaces=True) -> [NodeTreeItem]: root_items = [] api = WorkspaceApi(tmpl_context.current_user) workspaces = api.get_all_for_user(tmpl_context.current_user) if not all_workspaces: # Show only current workspace - this is used for "move item" screen # which must not allow to move from a workspace to another item = NodeTreeItem(workspace, child_contents) item.is_selected = select_active_workspace root_items.append(item) else: for workspace_cursor in workspaces: item = None if workspace_cursor == workspace: item = NodeTreeItem(workspace_cursor, child_contents) else: item = NodeTreeItem(workspace_cursor, []) item.is_selected = select_active_workspace and workspace_cursor == workspace root_items.append(item) return root_items
def _build_sibling_list_of_workspaces(self, workspace: Workspace, child_contents: [NodeTreeItem], select_active_workspace = False, all_workspaces = True) -> [NodeTreeItem]: root_items = [] api = WorkspaceApi(tmpl_context.current_user) workspaces = api.get_all_for_user(tmpl_context.current_user) if not all_workspaces: # Show only current workspace - this is used for "move item" screen # which must not allow to move from a workspace to another item = NodeTreeItem(workspace, child_contents) item.is_selected = select_active_workspace root_items.append(item) else: for workspace_cursor in workspaces: item = None if workspace_cursor==workspace: item = NodeTreeItem(workspace_cursor, child_contents) else: item = NodeTreeItem(workspace_cursor, []) item.is_selected = select_active_workspace and workspace_cursor==workspace root_items.append(item) return root_items
def treeview_root(self, id='#', current_id=None, all_workspaces=True, folder_allowed_content_types='', ignore_id=None, ignore_workspace_id=None): all_workspaces = bool(int(all_workspaces)) # ignore_workspace_id is a string like 3,12,78,15 ignored_ids = [int(id) for id in ignore_workspace_id.split(',')] if ignore_workspace_id else None if not current_id: # Default case is to return list of workspaces api = WorkspaceApi(tmpl_context.current_user) workspaces = api.get_all_for_user(tmpl_context.current_user, ignored_ids) dictified_workspaces = Context(CTX.MENU_API).toDict(workspaces, 'd') return dictified_workspaces allowed_content_types = ContentType.allowed_types_from_str(folder_allowed_content_types) ignored_item_ids = [int(ignore_id)] if ignore_id else [] # Now complex case: we must return a structured tree # including the selected node, all parents (and their siblings) workspace, content = convert_id_into_instances(current_id) # The following step allow to select the parent folder when content itself is not visible in the treeview if content and content.type!=ContentType.Folder and CFG.CST.TREEVIEW_ALL!=CFG.get_instance().WEBSITE_TREEVIEW_CONTENT: content = content.parent if content.parent else None # This is the init of the recursive-like build of the tree content_parent = content tree_items = [] # The first step allow to load child of selected item # (for example, when you select a folder in the windows explorer, # then the selected folder is expanded by default) content_api = ContentApi(tmpl_context.current_user) child_folders = content_api.get_child_folders(content_parent, workspace, allowed_content_types, ignored_item_ids) if len(child_folders)>0: first_child = child_folders[0] content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, first_child, tree_items, False, allowed_content_types, ignored_item_ids) content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, content_parent, tree_items, True, allowed_content_types, ignored_item_ids) while content_parent: # Do the same for the parent level content_parent, tree_items = self._build_sibling_list_of_tree_items(workspace, content_parent, tree_items) # Now, we have a tree_items list that is the root folders list, # so we now have to put it as a child of a list of workspaces should_select_workspace = not content full_tree = self._build_sibling_list_of_workspaces(workspace, tree_items, should_select_workspace, all_workspaces) return Context(CTX.MENU_API_BUILD_FROM_TREE_ITEM).toDict(full_tree, 'd')
def get_workspace_readable_calendars_urls_for_user(cls, user: User)\ -> [str]: calendar_urls = [] workspace_api = WorkspaceApi(user) for workspace in workspace_api.get_all_for_user(user): if workspace.calendar_enabled: calendar_urls.append( cls.get_workspace_calendar_url( workspace_id=workspace.workspace_id, )) return calendar_urls
def get_workspace_readable_calendars_urls_for_user(cls, user: User)\ -> [str]: calendar_urls = [] workspace_api = WorkspaceApi(user) for workspace in workspace_api.get_all_for_user(user): if workspace.calendar_enabled: calendar_urls.append(cls.get_workspace_calendar_url( workspace_id=workspace.workspace_id, )) return calendar_urls