当前位置: 首页>>代码示例>>Python>>正文


Python util.generate_json_response_with_pulp_encoder函数代码示例

本文整理汇总了Python中pulp.server.webservices.views.util.generate_json_response_with_pulp_encoder函数的典型用法代码示例。如果您正苦于以下问题:Python generate_json_response_with_pulp_encoder函数的具体用法?Python generate_json_response_with_pulp_encoder怎么用?Python generate_json_response_with_pulp_encoder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了generate_json_response_with_pulp_encoder函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_generate_json_response_with_pulp_encoder

 def test_generate_json_response_with_pulp_encoder(self, mock_json):
     """
     Ensure that the shortcut function uses the specified encoder.
     """
     test_content = {'foo': 'bar'}
     util.generate_json_response_with_pulp_encoder(test_content)
     mock_json.dumps.assert_called_once_with(test_content, default=pulp_json_encoder)
开发者ID:credativ,项目名称:pulp,代码行数:7,代码来源:test_util.py

示例2: get

    def get(self, request):
        """
        List all roles.

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

        :return: Response containing a list of roles
        :rtype: django.http.HttpResponse
        """
        role_query_manager = factory.role_query_manager()
        user_query_manager = factory.user_query_manager()
        permissions_manager = factory.permission_manager()
        roles = role_query_manager.find_all()
        for role in roles:
            role['users'] = [u['login'] for u in
                             user_query_manager.find_users_belonging_to_role(role['id'])]

            resource_permission = {}
            # isolate schema change
            if role['permissions']:
                for item in role['permissions']:
                    resource = item['resource']
                    operations = item.get('permission', [])
                    resource_permission[resource] = [permissions_manager.operation_value_to_name(o)
                                                     for o in operations]

            role['permissions'] = resource_permission

            link = {'_href': reverse('role_resource',
                    kwargs={'role_id': role['id']})}
            role.update(link)
        return generate_json_response_with_pulp_encoder(roles)
开发者ID:hgschmie,项目名称:pulp,代码行数:33,代码来源:roles.py

示例3: get

    def get(self, request):
        """
        List all roles.

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

        :return: Response containing a list of roles
        :rtype: django.http.HttpResponse
        """
        role_query_manager = factory.role_query_manager()
        permissions_manager = factory.permission_manager()
        roles = role_query_manager.find_all()
        for role in roles:
            users = [u.login for u in user_controller.find_users_belonging_to_role(role["id"])]
            role["users"] = users

            resource_permission = {}
            # isolate schema change
            if role["permissions"]:
                for item in role["permissions"]:
                    resource = item["resource"]
                    operations = item.get("permission", [])
                    resource_permission[resource] = [permissions_manager.operation_value_to_name(o) for o in operations]

            role["permissions"] = resource_permission

            link = {"_href": reverse("role_resource", kwargs={"role_id": role["id"]})}
            role.update(link)
        return generate_json_response_with_pulp_encoder(roles)
开发者ID:pcreech,项目名称:pulp,代码行数:30,代码来源:roles.py

示例4: get

    def get(self, request):
        """
        Show current status of pulp server.

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

        :return: Response showing surrent server status
        :rtype: django.http.HttpResponse
        """
        pulp_version = status_manager.get_version()
        pulp_db_connection = status_manager.get_mongo_conn_status()
        pulp_messaging_connection = status_manager.get_broker_conn_status()

        # do not ask for the worker list unless we have a DB connection
        if pulp_db_connection['connected']:
            # convert Worker documents to dicts
            pulp_workers = [w.to_mongo().to_dict() for w in status_manager.get_workers()]
        else:
            pulp_workers = []

        # 'api_version' is deprecated and can go away in 3.0, bz #1171763
        status_data = {'api_version': '2',
                       'versions': pulp_version,
                       'database_connection': pulp_db_connection,
                       'messaging_connection': pulp_messaging_connection,
                       'known_workers': pulp_workers}

        return generate_json_response_with_pulp_encoder(status_data)
开发者ID:alanoe,项目名称:pulp,代码行数:29,代码来源:status.py

