本文整理汇总了Python中rest_framework.status.HTTP_409_CONFLICT属性的典型用法代码示例。如果您正苦于以下问题:Python status.HTTP_409_CONFLICT属性的具体用法?Python status.HTTP_409_CONFLICT怎么用?Python status.HTTP_409_CONFLICT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类rest_framework.status
的用法示例。
在下文中一共展示了status.HTTP_409_CONFLICT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: enable
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def enable(self, request, pk=None):
recipe = self.get_object()
if recipe.approved_revision:
try:
recipe.approved_revision.enable(user=request.user)
except EnabledState.NotActionable as e:
return Response({"error": str(e)}, status=status.HTTP_409_CONFLICT)
else:
return Response(
{"error": "Cannot enable a recipe that is not approved."},
status=status.HTTP_409_CONFLICT,
)
recipe.latest_revision.refresh_from_db()
return Response(RecipeSerializer(recipe).data)
示例2: _create
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def _create(self, request, file):
try:
pkhash = get_hash(file)
except Exception as e:
st = status.HTTP_400_BAD_REQUEST
raise ValidationException(e.args, '(not computed)', st)
serializer = self.get_serializer(data={
'pkhash': pkhash,
'file': file,
'description': request.data.get('description')
})
try:
serializer.is_valid(raise_exception=True)
except Exception as e:
st = status.HTTP_400_BAD_REQUEST
if find_primary_key_error(e):
st = status.HTTP_409_CONFLICT
raise ValidationException(e.args, pkhash, st)
else:
# create on ledger + db
return self.commit(serializer, request)
示例3: _create
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def _create(self, request, data_opener):
try:
pkhash = get_hash(data_opener)
except Exception as e:
st = status.HTTP_400_BAD_REQUEST
raise ValidationException(e.args, '(not computed)', st)
serializer = self.get_serializer(data={
'pkhash': pkhash,
'data_opener': data_opener,
'description': request.data.get('description'),
'name': request.data.get('name'),
})
try:
serializer.is_valid(raise_exception=True)
except Exception as e:
st = status.HTTP_400_BAD_REQUEST
if find_primary_key_error(e):
st = status.HTTP_409_CONFLICT
raise ValidationException(e.args, pkhash, st)
else:
# create on ledger + db
return self.commit(serializer, request)
示例4: _create
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def _create(self, request, file):
pkhash = get_hash(file)
serializer = self.get_serializer(data={
'pkhash': pkhash,
'file': file,
'description': request.data.get('description')
})
try:
serializer.is_valid(raise_exception=True)
except Exception as e:
st = status.HTTP_400_BAD_REQUEST
if find_primary_key_error(e):
st = status.HTTP_409_CONFLICT
raise ValidationException(e.args, pkhash, st)
else:
# create on ledger + db
return self.commit(serializer, request)
示例5: test_terminate_while_saving
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def test_terminate_while_saving(self):
# Create upload
upload = UploadFactory(
filename='test_data.txt', upload_metadata=json.dumps({'filename': 'test_data.txt'}), upload_length=100,
state=states.SAVING)
# Prepare headers
headers = {
'Tus-Resumable': tus_api_version,
}
# Perform request
result = self.client.delete(
reverse('rest_framework_tus:api:upload-detail', kwargs={'guid': upload.guid}), headers=headers)
# Check result
assert result.status_code == status.HTTP_409_CONFLICT
# Verify existence
assert get_upload_model().objects.filter(guid=upload.guid).exists()
示例6: test_create_channel_duplicate
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def test_create_channel_duplicate(mocker, patched_users_api):
"""creating a duplicate channel should return an error"""
client = APIClient()
role = RoleFactory.create(role=Staff.ROLE_ID)
role.user.is_superuser = True
role.user.save()
client.force_login(role.user)
channel = ChannelFactory.create()
mocker.patch(
'discussions.serializers.add_channel',
side_effect=ChannelAlreadyExistsException,
autospec=True,
)
create_channel_input = _make_create_channel_input(role.program.id, 'description')
resp = client.post(reverse('channel-list'), data={
**create_channel_input,
"name": channel.name,
}, format="json")
assert resp.status_code == statuses.HTTP_409_CONFLICT
assert resp.json() == {"name": "A channel with that name already exists"}
示例7: post
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def post(self, request, *args, **kwargs):
"""Create a new channel"""
serializer = ChannelSerializer(data=request.data, context={'request': request})
serializer.is_valid(raise_exception=True)
try:
serializer.save()
except ChannelAlreadyExistsException:
return Response(
{"name": "A channel with that name already exists"},
status=status.HTTP_409_CONFLICT,
)
return Response(
serializer.data,
status=status.HTTP_201_CREATED,
)
示例8: create
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def create(self, request, *args, **kwargs):
errors = []
validation_failures = []
schema_errors, validation_errors = validate_sw_json(request.data, request.user.summoner)
if schema_errors:
errors.append(schema_errors)
if validation_errors:
validation_failures = "Uploaded data does not match previously imported data. To override, set import preferences to ignore validation errors and import again."
import_options = request.user.summoner.preferences.get('import_options', self.default_import_options)
if not errors and (not validation_failures or import_options['ignore_validation_errors']):
# Queue the import
task = com2us_data_import.delay(request.data, request.user.summoner.pk, import_options)
return Response({'job_id': task.task_id})
elif validation_failures:
return Response({'validation_error': validation_failures}, status=status.HTTP_409_CONFLICT)
else:
return Response({'error': errors}, status=status.HTTP_400_BAD_REQUEST)
示例9: disable
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def disable(self, request, pk=None):
recipe = self.get_object()
try:
recipe.approved_revision.disable(user=request.user)
except EnabledState.NotActionable as e:
return Response({"error": str(e)}, status=status.HTTP_409_CONFLICT)
recipe.latest_revision.refresh_from_db()
return Response(RecipeSerializer(recipe).data)
示例10: create
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def create(self, request, *args, **kwargs):
"""Create a resource."""
self.define_contributor(request)
try:
return super().create(request, *args, **kwargs)
except IntegrityError as ex:
return Response({"error": str(ex)}, status=status.HTTP_409_CONFLICT)
示例11: assertDeleteAccountFailureStillHasDomainsResponse
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def assertDeleteAccountFailureStillHasDomainsResponse(self, response):
return self.assertContains(
response=response,
text="To delete your user account, first delete all of your domains.",
status_code=status.HTTP_409_CONFLICT
)
示例12: test_identification_by_token
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def test_identification_by_token(self):
"""
Test if the conflict of having multiple domains, but not specifying which to update is correctly recognized.
"""
self.client.set_credentials_basic_auth('', self.token.plain)
response = self.client.get(self.reverse('v1:dyndns12update'), REMOTE_ADDR='10.5.5.7')
self.assertStatus(response, status.HTTP_409_CONFLICT)
示例13: _create
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def _create(self, request):
metrics = request.data.get('metrics')
description = request.data.get('description')
try:
pkhash = get_hash(description)
except Exception as e:
st = status.HTTP_400_BAD_REQUEST
raise ValidationException(e.args, '(not computed)', st)
serializer = self.get_serializer(data={
'pkhash': pkhash,
'metrics': metrics,
'description': description,
})
try:
serializer.is_valid(raise_exception=True)
except Exception as e:
st = status.HTTP_400_BAD_REQUEST
if find_primary_key_error(e):
st = status.HTTP_409_CONFLICT
raise ValidationException(e.args, pkhash, st)
else:
# create on ledger + db
return self.commit(serializer, request)
示例14: _create
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def _create(self, request, data_manager_keys, test_only):
# compute_data will uncompress data archives to paths which will be
# hardlinked thanks to datasample pre_save signal.
# In all other cases, we need to remove those references.
if not data_manager_keys:
raise Exception("missing or empty field 'data_manager_keys'")
self.check_datamanagers(data_manager_keys) # can raise
paths_to_remove = []
try:
# will uncompress data archives to paths
computed_data = self.compute_data(request, paths_to_remove)
serializer = self.get_serializer(data=computed_data, many=True)
try:
serializer.is_valid(raise_exception=True)
except Exception as e:
pkhashes = [x['pkhash'] for x in computed_data]
st = status.HTTP_400_BAD_REQUEST
if find_primary_key_error(e):
st = status.HTTP_409_CONFLICT
raise ValidationException(e.args, pkhashes, st)
else:
# create on ledger + db
ledger_data = {'test_only': test_only,
'data_manager_keys': data_manager_keys}
data, st = self.commit(serializer, ledger_data) # pre_save signal executed
return data, st
finally:
for gpath in paths_to_remove:
shutil.rmtree(gpath, ignore_errors=True)
示例15: test_add_objective_conflict
# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_409_CONFLICT [as 别名]
def test_add_objective_conflict(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 = {'pkhash': pkhash}
response = self.client.post(url, data, format='multipart', **extra)
r = response.json()
self.assertEqual(r['pkhash'], pkhash)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
# XXX reload data as the previous call to post change it
_, data = self.get_default_objective_data()
response = self.client.post(url, data, format='multipart', **extra)
r = response.json()
self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
self.assertEqual(r['pkhash'], pkhash)