Ejemplo n.º 1
0
    def get(self, request, *args,**kwargs):

        params = request.query_params
        if not params:

            return JsonResponse(
                {
                    'code':10001,
                    'msg':'Method Not Allowed'
                }
            )
        query_match = []
        girlsay = params.get('girlsay')

        ret = jieba.lcut(girlsay, cut_all=True)

        result = jieba_analyse(ret)

        for elment in result:
            query_match.append(Q(girlsay__icontains=elment))

        #print(query_match,girlsay,result)
        #获取所有数据
        shuyu = ShuYu.objects.filter(reduce(operator.or_, query_match))
        #print(shuyu)
        #创建分页对象
        pg = MyPageNumberPagination()
        #获取分页的数据
        page_shuyu = pg.paginate_queryset(queryset=shuyu,request=request,view=self)
        #对数据进行序列化
        serializer = ShuYuSerializer(instance=page_shuyu,many=True)

        return pg.get_paginated_response(serializer.data)
Ejemplo n.º 2
0
    def get(self, request, *args,**kwargs):

        cid = request._request.GET.get('cid')

        child_object = CategoryChild.objects.get(pk=cid)
        child = child_object.shuyu.all().order_by('-updated')
        category = child_object.name
        # 创建分页对象
        pg = MyPageNumberPagination()
        # 获取分页的数据
        page_child = pg.paginate_queryset(queryset=child,request=request,view=self)

        # 对数据进行序列化
        serializer = ShuYuSerializer(instance=page_child, many=True)

        # 搜索排行+1
        try:
            pool = redis.ConnectionPool(host=settings.REDIS_SERVER,port=settings.REDIS_PORT,decode_responses=True)
            conn = redis.Redis(connection_pool=pool)
            conn.zincrby(settings.SEARCH_RANK,category,1)
        except Exception as e:
            logger.error(e)

        #return Response(serializer.data)
        return pg.get_paginated_response(serializer.data)
Ejemplo n.º 3
0
 def get(self, request, *args, **kwargs):
     namespace = request.query_params.dict().get('namespace')
     context = {}
     try:
         if namespace:
             ret = v1.list_namespaced_pod(namespace=namespace)
         else:
             ret = v1.list_namespaced_pod(namespace='default')
             # ret = v1.list_pod_for_all_namespaces(watch=False)
         tmp_context = []
         for i in ret.items:
             tmp_dict = dict()
             tmp_dict['pod_ip'] = i.status.pod_ip
             tmp_dict['namespace'] = i.metadata.namespace
             from django.utils import timezone
             tmp_dict['create_time'] = timezone.localtime(i.metadata.creation_timestamp).strftime("%Y-%m-%d %H:%M:%S")
             # print(timezone.localtime(i.metadata.creation_timestamp).strftime("%Y-%m-%d %H:%M:%S"))
             tmp_dict['name'] = i.metadata.name
             tmp_dict['host_ip'] = i.status.host_ip
             tmp_dict['status'] = i.status.phase
             # 当pod处于Pending状态, 此时pod重启次数 i.status.phase 信息为 None
             # 如果为None, 则返回 0
             tmp_dict['restart_count'] = [0 if i.status.container_statuses is None else i.status.container_statuses[0].restart_count][0]
             tmp_context.append(tmp_dict)
         paginator = MyPageNumberPagination()
         page_publish_list = paginator.paginate_queryset(tmp_context, self.request, view=self)
         ps = PodSerializers(page_publish_list, many=True)
         response = paginator.get_paginated_response(ps.data)
         return response
     except Exception as e:
         logger.error('获取pod详细信息出错:%s' % str(traceback.format_exc()))
         context['errcode'] = 1000
         context['msg'] = e
         context['data'] = ''
     return Response(context)
