Пример #1
0
 def get(self, req, *args, **kwargs):
     query = req.GET.get("query", "")
     try:
         page = int(req.GET.get("page", 1))
     except ValueError:
         page = 1
     try:
         page_size = int(req.GET.get("page_size", 10))
     except ValueError:
         page_size = 10
     tenants, total = team_services.list_teams_by_user_id(
         eid=self.enterprise.enterprise_id,
         user_id=req.user.user_id,
         query=query,
         page=page,
         page_size=page_size)
     result = {
         "tenants": tenants,
         "total": total,
         "page": page,
         "page_size": page_size
     }
     serializer = ListTeamRespSerializer(data=result)
     serializer.is_valid(raise_exception=True)
     return Response(serializer.data, status.HTTP_200_OK)
Пример #2
0
    def get(self, req, user_id, *args, **kwargs):
        eid = req.GET.get("eid", "")
        if not eid:
            raise serializers.ValidationError("缺少'eid'字段")
        query = req.GET.get("query", "")
        try:
            page = int(req.GET.get("page", 1))
        except ValueError:
            page = 1
        try:
            page_size = int(req.GET.get("page_size", 10))
        except ValueError:
            page_size = 10

        tenants, total = team_services.list_teams_by_user_id(
            eid=eid,
            user_id=user_id,
            query=query,
            page=page,
            page_size=page_size)
        result = {"tenants": tenants, "total": total}

        serializer = ListTeamRespSerializer(data=result)
        serializer.is_valid(raise_exception=True)

        return Response(result, status.HTTP_200_OK)
Пример #3
0
    def get(self, req, *args, **kwargs):
        query = req.GET.get("query", "")
        try:
            page = int(req.GET.get("page", 1))
        except ValueError:
            page = 1
        try:
            page_size = int(req.GET.get("page_size", 10))
        except ValueError:
            page_size = 10
        tenant_names = req.GET.get("tenant_names", "")

        if tenant_names:
            data = team_services.list_by_tenant_names(tenant_names.split(","))
            result = {"tenants": data, "total": len(data)}
        else:
            data, total = team_services.list_teams_v2(req.user.enterprise_id,
                                                      query=query,
                                                      page=page,
                                                      page_size=page_size)
            result = {
                "tenants": data,
                "total": total,
                "page": page,
                "page_size": page_size
            }
        serializer = ListTeamRespSerializer(data=result)
        serializer.is_valid(raise_exception=True)
        return Response(result, status.HTTP_200_OK)