当前位置: 首页>>代码示例>>Python>>正文


Python WorkspaceApi.get_one_by_label方法代码示例

本文整理汇总了Python中tracim.lib.workspace.WorkspaceApi.get_one_by_label方法的典型用法代码示例。如果您正苦于以下问题:Python WorkspaceApi.get_one_by_label方法的具体用法?Python WorkspaceApi.get_one_by_label怎么用?Python WorkspaceApi.get_one_by_label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tracim.lib.workspace.WorkspaceApi的用法示例。


在下文中一共展示了WorkspaceApi.get_one_by_label方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Root

# 需要导入模块: from tracim.lib.workspace import WorkspaceApi [as 别名]
# 或者: from tracim.lib.workspace.WorkspaceApi import get_one_by_label [as 别名]
class Root(DAVCollection):
    """
    Root ressource that represents tracim's home, which contains all workspaces
    """

    def __init__(self, path: str, environ: dict):
        super(Root, self).__init__(path, environ)

        self.user = UserApi(None).get_one_by_email(environ['http_authenticator.username'])
        # TODO BS 20170221: Web interface should list all workspace to. We
        # disable it here for moment. When web interface will be updated to
        # list all workspace, change this here to.
        self.workspace_api = WorkspaceApi(self.user, force_role=True)

    def __repr__(self) -> str:
        return '<DAVCollection: Root>'

    def getMemberNames(self) -> [str]:
        """
        This method returns the names (here workspace's labels) of all its children

        Though for perfomance issue, we're not using this function anymore
        """
        return [workspace.label for workspace in self.workspace_api.get_all()]

    def getMember(self, label: str) -> DAVCollection:
        """
        This method returns the child Workspace that corresponds to a given name

        Though for perfomance issue, we're not using this function anymore
        """
        try:
            workspace = self.workspace_api.get_one_by_label(label)
            workspace_path = '%s%s%s' % (self.path, '' if self.path == '/' else '/', transform_to_display(workspace.label))

            return Workspace(workspace_path, self.environ, workspace)
        except AttributeError:
            return None

    def createEmptyResource(self, name: str):
        """
        This method is called whenever the user wants to create a DAVNonCollection resource (files in our case).

        There we don't allow to create files at the root;
        only workspaces (thus collection) can be created.
        """
        raise DAVError(HTTP_FORBIDDEN)

    def createCollection(self, name: str):
        """
        This method is called whenever the user wants to create a DAVCollection resource as a child (in our case,
        we create workspaces as this is the root).

        [For now] we don't allow to create new workspaces through
        webdav client. Though if we come to allow it, deleting the error's raise will
        make it possible.
        """
        # TODO : remove comment here
        # raise DAVError(HTTP_FORBIDDEN)

        new_workspace = self.workspace_api.create_workspace(name)
        self.workspace_api.save(new_workspace)

        workspace_path = '%s%s%s' % (
        self.path, '' if self.path == '/' else '/', transform_to_display(new_workspace.label))

        transaction.commit()
        return Workspace(workspace_path, self.environ, new_workspace)

    def getMemberList(self):
        """
        This method is called by wsgidav when requesting with a depth > 0, it will return a list of _DAVResource
        of all its direct children
        """

        members = []
        for workspace in self.workspace_api.get_all():
            workspace_path = '%s%s%s' % (self.path, '' if self.path == '/' else '/', workspace.label)
            members.append(Workspace(workspace_path, self.environ, workspace))

        return members
开发者ID:lebouquetin,项目名称:tracim,代码行数:83,代码来源:sql_resources.py

示例2: get_workspace_from_path

# 需要导入模块: from tracim.lib.workspace import WorkspaceApi [as 别名]
# 或者: from tracim.lib.workspace.WorkspaceApi import get_one_by_label [as 别名]
 def get_workspace_from_path(self, path: str, api: WorkspaceApi) -> Workspace:
     try:
         return api.get_one_by_label(transform_to_bdd(path.split('/')[1]))
     except NoResultFound:
         return None
开发者ID:buxx,项目名称:tracim,代码行数:7,代码来源:sql_dav_provider.py


注:本文中的tracim.lib.workspace.WorkspaceApi.get_one_by_label方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。