コード例 #1
0
ファイル: v3.py プロジェクト: wangchaobin/GloboNetworkAPI
    def get(self, request, *args, **kwargs):
        """
        Return list of equipments

        :param rights_write(optional): Right of Write - Filter by rights of write
        :param environment(optional): Id of environment - Filter by environment
        :param ipv4(optional): Id of ipv4 - Filter by id ipv4
        :param ipv6(optional): Id of ipv6 - Filter by id ipv6
        :param is_router(optional): Boolean (True|False) - Filter for routers
        :param name(optional): Name of Equipment
        """

        if not kwargs.get('obj_id'):
            rights_write = request.GET.get('rights_write')
            environment = request.GET.get('environment')
            ipv4 = request.GET.get('ipv4')
            ipv6 = request.GET.get('ipv6')
            is_router = request.GET.get('is_router')
            environment_sdn_controller = request.GET.get(
                'environment_sdn_controller')
            name = request.GET.get('name')

            # get equipments queryset
            obj_model = facade.get_equipments(
                user=request.user,
                rights_read=1,
                environment=environment,
                ipv4=ipv4,
                ipv6=ipv6,
                rights_write=rights_write,
                name=name,
                is_router=is_router,
                environment_sdn_controller=environment_sdn_controller,
                search=self.search)
            equipments = obj_model['query_set']
            only_main_property = False

        else:
            obj_ids = kwargs.get('obj_id').split(';')
            equipments = facade.get_equipment_by_ids(obj_ids)
            only_main_property = True
            obj_model = None

        # serializer equipments
        eqpt_serializers = serializers.EquipmentV3Serializer(
            equipments,
            many=True,
            fields=self.fields,
            include=self.include,
            exclude=self.exclude,
            kind=self.kind)

        # prepare serializer with customized properties
        data = render_to_json(eqpt_serializers,
                              main_property='equipments',
                              obj_model=obj_model,
                              request=request,
                              only_main_property=only_main_property)

        return Response(data, status=status.HTTP_200_OK)
コード例 #2
0
ファイル: views.py プロジェクト: globocom/GloboNetworkAPI
    def get(self, request, *args, **kwargs):
        """
        Return list of equipments

        :param rights_write(optional): Right of Write - Filter by rights of write
        :param environment(optional): Id of environment - Filter by environment
        :param ipv4(optional): Id of ipv4 - Filter by id ipv4
        :param ipv6(optional): Id of ipv6 - Filter by id ipv6
        :param is_router(optional): Boolean (True|False) - Filter for routers
        :param name(optional): Name of Equipment
        """

        if not kwargs.get('obj_id'):
            rights_write = request.GET.get('rights_write')
            environment = request.GET.get('environment')
            ipv4 = request.GET.get('ipv4')
            ipv6 = request.GET.get('ipv6')
            is_router = request.GET.get('is_router')
            environment_sdn_controller = request.GET.get('environment_sdn_controller')
            name = request.GET.get('name')

            # get equipments queryset
            obj_model = facade_v3.get_equipments(
                user=request.user,
                rights_read=1,
                environment=environment,
                ipv4=ipv4,
                ipv6=ipv6,
                rights_write=rights_write,
                name=name,
                is_router=is_router,
                environment_sdn_controller=environment_sdn_controller,
                search=self.search
            )
            equipments = obj_model['query_set']
            only_main_property = False

        else:
            obj_ids = kwargs.get('obj_id').split(';')
            equipments = facade_v3.get_equipment_by_ids(obj_ids)
            only_main_property = True
            obj_model = None

        # serializer equipments
        eqpt_serializers = serializers.EquipmentV4Serializer(
            equipments,
            many=True,
            fields=self.fields,
            include=self.include,
            exclude=self.exclude,
            kind=self.kind
        )

        # prepare serializer with customized properties
        data = render_to_json(
            eqpt_serializers,
            main_property='equipments',
            obj_model=obj_model,
            request=request,
            only_main_property=only_main_property
        )

        return Response(data, status=status.HTTP_200_OK)