示例5: get

    def get(self, request, consumer_id, schedule_id):
        """
        List a specific schedule <action>.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: The consumer ID.
        :type consumer_id: str
        :param schedule_id: the schedule id
        :type schedule_id: str

        :raises MissingResource: if consumer/schedule does not exist

        :return: Response containing consumer's schedule <action>
        :rtype: django.http.HttpResponse
        """

        scheduled_call = None
        for call in self.manager.get(consumer_id, self.ACTION):
            if call.id == schedule_id:
                scheduled_call = call
                break
        if scheduled_call is None:
            raise MissingResource(consumer_id=consumer_id, schedule_id=schedule_id)

        scheduled_obj = scheduled_unit_management_obj(scheduled_call.for_display())
        add_link_schedule(scheduled_obj, self.ACTION, consumer_id)
        return generate_json_response_with_pulp_encoder(scheduled_obj)
开发者ID:alanoe,项目名称:pulp,代码行数:28,代码来源:consumers.py

示例6: post

    def post(self, request, consumer_id):
        """
        Associate a profile with a consumer by content type ID.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: A consumer ID.
        :type consumer_id: str

        :raises MissingValue: if some parameter were not provided

        :return: Response representing the created profile
        :rtype: django.http.HttpResponse
        """

        body = request.body_as_json
        content_type = body.get('content_type')
        profile = body.get('profile')

        manager = factory.consumer_profile_manager()
        new_profile = manager.create(consumer_id, content_type, profile)
        if content_type is None:
            raise MissingValue('content_type')
        link = add_link_profile(new_profile)
        response = generate_json_response_with_pulp_encoder(new_profile)
        redirect_response = generate_redirect_response(response, link['_href'])
        return redirect_response
开发者ID:alanoe,项目名称:pulp,代码行数:27,代码来源:consumers.py

示例7: post

    def post(self, request):
        """
        Create a new repo. `id` field in body is required. `display_name` will default to `id`.

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

        :return: Response containing a serialized dict for the created repo.
        :rtype : django.http.HttpResponse
        """
        repo_data = request.body_as_json
        repo_id = repo_data.get('id')

        repo_obj = repo_controller.create_repo(
            repo_id,
            display_name=repo_data.get('display_name', repo_id),
            description=repo_data.get('description'),
            notes=repo_data.get('notes'),
            importer_type_id=repo_data.get('importer_type_id'),
            importer_repo_plugin_config=repo_data.get('importer_config'),
            distributor_list=repo_data.get('distributors')
        )

        repo = serializers.Repository(repo_obj).data
        response = generate_json_response_with_pulp_encoder(repo)
        return generate_redirect_response(response, repo['_href'])
开发者ID:grizax,项目名称:pulp,代码行数:26,代码来源:repositories.py

示例8: post

    def post(self, request):
        """
        Create a repo group from the data passed in the body.

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

        :return: Response containing a serialized dict of the new repo group
        :rtype: django.http.HttpResponse
        :raises pulp_exceptions.MissingValue: if required values are not passed into the body
        :raises pulp_exceptions.InvalidValue: if invalid values are passed into the body
        """
        group_data = request.body_as_json
        group_id = group_data.pop('id', None)
        if group_id is None:
            raise pulp_exceptions.MissingValue(['id'])
        display_name = group_data.pop('display_name', None)
        description = group_data.pop('description', None)
        repo_ids = group_data.pop('repo_ids', None)
        notes = group_data.pop('notes', None)
        distributors = group_data.pop('distributors', None)
        if group_data:
            raise pulp_exceptions.InvalidValue(group_data.keys())
        # Create the repo group
        manager = managers_factory.repo_group_manager()
        args = [group_id, display_name, description, repo_ids, notes]
        kwargs = {'distributor_list': distributors}
        group = manager.create_and_configure_repo_group(*args, **kwargs)
        group = _add_group_link(group)
        group['distributors'] = distributors or []
        response = generate_json_response_with_pulp_encoder(group)
        return generate_redirect_response(response, group['_href'])
开发者ID:jeremycline,项目名称:pulp,代码行数:32,代码来源:repo_groups.py

