Exemplo n.º 1
0
class ConsumerContentApplicabilityView(View):
    """
    View for query content applicability.
    """
    @auth_required(authorization.READ)
    @json_body_required
    def post(self, request):
        """
        Query content applicability for a given consumer criteria query.

        body {criteria: <object>,
              content_types: <array>[optional]}

        This method returns a JSON document containing an array of objects that each have two
        keys: 'consumers', and 'applicability'. 'consumers' will index an array of consumer_ids,
        for consumers that have the same repository bindings and profiles. 'applicability' will
        index an object that will have keys for each content type that is applicable, and the
        content type ids will index the applicability data for those content types. For example,

        [{'consumers': ['consumer_1', 'consumer_2'],
          'applicability': {'content_type_1': ['unit_1', 'unit_3']}},
         {'consumers': ['consumer_2', 'consumer_3'],
          'applicability': {'content_type_1': ['unit_1', 'unit_2']}}]

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest

        :return: Response containing applicability data matching the consumer criteria query
        :rtype:  jango.http.HttpResponse
        """

        # Get the consumer_ids that match the consumer criteria query that the requestor queried
        # with, and build a map from consumer_id to a dict with profiles and repo_ids for each
        # consumer
        try:
            consumer_criteria = self._get_consumer_criteria(request)
            content_types = self._get_content_types(request)
        except InvalidValue, e:
            return HttpResponseBadRequest(str(e))

        response = retrieve_consumer_applicability(consumer_criteria,
                                                   content_types)
        return generate_json_response_with_pulp_encoder(response)
Exemplo n.º 2
0
class ContentApplicability(JSONController):
    """
    Query content applicability.
    """
    @auth_required(READ)
    def POST(self):
        """
        Query content applicability for a given consumer criteria query.

        body {criteria: <object>,
              content_types: <array>[optional]}

        This method returns a JSON document containing an array of objects that each have two
        keys: 'consumers', and 'applicability'. 'consumers' will index an array of consumer_ids,
        for consumers that have the same repository bindings and profiles. 'applicability' will
        index an object that will have keys for each content type that is applicable, and the
        content type ids will index the applicability data for those content types. For example,

        [{'consumers': ['consumer_1', 'consumer_2'],
          'applicability': {'content_type_1': ['unit_1', 'unit_3']}},
         {'consumers': ['consumer_2', 'consumer_3'],
          'applicability': {'content_type_1': ['unit_1', 'unit_2']}}]

        :return: applicability data matching the consumer criteria query
        :rtype:  str
        """
        # Get the consumer_ids that match the consumer criteria query that the requestor queried
        # with, and build a map from consumer_id to a dict with profiles and repo_ids for each
        # consumer
        try:
            consumer_criteria = self._get_consumer_criteria()
            content_types = self._get_content_types()
        except InvalidValue, e:
            return self.bad_request(str(e))

        return self.ok(
            retrieve_consumer_applicability(consumer_criteria, content_types))