示例#1
0
    def get(self, request, *args, **kwargs):
        """Returns a list of environment by ids ou dict."""

        if not kwargs.get('obj_ids'):
            obj_model = facade.get_environment_by_search(self.search)
            environments = obj_model['query_set']
            only_main_property = False
        else:
            environment_ids = kwargs.get('obj_ids').split(';')
            environments = facade.get_environment_by_ids(environment_ids)
            only_main_property = True
            obj_model = None

        # serializer environments
        serializer_env = serializers.EnvironmentV3Serializer(
            environments,
            many=True,
            fields=self.fields,
            include=self.include,
            exclude=self.exclude,
            kind=self.kind)

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

        return Response(data, status=status.HTTP_200_OK)
示例#2
0
    def get(self, request, *args, **kwargs):
        """Returns a list of environment by ids ou dict."""

        if not kwargs.get('obj_ids'):
            obj_model = facade.get_environment_by_search(self.search)
            environments = obj_model['query_set']
            only_main_property = False
        else:
            environment_ids = kwargs.get('obj_ids').split(';')
            environments = facade.get_environment_by_ids(environment_ids)
            only_main_property = True
            obj_model = None

        # serializer environments
        serializer_env = serializers.EnvironmentV3Serializer(
            environments,
            many=True,
            fields=self.fields,
            include=self.include,
            exclude=self.exclude,
            kind=self.kind
        )

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

        return Response(data, status=status.HTTP_200_OK)
示例#3
0
    def get(self, request, *args, **kwargs):
        """Returns a list of environment by ids ou dict."""

        # String with all important fields to define response
        request_identifier_to_cache = str(self.search) + str(
            self.fields) + str(self.include) + str(self.exclude) + str(
                self.kind)

        if not kwargs.get('obj_ids'):
            data = get_cached_search(ENVIRONMENT_CACHE_ENTRY,
                                     request_identifier_to_cache)
            if data:
                return Response(data, status=status.HTTP_200_OK)

            obj_model = facade.get_environment_by_search(self.search)
            environments = obj_model['query_set']
            only_main_property = False
        else:
            environment_ids = kwargs.get('obj_ids').split(';')
            environments = facade.get_environment_by_ids(environment_ids)
            only_main_property = True
            obj_model = None

        # serializer environments
        serializer_env = serializers.EnvironmentV3Serializer(
            environments,
            many=True,
            fields=self.fields,
            include=self.include,
            exclude=self.exclude,
            kind=self.kind)

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

        set_cache_search_with_list(ENVIRONMENT_CACHE_ENTRY,
                                   request_identifier_to_cache, data,
                                   facade.get_environment_cache_time())
        return Response(data, status=status.HTTP_200_OK)