示例9: get

    def get(self, request, repo_id):
        """
        Retrieve sync history for a specified repository.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of the repository
        :type  repo_id: str

        :return: Response containing a list of dicts, one for each sync event
        :rtype : django.http.HttpResponse
        :raises pulp_exceptions.InvalidValue: if limit is not an integer
        """

        sort = request.GET.get(constants.REPO_HISTORY_FILTER_SORT)
        start_date = request.GET.get(constants.REPO_HISTORY_FILTER_START_DATE)
        end_date = request.GET.get(constants.REPO_HISTORY_FILTER_END_DATE)
        limit = request.GET.get(constants.REPO_HISTORY_FILTER_LIMIT)
        if limit:
            try:
                limit = int(limit)
            except ValueError:
                raise pulp_exceptions.InvalidValue([constants.REPO_HISTORY_FILTER_LIMIT])
        if not sort:
            sort = constants.SORT_DESCENDING

        sync_manager = manager_factory.repo_sync_manager()
        # Error checking is done on these options in the sync manager before the database is queried
        entries = sync_manager.sync_history(repo_id, limit=limit, sort=sort, start_date=start_date,
                                            end_date=end_date)
        return generate_json_response_with_pulp_encoder(entries)
开发者ID:hgschmie,项目名称:pulp,代码行数:31,代码来源:repositories.py

示例10: post

    def post(self, request, repo_id):
        """
        Associate a distributor with a repository.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: The id of the repository to associate with
        :type  repo_id: str

        :return: Response containing a dict of the associated distributor
        :rtype : django.http.HttpResponse
        """

        # Validation will occur in the manager
        distributor_type = request.body_as_json.get('distributor_type_id', None)
        distributor_config = request.body_as_json.get('distributor_config', None)
        distributor_id = request.body_as_json.get('distributor_id', None)
        auto_publish = request.body_as_json.get('auto_publish', False)

        distributor_manager = manager_factory.repo_distributor_manager()
        distributor = distributor_manager.add_distributor(
            repo_id, distributor_type, distributor_config, auto_publish, distributor_id
        )
        distributor['_href'] = reverse(
            'repo_distributor_resource',
            kwargs={'repo_id': repo_id, 'distributor_id': distributor['id']}
        )
        response = generate_json_response_with_pulp_encoder(distributor)
        return generate_redirect_response(response, distributor['_href'])
开发者ID:hgschmie,项目名称:pulp,代码行数:29,代码来源:repositories.py

示例11: put

    def put(self, request, repo_id):
        """
        Update a repository. This call will return synchronously unless a distributor is updated.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of repository to be updated
        :type  repo_id: str

        :return: Response containing a serialized dict for the updated repo.
        :rtype : django.http.HttpResponse
        :raises pulp_exceptions.OperationPostponed: if a distributor is updated, dispatch a task
        """

        delta = request.body_as_json.get('delta', None)
        importer_config = request.body_as_json.get('importer_config', None)
        distributor_configs = request.body_as_json.get('distributor_configs', None)
        repo_manager = manager_factory.repo_manager()
        task_result = repo_manager.update_repo_and_plugins(repo_id, delta, importer_config,
                                                           distributor_configs)
        repo = task_result.return_value
        repo['_href'] = reverse('repo_resource', kwargs={'repo_id': repo_id})
        _convert_repo_dates_to_strings(repo)

        # Tasks are spawned if a distributor is updated, raise that as a result
        if task_result.spawned_tasks:
            raise pulp_exceptions.OperationPostponed(task_result)

        result = task_result.serialize()
        return generate_json_response_with_pulp_encoder(result)
开发者ID:hgschmie,项目名称:pulp,代码行数:30,代码来源:repositories.py

示例12: get

    def get(self, request, repo_id):
        """
        Looks for query parameters 'importers' and 'distributors', and will add
        the corresponding fields to the repository returned. Query parameter
        'details' is equivalent to passing both 'importers' and 'distributors'.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of requested repository
        :type  repo_id: str

        :return: Response containing a serialized dict for the requested repo.
        :rtype : django.http.HttpResponse
        :raises exceptions.MissingResource: if repo cannot be found
        """
        repo_obj = model.Repository.objects.get_repo_or_missing_resource(repo_id)
        repo = serializers.Repository(repo_obj).data

        # Add importers and distributors to the dicts if requested.
        details = request.GET.get('details', 'false').lower() == 'true'
        if request.GET.get('importers', 'false').lower() == 'true' or details:
            _merge_related_objects('importers', model.Importer, (repo,))
        if request.GET.get('distributors', 'false').lower() == 'true' or details:
            _merge_related_objects('distributors', model.Distributor, (repo,))
        if details:
            repo['total_repository_units'] = sum(repo['content_unit_counts'].itervalues())
            total_missing = repo_controller.missing_unit_count(repo_obj.repo_id)
            repo['locally_stored_units'] = repo['total_repository_units'] - total_missing

        return generate_json_response_with_pulp_encoder(repo)