Ejemplo n.º 4
0
 def get(self, request, *args, **kwargs):
     context = {'errcode': 0, 'msg': '获取节点成功!', 'data': ''}
     try:
         ret = v1.list_node()
         tmp_context = []
         for i in ret.items:
             tmp_dict = dict()
             tmp_dict['host'] = i.status.addresses[0].address
             tmp_dict['hostname'] = i.status.addresses[1].address
             tmp_dict['labels'] = i.metadata.namespace
             tmp_dict['capacity'] = i.status.capacity
             tmp_dict['allocatable'] = i.status.allocatable
             tmp_dict['status'] = i.status.conditions[-1].status
             tmp_context.append(tmp_dict)
         paginator = MyPageNumberPagination()
         page_publish_list = paginator.paginate_queryset(tmp_context, self.request, view=self)
         context['data'] = page_publish_list
     except Exception as e:
         logger.error('获取节点信息失败:%s' % str(traceback.format_exc()), e)
         context['msg'] = '获取失败'
         context['errcode'] = 1000
     return Response(context)
Ejemplo n.º 5
0
    def get(self, request, *args,**kwargs):


        # 子分类id
        child_id = request._request.GET.get('cid')

        # 获取大分类对象
        child_object = CategoryLessonChild.objects.get(pk=child_id)

        # 获取子分类对象
        lesson_obj = child_object.lesson.all().order_by('-updated')

        #lesson = category_obj.lesson.get(pk=lid).all()
        # 创建分页对象
        pg = MyPageNumberPagination()
        # 获取分页的数据
        page_child = pg.paginate_queryset(queryset=lesson_obj,request=request,view=self)

        # 对数据进行序列化
        serializer = LessonSerializer(instance=page_child, many=True)

        return pg.get_paginated_response(serializer.data)
Ejemplo n.º 6
0
    def get(self, request, *args,**kwargs):

        type = request._request.GET.get('type')

        dic = {
            'ltjx' : '网上撩妹',
            'mrtj' : '精选文章',
            'kctj' : '极限话术高级版'
        }


        child_object = CategoryLessonChild.objects.get(name=dic.get(type)).lesson.all().order_by('-created')


        pg = MyPageNumberPagination()
        # 获取分页的数据
        page_child_lesson = pg.paginate_queryset(queryset=child_object,request=request,view=self)

        # 对数据进行序列化
        serializer = LessonSerializer(instance=page_child_lesson, many=True)

        return pg.get_paginated_response(serializer.data)
Ejemplo n.º 7
0
    def get(self, request, *args, **kwargs):
        namespace = request.query_params.dict().get('namespace')
        context = {'errcode': 0, 'msg': '获取Deployment成功!', 'data': ''}
        try:
            if namespace:
                ret = apps_v1.list_namespaced_deployment(namespace=namespace)
            else:
                ret = apps_v1.list_deployment_for_all_namespaces()
            tmp_context = []
            for i in ret.items:
                tmp_dict = dict()
                tmp_dict['name'] = i.metadata.name
                tmp_dict['namespace'] = i.metadata.namespace
                tmp_dict['labels'] = i.metadata.labels
                from django.utils import timezone
                tmp_dict['create_time'] = timezone.localtime(
                    i.metadata.creation_timestamp).strftime(
                        "%Y-%m-%d %H:%M:%S")
                tmp_dict['image'] = i.spec.template.spec.containers[0].image
                tmp_dict['replicas'] = i.spec.replicas
                tmp_dict['available_replicas'] = i.status.available_replicas
                tmp_dict['ready_replicas'] = i.status.ready_replicas
                tmp_dict[
                    'unavailable_replicas'] = i.status.unavailable_replicas
                tmp_dict['updated_replicas'] = i.status.updated_replicas
                tmp_context.append(tmp_dict)
            paginator = MyPageNumberPagination()
            page_publish_list = paginator.paginate_queryset(tmp_context,
                                                            self.request,
                                                            view=self)
            ps = DeploymentSerializers(page_publish_list, many=True)
            response = paginator.get_paginated_response(ps.data)
            return response

        except Exception as e:
            context['errcode'] = 1000
            context['msg'] = e
        return Response(context)