本文整理汇总了Python中pulp.server.webservices.views.util.generate_json_response函数的典型用法代码示例。如果您正苦于以下问题:Python generate_json_response函数的具体用法?Python generate_json_response怎么用?Python generate_json_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generate_json_response函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: put
def put(self, request, upload_id, offset):
"""
Upload to a specific file upload.
:param request: WSGI request object, body contains bits to upload
:type request: django.core.handlers.wsgi.WSGIRequest
:param upload_id: id of the initialized upload
:type upload_id: str
:param offset: place in the uploaded file to start writing
:type offset: str of an integer
:return: response containing null
:rtype: django.http.HttpResponse
:raises: pulp.server.exceptions.MissingResource if upload ID does not exist
:raises: InvalidValue if offset cannot be converted to an integer
"""
try:
offset = int(offset)
except ValueError:
raise InvalidValue(["offset"])
upload_manager = factory.content_upload_manager()
# If the upload ID doesn't exists, either because it was not initialized
# or was deleted, the call to the manager will raise missing resource
upload_manager.save_data(upload_id, offset, request.body)
return generate_json_response(None)
开发者ID:credativ,项目名称:pulp,代码行数:28,代码来源:content.py
示例2: _get
def _get(self, schedule_id, resource_href):
"""
Gets and returns a schedule by ID, in dict form suitable for json serialization and
end-user presentation.
:param resource_href: href of the schedule
:type resource_href: str
:param schedule_id: unique ID of a schedule
:type schedule_id: basestring
:return: dictionary representing the schedule
:rtype: dict
:raise pulp.server.exceptions.MissingResource: if schedule is not found
"""
# If schedule_id is not a valid bson ObjectId, this will raise InvalidValue. If the
# schedule_id is a valid bson ObjectId but doesn't exist it will raise StopIteration.
# Either should be a 404.
try:
schedule = next(iter(schedule_utils.get([schedule_id])))
except (StopIteration, pulp_exceptions.InvalidValue):
raise pulp_exceptions.MissingResource(schedule_id=schedule_id)
ret = schedule.for_display()
ret['_href'] = resource_href
return generate_json_response(ret)
开发者ID:alanoe,项目名称:pulp,代码行数:27,代码来源:schedule.py
示例3: post
def post(self, request):
"""
Revoke permissions from a role.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:return: An empty response
:rtype: django.http.HttpResponse
"""
params = request.body_as_json
role_id = params.get('role_id', None)
resource = params.get('resource', None)
operation_names = params.get('operations', None)
_validate_params({'role_id': role_id,
'resource': resource,
'operation_names': operation_names})
role_manager = factory.role_manager()
permission_manager = factory.permission_manager()
operations = permission_manager.operation_names_to_values(operation_names)
remove_perm = role_manager.remove_permissions_from_role(role_id, resource, operations)
return generate_json_response(remove_perm)
开发者ID:jeremycline,项目名称:pulp,代码行数:25,代码来源:permissions.py
示例4: put
def put(self, request, repo_id, importer_id, schedule_id):
"""
Update a scheduled repository sync.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param repo_id: id of the repository
:type repo_id: str
:param importer_id: id of the importer
:type importer_id: str
:param schedule_id: id of the scheduled repository sync to update
:type schedule)id: str
:return: information about the updated scheduled sync
:rtype: django.http.HttpResponse
"""
if 'schedule' in request.body_as_json:
request.body_as_json['iso_schedule'] = request.body_as_json.pop('schedule')
schedule = self.manager.update(repo_id, importer_id, schedule_id, request.body_as_json)
ret = schedule.for_display()
ret['_href'] = reverse(
'repo_sync_schedule_resource',
kwargs={'repo_id': repo_id, 'importer_id': importer_id, 'schedule_id': schedule_id}
)
return generate_json_response(ret)
开发者ID:grizax,项目名称:pulp,代码行数:26,代码来源:repositories.py
示例5: post
def post(self, request, repo_id, importer_id):
"""
Create a new scheduled sync.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param repo_id: id of the repository
:type repo_id: str
:param importer_id: create a new scheduled sync for this importer
:type importer_id: str
:return: Response containing a serialized dict of the new scheduled sync
:rtype : django.http.HttpResponse
:raises exceptions.UnsupportedValue: if there are unsupported request body params
"""
manager = manager_factory.repo_sync_schedule_manager()
sync_options = {'override_config': request.body_as_json.pop('override_config', {})}
schedule = request.body_as_json.pop('schedule', None)
failure_threshold = request.body_as_json.pop('failure_threshold', None)
enabled = request.body_as_json.pop('enabled', True)
if request.body_as_json:
raise exceptions.UnsupportedValue(request.body_as_json.keys())
scheduled_call = manager.create(repo_id, importer_id, sync_options,
schedule, failure_threshold, enabled)
display_call = scheduled_call.for_display()
display_call['_href'] = reverse(
'repo_sync_schedule_resource',
kwargs={'repo_id': repo_id, 'importer_id': importer_id,
'schedule_id': scheduled_call['id']}
)
response = generate_json_response(display_call)
return generate_redirect_response(response, display_call['_href'])
开发者ID:grizax,项目名称:pulp,代码行数:34,代码来源:repositories.py
示例6: get
def get(self, request, repo_id, importer_id):
"""
Retrieve a list of all scheduled syncs for the given importer and repo.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param repo_id: id of the repository
:type repo_id: str
:param importer_id: retrieve the scheduled syncs of this importer
:type importer_id: str
:return: Response containing a list of dicts, one for each scheduled sync
:rtype : django.http.HttpResponse
"""
manager = manager_factory.repo_sync_schedule_manager()
schedules = manager.list(repo_id, importer_id)
for_display = [schedule.for_display() for schedule in schedules]
for entry in for_display:
entry['_href'] = reverse(
'repo_sync_schedule_resource',
kwargs={'repo_id': repo_id, 'importer_id': importer_id, 'schedule_id': entry['_id']}
)
return generate_json_response(for_display)
开发者ID:grizax,项目名称:pulp,代码行数:25,代码来源:repositories.py
示例7: get
def get(self, request, type_id):
"""
Return a response containing a dict with info about a content type.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param type_id: type of content unit
:type type_id: str
:return: response containing a dict that contains info about a content type or
404 response if the specified content type is not found.
:rtype : django.http.HttpResponse or HttpResponseNotFound
"""
cqm = factory.content_query_manager()
content_type = cqm.get_content_type(type_id)
if content_type is None:
msg = _('No content type resource: %(r)s') % {'r': type_id}
return generate_json_response(msg, response_class=HttpResponseNotFound)
resource = serialization.content.content_type_obj(content_type)
# These urls are not valid endpoints but are left here for for semantic versioning.
# BZ - 1187287
links = {
'actions': {'_href': '/'.join([request.get_full_path().rstrip('/'), 'actions/'])},
'content_units': {'_href': '/'.join([request.get_full_path().rstrip('/'), 'units/'])}
}
resource.update(links)
return generate_json_response_with_pulp_encoder(resource)
开发者ID:beav,项目名称:pulp,代码行数:27,代码来源:content.py
示例8: post
def post(self, request):
"""
Grant permissions to a role.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:return: An empty response
:rtype: django.http.HttpResponse
"""
params = request.body_as_json
role_id = params.get('role_id', None)
resource = params.get('resource', None)
operation_names = params.get('operations', None)
_check_invalid_params({'role_id': role_id,
'resource': resource,
'operation_names': operation_names})
# Grant permission synchronously
role_manager = factory.role_manager()
permission_manager = factory.permission_manager()
operations = permission_manager.operation_names_to_values(operation_names)
add_perm = role_manager.add_permissions_to_role(role_id, resource, operations)
return generate_json_response(add_perm)
开发者ID:hgschmie,项目名称:pulp,代码行数:25,代码来源:permissions.py
示例9: format_results
def format_results(self, data, get_dict, path):
"""
Format the results and begin streaming out to the caller for the v3 API
:param data: The module data to stream back to the caller
:type data: dict
:param get_dict: The GET parameters
:type get_dict: dict
:param path: The path starting with parameters
:type get_dict: dict
:return: the body of what should be streamed out to the caller
:rtype: str
"""
module_name = get_dict.get("module", "")
path_parameter = get_dict.get("path", None)
module_list = data.get(module_name)
if not path_parameter:
limit = int(get_dict.get("limit", 20))
current_offset = int(get_dict.get("offset", 0))
module_version = get_dict.get("version", None)
first_path = self._format_query_string(path, module_name, module_version, 0, limit)
current_path = self._format_query_string(path, module_name, module_version, current_offset, limit)
if current_offset > 0:
previous_path = self._format_query_string(
path, module_name, module_version, current_offset - limit, limit
)
else:
previous_path = None
formatted_results = {
"pagination": {
"limit": limit,
"offset": current_offset,
"first": first_path,
"previous": previous_path,
"current": current_path,
"next": None,
"total": 1,
},
"results": [],
}
total_count = len(module_list)
for module in module_list[current_offset : (current_offset + limit)]:
formatted_module = self._format_module(module_name, module)
formatted_results["results"].append(formatted_module)
formatted_results["pagination"]["total"] = total_count
if total_count > (current_offset + limit):
next_path = self._format_query_string(path, module_name, module_version, current_offset + limit, limit)
formatted_results["pagination"]["next"] = next_path
else:
formatted_module = self._format_module(module_name, module_list[0])
formatted_results = formatted_module
return generate_json_response(formatted_results)
开发者ID:pcreech,项目名称:pulp_puppet,代码行数:59,代码来源:releases.py
示例10: test_generate_json_response_not_found
def test_generate_json_response_not_found(self):
"""
Test that response is correct for non-base HttpResponses
"""
response = util.generate_json_response(None, HttpResponseNotFound)
self.assertTrue(isinstance(response, HttpResponseNotFound))
self.assertEqual(response.status_code, 404)
self.assertEqual(response._headers.get('content-type'),
('Content-Type', 'application/json'))
开发者ID:credativ,项目名称:pulp,代码行数:9,代码来源:test_util.py
示例11: test_generate_json_response_default_params
def test_generate_json_response_default_params(self):
"""
Make sure that the response is correct under normal conditions.
"""
test_content = {'foo': 'bar'}
response = util.generate_json_response(test_content)
self.assertTrue(isinstance(response, HttpResponse))
self.assertEqual(response.status_code, 200)
self.assertEqual(response._headers.get('content-type'),
('Content-Type', 'application/json'))
response_content = json.loads(response.content)
self.assertEqual(response_content, test_content)
开发者ID:credativ,项目名称:pulp,代码行数:12,代码来源:test_util.py
示例12: get
def get(self, request, type_id, unit_id):
"""
Return user metadata for a content unit.
:param type_id: The Unit's type id.
:type type_id: basestring
:param unit_id: The id of the unit that you wish to set the pulp_user_metadata field on
:type unit_id: basestring
:return: response containing pulp user metadata field
:rtype: django.http.HttpResponse or HttpResponseNotFound
"""
cqm = factory.content_query_manager()
try:
unit = cqm.get_content_unit_by_id(type_id, unit_id)
except MissingResource:
msg = _("No content unit resource: %(r)s") % {"r": unit_id}
return generate_json_response(msg, HttpResponseNotFound)
resource = serial_content.content_unit_obj(unit[constants.PULP_USER_METADATA_FIELDNAME])
return generate_json_response(resource)
开发者ID:credativ,项目名称:pulp,代码行数:21,代码来源:content.py
示例13: post
def post(self, request):
"""
Return client SSL certificate and a private key.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:return: Response containing cert and key
:rtype: django.http.HttpResponse
"""
user = factory.principal_manager().get_principal()
key, certificate = factory.cert_generation_manager().make_admin_user_cert(user)
key_cert = {'key': key, 'certificate': certificate}
return generate_json_response(key_cert)
开发者ID:alanoe,项目名称:pulp,代码行数:13,代码来源:root_actions.py
示例14: delete
def delete(self, request, consumer_group_id):
"""
Delete a specified consumer group.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param consumer_group_id: id for the requested group
:type consumer_group_id: str
:return: An empty response
:rtype: django.http.HttpResponse
"""
manager = factory.consumer_group_manager()
result = manager.delete_consumer_group(consumer_group_id)
return generate_json_response(result)
开发者ID:credativ,项目名称:pulp,代码行数:14,代码来源:consumer_groups.py
示例15: delete
def delete(self, request, task_id):
"""
Dispatch tasks.cancel to delete a single task.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param task_id: The ID of the task you wish to cancel
:type task_id: basestring
:return: Response containing None
:rtype: django.http.HttpResponse
"""
tasks.cancel(task_id)
return generate_json_response(None)
开发者ID:credativ,项目名称:pulp,代码行数:14,代码来源:tasks.py
示例16: delete
def delete(self, request, repo_group_id):
"""
Delete the specified repo group.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param repo_group_id: id of repo group to delete
:type repo_group_id: str
:return: An empty response
:rtype: django.http.HttpResponse
"""
manager = managers_factory.repo_group_manager()
manager.delete_repo_group(repo_group_id)
return generate_json_response(None)
开发者ID:jeremycline,项目名称:pulp,代码行数:15,代码来源:repo_groups.py
示例17: delete
def delete(self, request, upload_id):
"""
Delete a single upload.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param upload_id: id of the upload to be deleted
:type upload_id: str
:return: response with None
:rtype: django.http.HttpResponse
"""
upload_manager = factory.content_upload_manager()
upload_manager.delete_upload(upload_id)
return generate_json_response(None)
开发者ID:credativ,项目名称:pulp,代码行数:15,代码来源:content.py
示例18: post
def post(self, request, *args, **kwargs):
"""
Initialize an upload and return a serialized dict containing the upload data.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:return : Serialized response containing a url to delete an upload and a unique id.
:rtype : django.http.HttpResponse
"""
upload_manager = factory.content_upload_manager()
upload_id = upload_manager.initialize_upload()
href = reverse("content_upload_resource", kwargs={"upload_id": upload_id})
response = generate_json_response({"_href": href, "upload_id": upload_id})
response_redirect = generate_redirect_response(response, href)
return response_redirect
开发者ID:credativ,项目名称:pulp,代码行数:15,代码来源:content.py
示例19: delete
def delete(self, request, role_id):
"""
Delete a role.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param role_id: id for the requested role
:type role_id: str
:return: An empty response
:rtype: django.http.HttpResponse
"""
manager = factory.role_manager()
result = manager.delete_role(role_id)
return generate_json_response(result)
开发者ID:pcreech,项目名称:pulp,代码行数:15,代码来源:roles.py
示例20: get
def get(self, request):
"""
Return a response containing a serialized list of importers present in the server.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:return : Response containing a serialized list of dicts containing importer data
:rtype : django.http.HttpResponse
"""
manager = factory.plugin_manager()
all_importers = manager.importers()
for importer in all_importers:
importer['_href'] = '/'.join([request.get_full_path().rstrip('/'), importer['id'], ''])
return generate_json_response(all_importers)
开发者ID:beav,项目名称:pulp,代码行数:16,代码来源:plugins.py
注:本文中的pulp.server.webservices.views.util.generate_json_response函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论