本文整理汇总了Python中pulp.server.webservices.views.util.generate_redirect_response函数的典型用法代码示例。如果您正苦于以下问题:Python generate_redirect_response函数的具体用法?Python generate_redirect_response怎么用?Python generate_redirect_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了generate_redirect_response函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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: basestring
:return: Response containing the serialized distributor
:rtype : django.http.HttpResponse
"""
distributor_type = request.body_as_json.get('distributor_type_id')
if distributor_type is None:
raise exceptions.MissingValue('distributor_type_id')
distributor_config = request.body_as_json.get('distributor_config')
distributor_id = request.body_as_json.get('distributor_id')
auto_publish = request.body_as_json.get('auto_publish', False)
distributor = dist_controller.add_distributor(repo_id, distributor_type, distributor_config,
auto_publish, distributor_id)
serialized = model.Distributor.SERIALIZER(distributor).data
response = generate_json_response_with_pulp_encoder(serialized)
return generate_redirect_response(response, serialized['_href'])
示例2: post
def post(self, request, consumer_id):
"""
Create a schedule.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:param consumer_id: The consumer ID.
:type consumer_id: str
:raises UnsupportedValue: if some extra unsupported keys were specified.
:return: Response containing just created schedule
:rtype: django.http.HttpResponse
"""
params = request.body_as_json
units = params.pop('units', None)
options = params.pop('options', {})
schedule = params.pop('schedule', None)
failure_threshold = params.pop('failure_threshold', None)
enabled = params.pop('enabled', True)
if params:
raise UnsupportedValue(params.keys())
scheduled_call = self.manager.create_schedule(
self.ACTION, consumer_id, units, options, schedule, failure_threshold, enabled)
scheduled_obj = scheduled_unit_management_obj(scheduled_call.for_display())
link = add_link_schedule(scheduled_obj, self.ACTION, consumer_id)
response = generate_json_response_with_pulp_encoder(scheduled_obj)
redirect_response = generate_redirect_response(response, link['_href'])
return redirect_response
示例3: post
def post(self, request):
"""
Create a new repo. 'id' field in body is required.
: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
"""
# Pull the repo data out of the request body (validation will occur
# in the manager)
repo_data = request.body_as_json
repo_id = repo_data.get('id', None)
display_name = repo_data.get('display_name', None)
description = repo_data.get('description', None)
notes = repo_data.get('notes', None)
importer_type_id = repo_data.get('importer_type_id', None)
importer_repo_plugin_config = repo_data.get('importer_config', None)
distributors = repo_data.get('distributors', None)
# Creation
repo_manager = manager_factory.repo_manager()
args = [repo_id, display_name, description, notes]
kwargs = {'importer_type_id': importer_type_id,
'importer_repo_plugin_config': importer_repo_plugin_config,
'distributor_list': distributors}
repo = repo_manager.create_and_configure_repo(*args, **kwargs)
repo['_href'] = reverse('repo_resource', kwargs={'repo_id': repo_id})
response = generate_json_response_with_pulp_encoder(repo)
return generate_redirect_response(response, repo['_href'])
示例4: post
def post(self, request):
"""
Create a consumer group and return a serialized object containing just created group.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:return: Response containing the consumer group
:rtype: django.http.HttpResponse
:raises: MissingValue if group ID is not provided
:raises: InvalidValue if some parameters are invalid
"""
params = request.body_as_json
group_id = params.pop('id', None)
if group_id is None:
raise pulp_exceptions.MissingValue(['id'])
display_name = params.pop('display_name', None)
description = params.pop('description', None)
consumer_ids = params.pop('consumer_ids', None)
notes = params.pop('notes', None)
if params:
raise pulp_exceptions.InvalidValue(params.keys())
manager = factory.consumer_group_manager()
group = manager.create_consumer_group(group_id, display_name, description, consumer_ids,
notes)
link = {"_href": reverse('consumer_group_resource',
kwargs={'consumer_group_id': group['id']})}
group.update(link)
response = generate_json_response_with_pulp_encoder(group)
response_redirect = generate_redirect_response(response, link['_href'])
return response_redirect
示例5: 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'])
示例6: test_generate_redirect_response
def test_generate_redirect_response(self, mock_iri_to_uri):
"""
Test HttpResponseRedirect.
"""
test_content = {'foo': 'bar'}
href = '/some/url/'
response = HttpResponse(content=test_content)
redirect_response = util.generate_redirect_response(response, href)
self.assertEqual(redirect_response.status_code, 201)
self.assertEqual(redirect_response.reason_phrase, 'CREATED')
self.assertEqual(redirect_response._headers['location'][1],
str(mock_iri_to_uri.return_value))
mock_iri_to_uri.assert_called_once_with(href)
示例7: 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
示例8: post
def post(self, request):
"""
Create a new role.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:return: Response containing the role
:rtype: django.http.HttpResponse
"""
role_data = request.body_as_json
role_id = role_data.get("role_id", None)
display_name = role_data.get("display_name", None)
description = role_data.get("description", None)
manager = factory.role_manager()
role = manager.create_role(role_id, display_name, description)
link = {"_href": reverse("role_resource", kwargs={"role_id": role["id"]})}
role.update(link)
response = generate_json_response_with_pulp_encoder(role)
redirect_response = generate_redirect_response(response, link["_href"])
return redirect_response
示例9: post
def post(self, request):
"""
Create a new user.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:return: Response containing the user
:rtype: django.http.HttpResponse
:raises: MissingValue if login field is missing
:raises: InvalidValue if some parameters are invalid
"""
# Pull all the user data
user_data = request.body_as_json
login = user_data.pop('login', None)
if login is None:
raise pulp_exceptions.MissingValue(['login'])
password = user_data.pop('password', None)
name = user_data.pop('name', None)
if user_data:
raise pulp_exceptions.InvalidValue(user_data.keys())
# Creation
manager = factory.user_manager()
args = [login]
kwargs = {'password': password,
'name': name}
user = manager.create_user(*args, **kwargs)
# Add the link to the user
link = _add_link(user)
# Grant permissions
permission_manager = factory.permission_manager()
permission_manager.grant_automatic_permissions_for_resource(link['_href'])
response = generate_json_response_with_pulp_encoder(user)
return generate_redirect_response(response, link['_href'])
示例10: post
def post(self, request):
"""
Create a new user.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:return: Response containing the user
:rtype: django.http.HttpResponse
:raises: MissingValue if login field is missing
:raises: InvalidValue if some parameters are invalid
"""
user_data = request.body_as_json
login = user_data.pop('login', None)
if login is None:
raise pulp_exceptions.MissingValue(['login'])
password = user_data.pop('password', None)
# name defaults to login
name = user_data.pop('name', login)
# Raise if extra data is passed
if user_data:
raise pulp_exceptions.InvalidValue(user_data.keys())
new_user = user_controller.create_user(login, password=password, name=name)
serialized_user = model.User.SERIALIZER(new_user).data
# For backwards compatability. See https://pulp.plan.io/issues/1125
serialized_user['id'] = str(serialized_user['_id'])
# Grant permissions
permission_manager = factory.permission_manager()
permission_manager.grant_automatic_permissions_for_resource(serialized_user['_href'])
response = generate_json_response_with_pulp_encoder(serialized_user)
return generate_redirect_response(response, serialized_user['_href'])
示例11: post
def post(self, request):
"""
Create a new event listener.
:param request: WSGI request object
:type request: django.core.handlers.wsgi.WSGIRequest
:return: Response containing the event listener
:rtype: django.http.HttpResponse
"""
params = request.body_as_json
notifier_type_id = params.get('notifier_type_id', None)
notifier_config = params.get('notifier_config', None)
event_types = params.get('event_types', None)
manager = factory.event_listener_manager()
event = manager.create(notifier_type_id, notifier_config, event_types)
link = add_link(event)
response = generate_json_response_with_pulp_encoder(event)
redirect_response = generate_redirect_response(response, link['_href'])
return redirect_response