开发者ID:grizax,项目名称:pulp,代码行数:30,代码来源:repositories.py

示例13: put

    def put(self, request, repo_group_id, distributor_id):
        """
        Change information about a single repo group distributor association.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_group_id: repo group the distributor is associated with
        :type  repo_group_id: str
        :param distributor_id: distributor to update
        :type  distributor_id: str

        :return: response containing a serialized dict of the modified distributor association
        :rtype: django.http.HttpResponse
        :raises pulp_exceptions.MissingValue: if param 'distributor_config' is not in the body
        """
        params = request.body_as_json
        distributor_config = params.get('distributor_config', None)
        if distributor_config is None:
            raise pulp_exceptions.MissingValue(['distributor_config'])
        distributor_manager = managers_factory.repo_group_distributor_manager()
        result = distributor_manager.update_distributor_config(repo_group_id, distributor_id,
                                                               distributor_config)
        result['_href'] = reverse(
            'repo_group_distributor_resource',
            kwargs={'repo_group_id': repo_group_id, 'distributor_id': distributor_id}
        )
        return generate_json_response_with_pulp_encoder(result)
开发者ID:jeremycline,项目名称:pulp,代码行数:27,代码来源:repo_groups.py

示例14: put

    def put(self, request, repo_id):
        """
        Update a repository. This call will return synchronously unless a distributor is updated.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of repository to be updated
        :type  repo_id: str

        :return: Response containing a serialized dict for the updated repo.
        :rtype : django.http.HttpResponse

        :raises exceptions.OperationPostponed: if a task has been dispatched to update a
                                                    distributor
        """

        delta = request.body_as_json.get('delta', None)
        importer_config = request.body_as_json.get('importer_config', None)
        distributor_configs = request.body_as_json.get('distributor_configs', None)

        repo = model.Repository.objects.get_repo_or_missing_resource(repo_id)
        task_result = repo_controller.update_repo_and_plugins(repo, delta, importer_config,
                                                              distributor_configs)

        # Tasks are spawned if a distributor is updated, raise that as a result
        if task_result.spawned_tasks:
            raise exceptions.OperationPostponed(task_result)

        call_report = task_result.serialize()
        call_report['result'] = serializers.Repository(call_report['result']).data
        return generate_json_response_with_pulp_encoder(call_report)
开发者ID:grizax,项目名称:pulp,代码行数:31,代码来源:repositories.py

示例15: _generate_response

    def _generate_response(cls, query, options, *args, **kwargs):
        """
        Perform the database query using the given search data, and return the resuls as a JSON
        serialized HttpReponse object.

        This overrides the base class so we can validate repo existance and to choose the search
        method depending on how many unit types we are dealing with.

        :param query: The criteria that should be used to search for objects
        :type  query: dict
        :param options: additional options for including extra data
        :type  options: dict

        :return:      The serialized search results in an HttpReponse
        :rtype:       django.http.HttpResponse
        """
        repo_id = kwargs.get('repo_id')
        model.Repository.objects.get_repo_or_missing_resource(repo_id)
        criteria = UnitAssociationCriteria.from_client_input(query)
        manager = manager_factory.repo_unit_association_query_manager()
        if criteria.type_ids is not None and len(criteria.type_ids) == 1:
            type_id = criteria.type_ids[0]
            units = manager.get_units_by_type(repo_id, type_id, criteria=criteria)
        else:
            units = manager.get_units(repo_id, criteria=criteria)
        for unit in units:
            content.remap_fields_with_serializer(unit['metadata'])
        return generate_json_response_with_pulp_encoder(units)
开发者ID:grizax,项目名称:pulp,代码行数:28,代码来源:repositories.py


注:本文中的pulp.server.webservices.views.util.generate_json_response_with_pulp_encoder函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。