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


Python Team.objects方法代码示例

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


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

示例1: delete

# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import objects [as 别名]
 def delete(self, *args, **kwargs):
     if 'user' not in kwargs or not args:
         self.raise401()
     user = kwargs['user']
     path = parse_path(args[0])
     team = Team.objects(name=path[0]).first()
     if not team or user not in team.members:
         self.raise401()
     try:
         Team.objects(name=path[0]).delete()
         self.set_status(204)
         self.finish()
     except Exception as e:
         reason = e.message
         self.raise400(reason=reason)
开发者ID:hitigon,项目名称:warehouse,代码行数:17,代码来源:team.py

示例2: post

# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import objects [as 别名]
    def post(self, *args, **kwargs):
        """Create a new project by providing the details about the project.
        If the validation and saving are successful, it response with the
        project data and 201 status.
        Otherwise, it gives 4XX status and error messages.
        """
        name = self.get_argument('name', None)
        description = self.get_argument('description', None)
        url = self.get_argument('url', None)
        leader = self.get_argument('leader', None)
        members = self.get_argument('members', None)
        teams = self.get_argument('teams', None)
        repos = self.get_argument('repos', None)
        tags = self.get_argument('tags', None)
        if 'user' not in kwargs:
            self.raise401()

        try:
            # todo - better arguments handler
            url = url.strip()
            url = url if url else None
            members_list = []
            repos_list = []
            teams_list = []
            project_leader = kwargs['user']
            if leader:
                project_leader = User.objects(username=leader).first()

            if repos:
                for repo in parse_listed_strs(repos):
                    r = Repo.objects(name=repo).first()
                    if not r:
                        continue
                    repos_list.append(r)
            if members:
                for member in parse_listed_strs(members):
                    u = User.objects(username=member).first()
                    if not u or u == project_leader:
                        continue
                    members_list.append(u)
            if teams:
                for team in parse_listed_strs(teams):
                    t = Team.objects(name=team).first()
                    if not t:
                        continue
                    teams_list.append(t)
            members_list.append(project_leader)
            tags_list = parse_listed_strs(tags)
            project = Project(
                name=name, description=description,
                url=url, repos=repos_list,
                leader=project_leader, members=members_list,
                teams=teams_list, tags=tags_list)
            project.save()
            project_data = document_to_json(project, filter_set=_FILTER)
            self.set_status(201)
            self.write(project_data)
        except Exception as e:
            reason = e.message
            self.raise400(reason=reason)
开发者ID:hitigon,项目名称:warehouse,代码行数:62,代码来源:project.py

示例3: put

# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import objects [as 别名]
 def put(self, *args, **kwargs):
     if 'user' not in kwargs or not args:
         self.raise401()
     user = kwargs['user']
     path = parse_path(args[0])
     team = Team.objects(name=path[0]).first()
     if not team or user not in team.members:
         self.raise401()
     team_leader = team.leader
     update = {}
     name = self.get_argument('name', None)
     description = self.get_argument('description', None)
     url = self.get_argument('url', None)
     leader = self.get_argument('leader', None)
     members = self.get_argument('members', None)
     tags = self.get_argument('tags', None)
     if name:
         update['set__name'] = name
     if description:
         update['set__description'] = description
     if url:
         update['set__url'] = url
     if leader:
         team_leader = User.objects(username=leader).first()
         update['set__leader'] = team_leader
     if members:
         members_list = []
         for member in parse_listed_strs(members):
             u = User.objects(username=member).first()
             if not u or u == team_leader:
                 continue
             members_list.append(u)
         members_list.append(team_leader)
         update['set__members'] = members_list
     if tags:
         tags_list = parse_listed_strs(tags)
         update['set__tags'] = tags_list
     try:
         Team.objects(name=path[0]).update_one(**update)
         team = Team.objects(name=name or path[0]).first()
         team_data = document_to_json(team, filter_set=_FILTER)
         self.set_status(201)
         self.write(team_data)
     except Exception as e:
         reason = e.message
         self.raise400(reason=reason)
开发者ID:hitigon,项目名称:warehouse,代码行数:48,代码来源:team.py

