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


Python DataHubConnection.create_license_view方法代码示例

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


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

示例1: __init__

# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import create_license_view [as 别名]

#.........这里部分代码省略.........

        Raises LookupError when repo or collaborator does not exist.
        Raises User.DoesNotExist if collaborator owns repo.
        Raises PermissionDenied on insufficient permissions.
        """
        with _superuser_connection(self.repo_base) as conn:
            collaborators = conn.list_collaborators(repo=repo)
            collaborators = [c.get('username') for c in collaborators]

            # Current user must be the repo's owner or the collaborator to be
            # removed and must be an existing collaborator. If not the owner
            # and removing someone else, current user must have CREATE db
            # privileges.
            if (self.username not in [collaborator, self.repo_base] or
                    self.username not in collaborators):
                DataHubManager.has_repo_db_privilege(
                    self.username, self.repo_base, repo, 'CREATE')
            # The reason we're enforcing permission checks this way is to deal
            # with the edge case where a user removes himself as a collaborator
            # from another user's repo.
            if collaborator not in collaborators:
                raise LookupError('Failed to delete collaborator.'
                                  ' %s is not a collaborator in the specified '
                                  'repository.' % collaborator)

            collab = User.objects.get(username=collaborator)
            Collaborator.objects.get(
                user=collab, repo_name=repo, repo_base=self.repo_base).delete()

            result = conn.delete_collaborator(
                repo=repo, collaborator=collaborator)
        return result

    def create_license_view(self, repo, table, view_params, license_id):
        view_sql = self.user_con.get_view_sql(
            repo_base=self.repo_base,
            repo=repo,
            table=table,
            view_params=view_params,
            license_id=license_id)
        license_id = int(license_id)

        license_view_obj, created = LicenseView.objects.get_or_create(
            repo_base=self.repo_base,
            repo_name=repo,
            table=table,
            view_sql=view_sql,
            license_id=license_id)

        # Create view in database
        self.user_con.create_license_view(
            repo_base=self.repo_base,
            repo=repo,
            table=table,
            view_sql=view_sql,
            license_id=license_id)

        return True

    def delete_license_view(self, repo, table, license_view, license_id):
        license_view_obj = LicenseView.objects.filter(
            repo_base=self.repo_base,
            repo_name=repo,
            table=table,
            license_id=license_id)
开发者ID:datahuborg,项目名称:datahub,代码行数:69,代码来源:manager.py


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