本文整理汇总了Python中rest_framework.status.HTTP_202_ACCEPTED属性的典型用法代码示例。如果您正苦于以下问题:Python status.HTTP_202_ACCEPTED属性的具体用法?Python status.HTTP_202_ACCEPTED怎么用?Python status.HTTP_202_ACCEPTED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类rest_framework.status
的用法示例。
在下文中一共展示了status.HTTP_202_ACCEPTED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def post(self, request, *args, **kwargs):
# Check password and extract email
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
new_email = serializer.validated_data['new_email']
action = models.AuthenticatedChangeEmailUserAction(user=request.user, new_email=new_email)
verification_code = serializers.AuthenticatedChangeEmailUserActionSerializer(action).data['code']
request.user.send_email('change-email', recipient=new_email, context={
'confirmation_link': reverse('confirm-change-email', request=request, args=[verification_code]),
'old_email': request.user.email,
'new_email': new_email,
})
# At this point, we know that we are talking to the user, so we can tell that we sent an email.
return Response(data={'detail': 'Please check your mailbox to confirm email address change.'},
status=status.HTTP_202_ACCEPTED)
示例2: _labels_delete
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def _labels_delete(label, instance):
"""Delete a label from an instance.
:param instance: object to delete label from.
:param label: the label to delete.
:returns the status and all the tags.
"""
count = instance.tags.count()
instance.tags.remove(label)
if isinstance(instance, XForm):
xform_tags_delete.send(sender=XForm, xform=instance, tag=label)
# Accepted, label does not exist hence nothing removed
http_status = status.HTTP_202_ACCEPTED if count == instance.tags.count()\
else status.HTTP_200_OK
return [http_status, list(instance.tags.names())]
示例3: test_add_objective_no_sync_ok
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def test_add_objective_no_sync_ok(self):
self.add_default_data_manager()
pkhash, data = self.get_default_objective_data()
url = reverse('substrapp:objective-list')
extra = {
'HTTP_ACCEPT': 'application/json;version=0.0',
}
with mock.patch('substrapp.ledger.invoke_ledger') as minvoke_ledger:
minvoke_ledger.return_value = {
'message': 'Objective added in local db waiting for validation.'
'The substra network has been notified for adding this Objective'
}
response = self.client.post(url, data, format='multipart', **extra)
r = response.json()
self.assertEqual(r['pkhash'], pkhash)
self.assertEqual(r['validated'], False)
self.assertEqual(r['description'],
f'http://testserver/media/objectives/{r["pkhash"]}/{self.objective_description_filename}')
self.assertEqual(r['metrics'],
f'http://testserver/media/objectives/{r["pkhash"]}/{self.objective_metrics_filename}')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
示例4: test_add_algo_no_sync_ok
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def test_add_algo_no_sync_ok(self):
self.add_default_objective()
pkhash, data = self.get_default_algo_data()
url = reverse('substrapp:algo-list')
extra = {
'HTTP_ACCEPT': 'application/json;version=0.0',
}
with mock.patch('substrapp.ledger.invoke_ledger') as minvoke_ledger:
minvoke_ledger.return_value = {
'message': 'Algo added in local db waiting for validation.'
'The substra network has been notified for adding this Algo'
}
response = self.client.post(url, data, format='multipart', **extra)
r = response.json()
self.assertEqual(r['pkhash'], pkhash)
self.assertEqual(r['validated'], False)
self.assertEqual(r['description'],
f'http://testserver/media/algos/{r["pkhash"]}/{self.data_description_filename}')
self.assertEqual(r['file'],
f'http://testserver/media/algos/{r["pkhash"]}/{self.algo_filename}')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
示例5: _cancel_v6
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def _cancel_v6(self, request, scan_id):
"""Cancels a scan job
:param request: the HTTP POST request
:type request: :class:`rest_framework.request.Request`
:param scan_id: The ID of the Scan process
:type scan_id: int encoded as a str
:returns: The HTTP response to send back to the user
:rtype: :class:`rest_framework.response.Response`
"""
canceled_ids = Scan.objects.cancel_scan(scan_id)
resp_dict = {'id': scan_id, 'canceled_jobs': canceled_ids}
return JsonResponse(resp_dict, status=status.HTTP_202_ACCEPTED)
# return Response(resp_dict, status=status.HTTP_202_ACCEPTED)
# return Response(JSONRenderer().render(canceled_ids), status=status.HTTP_202_ACCEPTED)
示例6: test_cancel_scan_job_nothing_to_cancel
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def test_cancel_scan_job_nothing_to_cancel(self, msg_create, mock_msg_mgr):
"""Tests no cancel messages generated when jobs are not in a cancelable state"""
self.scan.job = job_utils.create_job()
self.scan.job.status = "COMPLETED"
self.scan.job.save()
self.scan.save()
self.ingest = ingest_test_utils.create_ingest(scan=self.scan, file_name='test3.txt',
status='QUEUED')
self.ingest.job.status = "CANCELED"
self.ingest.job.save()
url = '/%s/scans/cancel/%d/' % (self.api, self.scan.id)
response = self.client.generic('POST', url, json.dumps({'ingest': True}), 'application/json')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
result = json.loads(response.content)
self.assertEqual(result['id'], unicode(self.scan.id))
self.assertEqual(len(result['canceled_jobs']), 0)
msg_create.assert_not_called()
mock_msg_mgr.assert_not_called()
示例7: test_cancel_scan_broken_ingest_job
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def test_cancel_scan_broken_ingest_job(self, msg_create, mock_msg_mgr):
"""Tests no cancel messages generated when jobs are not in a cancelable state"""
self.scan.job = job_utils.create_job()
self.scan.save()
self.ingest = ingest_test_utils.create_ingest(scan=self.scan, file_name='test3.txt',
status='QUEUED')
self.ingest.job = None
self.ingest.save()
url = '/%s/scans/cancel/%d/' % (self.api, self.scan.id)
response = self.client.generic('POST', url, json.dumps({'ingest': True}), 'application/json')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
result = json.loads(response.content)
self.assertEqual(result['id'], unicode(self.scan.id))
self.assertEqual(len(result['canceled_jobs']), 1)
msg_create.assert_called()
mock_msg_mgr.assert_called()
示例8: test_all_jobs
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def test_all_jobs(self, mock_mgr):
"""Tests reprocessing all jobs in an existing recipe"""
mock_mgr.return_value = MockCommandMessageManager()
json_data = {
'forced_nodes': {
'all': True
}
}
url = '/%s/recipes/%i/reprocess/' % (self.api, self.recipe1.id)
response = self.client.generic('POST', url, json.dumps(json_data), 'application/json')
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED, response.content)
new_recipe = Recipe.objects.get(superseded_recipe_id=self.recipe1.id)
self.assertEqual(new_recipe.configuration['output_workspaces']['default'], self.workspace.name)
示例9: queue_bake_jobs
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def queue_bake_jobs(self, request):
"""Creates and queues the specified number of Scale Bake jobs
:param request: the HTTP POST request
:type request: :class:`rest_framework.request.Request`
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
"""
num = rest_util.parse_int(request, 'num')
if num < 1:
raise BadParameter('num must be at least 1')
# TODO: in the future, send command message to do this asynchronously
try:
recipe_type = RecipeType.objects.get(name='scale-bake', revision_num='1')
for _ in xrange(num):
Queue.objects.queue_new_recipe_for_user_v6(recipe_type, Data())
except (InvalidData, InvalidRecipeData, InactiveRecipeType) as ex:
message = 'Unable to create new recipe'
logger.exception(message)
raise BadParameter('%s: %s' % (message, unicode(ex)))
return Response(status=status.HTTP_202_ACCEPTED)
示例10: queue_casino_recipes
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def queue_casino_recipes(self, request):
"""Creates and queues the specified number of Scale Casino recipes
:param request: the HTTP POST request
:type request: :class:`rest_framework.request.Request`
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
"""
num = rest_util.parse_int(request, 'num')
if num < 1:
raise BadParameter('num must be at least 1')
# TODO: in the future, send command message to do this asynchronously
try:
recipe_type = RecipeType.objects.get(name='scale-casino', revision_num='1')
for _ in xrange(num):
Queue.objects.queue_new_recipe_for_user_v6(recipe_type, Data())
except (InvalidData, InvalidRecipeData, InactiveRecipeType) as ex:
message = 'Unable to create new recipe'
logger.exception(message)
raise BadParameter('%s: %s' % (message, unicode(ex)))
return Response(status=status.HTTP_202_ACCEPTED)
示例11: queue_hello_jobs
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def queue_hello_jobs(self, request):
"""Creates and queues the specified number of Scale Hello jobs
:param request: the HTTP POST request
:type request: :class:`rest_framework.request.Request`
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
"""
num = rest_util.parse_int(request, 'num')
if num < 1:
raise BadParameter('num must be at least 1')
# TODO: in the future, send command message to do this asynchronously
try:
recipe_type = RecipeType.objects.get(name='scale-hello', revision_num='1')
for _ in xrange(num):
Queue.objects.queue_new_recipe_for_user_v6(recipe_type, Data())
except (InvalidData, InvalidRecipeData, InactiveRecipeType) as ex:
message = 'Unable to create new recipe'
logger.exception(message)
raise BadParameter('%s: %s' % (message, unicode(ex)))
return Response(status=status.HTTP_202_ACCEPTED)
示例12: queue_count_jobs
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def queue_count_jobs(self, request):
"""Creates and queues the specified number of Scale Count jobs
:param request: the HTTP POST request
:type request: :class:`rest_framework.request.Request`
:rtype: :class:`rest_framework.response.Response`
:returns: the HTTP response to send back to the user
"""
num = rest_util.parse_int(request, 'num')
if num < 1:
raise BadParameter('num must be at least 1')
# TODO: in the future, send command message to do this asynchronously
try:
recipe_type = RecipeType.objects.get(name='scale-count', revision_num='1')
for _ in xrange(num):
Queue.objects.queue_new_recipe_for_user_v6(recipe_type, Data())
except (InvalidData, InvalidRecipeData, InactiveRecipeType) as ex:
message = 'Unable to create new recipe'
logger.exception(message)
raise BadParameter('%s: %s' % (message, unicode(ex)))
return Response(status=status.HTTP_202_ACCEPTED)
示例13: send
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def send(self, request, *args, **kwargs):
instance = self.get_object()
if instance.sent:
raise exceptions.ValidationError("message already sent")
instance.send()
track(
request.user,
"announcement.send",
properties={"announcement_id": instance.id},
)
return Response(
{"status": "message queued for sending"}, status=status.HTTP_202_ACCEPTED
)
示例14: create
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
email = serializer.validated_data["email"]
try:
user = User.objects.get(email__iexact=email)
except User.DoesNotExist:
raise ValidationError({"email": "User with that email does not exist"})
token = PasswordReset.generate_reset_token(email)
send_email.delay(
to_email=email,
context={"name": user.full_name, "token": token},
subject="Nullstill ditt passord på abakus.no",
plain_template="users/email/reset_password.txt",
html_template="users/email/reset_password.html",
from_email=None,
)
return Response(status=status.HTTP_202_ACCEPTED)
示例15: create
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_202_ACCEPTED [as 别名]
def create(self, request, *args, **kwargs):
"""
Attempts to create a registration token and email it to the user.
"""
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
email = serializer.validated_data.get("email")
token = Registrations.generate_registration_token(email)
send_email.delay(
to_email=email,
context={"token": token},
subject="Velkommen til Abakus.no",
plain_template="users/email/registration.txt",
html_template="users/email/registration.html",
from_email=None,
)
return Response(status=status.HTTP_202_ACCEPTED)