示例4: get

# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import objects [as 别名]
    def get(self, *args, **kwargs):
        if 'user' not in kwargs:
            self.raise401()

        user = kwargs['user']
        if args:
            path = parse_path(args[0])
            team = Team.objects(name=path[0]).first()
            if not team:
                self.raise404()
            team_data = document_to_json(team, filter_set=_FILTER)
        else:
            # username = self.get_argument('username', None)
            # try:
            #     username = parse_path(username)[0]
            # except IndexError:
            #     username = None
            # if username:
            #     user = User.objects(username=username).fisrt()
            limit = self.get_argument('limit', None)
            start = self.get_argument('start', None)
            try:
                limit = int(limit)
            except:
                limit = None
            try:
                start = int(start)
            except:
                start = None
            teams = Team.objects(members__in=[user])
            if limit and start:
                teams = teams[start: start+limit]
            elif limit:
                teams = teams[:limit]
            elif start:
                teams = teams[start:]
            team_data = query_to_json(teams, filter_set=_FILTER)
        self.write(team_data)
开发者ID:hitigon,项目名称:warehouse,代码行数:40,代码来源:team.py

示例5: _process_project

# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import objects [as 别名]
 def _process_project(self, project):
     team = Team.objects(team_id=project.namespace.id).first()
     # We reset team statistics when we first encounter it
     if team and project.namespace.id not in self.teams_seen:
         team.delete()
         team = None
         self.teams_seen.add(project.namespace.id)
     if not team:
         team = Team(team_id=project.namespace.id)
     for (lang, total) in self._lang_stats(project).items():
         if lang in team.languages:
             team.languages[lang] += total
         else:
             team.languages[lang] = total
     team.save()
开发者ID:globocom,项目名称:vitrine,代码行数:17,代码来源:worker.py

示例6: get

# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import objects [as 别名]
 def get(self, *args, **kwargs):
     if 'user' not in kwargs:
         self.raise401()
     user = kwargs['user']
     repo_type = None
     repo_query = None
     repo_contents = None
     repo_branches = None
     repo_tags = None
     repo_info = None
     limit = self.get_argument('limit', None)
     start = self.get_argument('start', None)
     try:
         limit = int(limit)
     except:
         limit = None
     if args:
         # author = self.get_argument('author', None)
         path = parse_path(args[0])
         if not path:
             self.raise404()
         repo = Repo.objects(owner=user, name=path[0]).first()
         if repo:
             scm_repo = GitRepo(repo.path)
             repo_info = scm_repo.get_info()
             repo_branches, repo_tags = get_repo_branches_tags(scm_repo)
             repo_type, repo_query, repo_contents = get_repo_contents(
                 scm_repo, path[1:], limit=limit, start=start)
         if not repo_contents:
             self.raise404()
         repo_data = document_to_json(repo, filter_set=_FILTER)
     else:
         team_name = self.get_argument('team_name', None)
         try:
             start = int(start)
         except:
             start = None
         try:
             team_name = parse_path(team_name)[0]
         except IndexError:
             team_name = None
         if team_name:
             team = Team.objects(name=team_name).first()
             if not team:
                 self.raise404()
             if user not in team.member:
                 self.raise403()
             repos = Repo.objects(team=team)
         else:
             repos = Repo.objects(owner=user)
         if limit and start:
             repos = repos[start: start+limit]
         elif limit:
             repos = repos[:limit]
         elif start:
             repos = repos[start:]
         repo_data = query_to_json(repos, filter_set=_FILTER)
     if repo_type and repo_contents:
         repo_data['repo_info'] = repo_info
         repo_data['repo_type'] = repo_type
         repo_data['repo_query'] = repo_query
         repo_data['repo_branches'] = repo_branches
         repo_data['repo_tags'] = repo_tags
         repo_data['repo_contents'] = repo_contents
     self.write(repo_data)
开发者ID:hitigon,项目名称:warehouse,代码行数:67,代码来源:repo.py

示例7: get

# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import objects [as 别名]
    def get(self, *args, **kwargs):
        """Retrieve the resources of projects for the current user.

        If `*args` is provided by matching the URL pattern, the first element
        in the args is considered as a project name, then the project data will
        be retrieved from Database and send back to the client and the source
        owner in the format of JSON.
        Otherwise, it responses with a list of projects parcipated by the
        user. The request can provide three arugments: `team`, `limit` and
        `start`. `team` is used for querying the projects of one team by
        its name, which the user is one of its memebers. `limit` is
        the max number of items sent back to the client. `start` is the
        starting index of the querying results.

        Only authenticated user/resouce owner can access by using access_token,
        and his/her scopes must include `projects`.

        The retrieved resource should always be related to the user, and it is
        not allowed to access others' projects or other teams' projects.

        .. todo::
            restrict the response data and add default limits
        """
        if 'user' not in kwargs:
            self.raise401()

        user = kwargs['user']
        if args:
            path = parse_path(args[0])
            project = Project.objects(name=path[0]).first()
            if not project:
                self.raise404()
            if project and user not in project.members:
                self.raise401()
            project_data = document_to_json(project, filter_set=_FILTER)
        else:
            team_name = self.get_argument('team', None)
            limit = self.get_argument('limit', None)
            start = self.get_argument('start', None)
            try:
                team_name = parse_path(team_name)[0]
            except IndexError:
                team_name = None
            try:
                limit = int(limit)
            except Exception:
                limit = None
            try:
                start = int(start)
            except Exception:
                start = None
            if team_name:
                team = Team.objects(name=team_name).first()
                if not team:
                    self.raise404()
                if user not in team.members:
                    self.raise403()
                project = Project.objects(teams__in=[team])
            else:
                project = Project.objects(members__in=[user])
            if limit and start:
                project = project[start:start + limit]
            elif limit:
                project = project[:limit]
            elif start:
                project = project[start:]
            project_data = query_to_json(project, filter_set=_FILTER)
        self.write(project_data)
开发者ID:hitigon,项目名称:warehouse,代码行数:70,代码来源:project.py

示例8: put

# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import objects [as 别名]
    def put(self, *args, **kwargs):
        """Update a project by its name and other information.
        """
        if 'user' not in kwargs or not args:
            self.raise401()
        name = self.get_argument('name', None)
        description = self.get_argument('description', None)
        url = self.get_argument('url', None)
        leader = self.get_argument('leader', None)
        members = self.get_argument('members', None)
        teams = self.get_argument('teams', None)
        repos = self.get_argument('repos', None)
        tags = self.get_argument('tags', None)

        user = kwargs['user']
        path = parse_path(args[0])
        project = Project.objects(name=path[0]).first()
        if not project or user not in project.members:
            self.raise401()
        project_leader = project.leader
        update = {}
        if name:
            update['set__name'] = name
        if description:
            update['set__description'] = description
        if url:
            update['set__url'] = url
        if leader:
            project_leader = User.objects(username=leader).first()
            update['set__leader'] = project_leader
        if members:
            members_list = []
            for member in parse_listed_strs(members):
                u = User.objects(username=member).first()
                if not u or u == project_leader:
                    continue
                members_list.append(u)
            members_list.append(project_leader)
            update['set__members'] = members_list
        if teams:
            teams_list = []
            for team in parse_listed_strs(teams):
                t = Team.objects(name=team).first()
                if not t:
                    continue
                teams_list.append(t)
            update['set__teams'] = teams_list
        if repos:
            repos_list = []
            for repo in parse_listed_strs(repos):
                r = Repo.objects(name=repo).first()
                if not r:
                    continue
                repos_list.append(r)
            update['set__repos'] = repos_list
        if tags:
            tags_list = parse_listed_strs(tags)
            update['set__tags'] = tags_list
        try:
            Project.objects(name=path[0]).update_one(**update)
            project = Repo.objects(name=name or path[0]).first()
            project_data = document_to_json(project, filter_set=_FILTER)
            self.set_status(201)
            self.write(project_data)
        except Exception as e:
            reason = e.message
            self.raise400(reason=reason)
开发者ID:hitigon,项目名称:warehouse,代码行数:69,代码来源:project.py


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