本文整理汇总了Python中rest_framework.status方法的典型用法代码示例。如果您正苦于以下问题:Python rest_framework.status方法的具体用法?Python rest_framework.status怎么用?Python rest_framework.status使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework
的用法示例。
在下文中一共展示了rest_framework.status方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def get(self, request):
if request.user.is_authenticated:
# 获取所有数据
roles = Product.objects.all()
# 创建分页对象
pg = PageNumberPagination()
# pg = MyLimitOffsetPagination()
# 获取分页的数据
page_roles = pg.paginate_queryset(queryset=roles, request=request, view=self)
# 对数据进行序列化
ser = ProductSerializer(instance=page_roles, many=True)
# print('ser.data的类型:' + str(ser.data))
msg = sort_out_list(request, ser.data)
return Response(msg, status=HTTP_200_OK)
else:
msg = {
'stateCode': 201,
'msg': '没有访问权限'
}
return Response(msg, 201)
# 获取搜索列表,暂时不分页
示例2: post
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def post(self, request):
'''
Add new tags (array of tag names) to user's profile
'''
if not request.data["tags"]:
return Response({"error": "tags were not included"}, status=400)
user = EngageUserProfile.objects.get(user=request.user)
for tag in request.data["tags"]:
try:
tag_to_add = Tag.objects.filter(name__contains=tag).first()
if tag_to_add is not None:
user.tags.add(tag_to_add)
except:
username = request.user.username
print(
"Could not add tag ({}) to user ({}) since it doesn't exist in the ingest_tag table.".format(tag, username))
try:
user.save()
except:
return Response(status=500)
return Response(status=200)
示例3: limited
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def limited(user=None):
illegality = Illegality.objects.filter(user=user,duration_status=True).order_by("-illegality_endtime")
if len(illegality) != 0 and illegality[0].duration_status:
illegality = illegality[0]
start_time = illegality.illegality_starttime
end_time = illegality.illegality_endtime
now = datetime.datetime.now()
if now >= start_time and now <= end_time:
raise serializers.ValidationError({"405": {"notice": "攻击比赛平台", "type": illegality.illegality_action,
"start_time": illegality.illegality_starttime,
"endtime": illegality.illegality_endtime,
'status': illegality.duration_status}})
elif now > end_time:
illegality.duration_status = False
illegality.save()
else:
pass
else:
pass
示例4: dependencies
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def dependencies(self, request, uuid=None):
from api.serializers import URLRunSerializer, URLTemplateSerializer
context = {'request': request}
try:
dependencies = models.DataObject.get_dependencies(uuid)
serialized_dependencies = {
'runs': [URLRunSerializer(
run, context=context).data
for run in dependencies.get('runs', [])],
'templates': [URLTemplateSerializer(
template, context=context).data
for template in dependencies.get(
'templates', [])],
'truncated': dependencies.get('truncated')
}
except ObjectDoesNotExist:
raise rest_framework.exceptions.NotFound()
return JsonResponse(serialized_dependencies, status=200)
示例5: get_task_monitor_settings
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def get_task_monitor_settings(self, request, uuid=None):
task_attempt = self._get_task_attempt(request, uuid)
return JsonResponse({
'SERVER_NAME': get_setting('SERVER_NAME'),
'DEBUG': get_setting('DEBUG'),
'WORKING_DIR_ROOT': os.path.join(
get_setting('INTERNAL_STORAGE_ROOT'), 'tmp', task_attempt.uuid),
'DEFAULT_DOCKER_REGISTRY': get_setting('DEFAULT_DOCKER_REGISTRY'),
'PRESERVE_ALL': get_setting('PRESERVE_ON_FAILURE'),
'PRESERVE_ON_FAILURE': get_setting('PRESERVE_ON_FAILURE'),
'HEARTBEAT_INTERVAL_SECONDS':
get_setting('TASKRUNNER_HEARTBEAT_INTERVAL_SECONDS'),
# container name is duplicated in TaskAttempt cleanup playbook
'PROCESS_CONTAINER_NAME': '%s-attempt-%s' % (
get_setting('SERVER_NAME'), uuid),
}, status=200)
示例6: post
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def post(self, request):
data = request.data
# username = data.get('username')
serializer = ProductSerializer(data=data)
if request.user.is_authenticated:
# print(data)
if serializer.is_valid(raise_exception=True):
serializer.save()
return Response({"stateCode": 200, "msg": "发布成功"}, 200)
return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)
else:
return Response({"stateCode": 201, "msg": "没有上传权限"}, 201)
示例7: staffdesignations
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def staffdesignations(request):
return HttpResponse(json.dumps(STAFF_TYPES), status=200)
示例8: staffgender
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def staffgender(request):
return HttpResponse(json.dumps(GENDER_TYPES), status=200)
示例9: get_agenda
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def get_agenda(request, meeting_id):
'''
Returns specified JSON serialized agenda if it exists
'''
agenda = Agenda.objects.get(meeting_id=meeting_id)
if agenda is None:
return Response(data={"error": "No agenda item with id:" + str(meeting_id)}, status=404)
data = AgendaSerializer(agenda, many=False).data
return Response(data=data, status=200)
示例10: mailchimpUpdRequest
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def mailchimpUpdRequest(payload=None, user=None, key=None, member_id=None):
"""
HTTP Method: PATCH
MailChimp API request used to update the status of existing users.
"""
user = user
key = key
url = f'https://{REGION}.api.mailchimp.com/3.0/lists/6ca892a88b/members/{member_id}'
r = requests.patch(url, auth=(user, key), data=payload)
return r
示例11: get
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def get(self, request):
user = EngageUserProfile.objects.get(user=request.user)
tags = user.tags.all()
tags_list = []
for tag in tags:
tags_list.append(tag.name)
return Response(data=tags_list, status=200)
示例12: wechat_notify_url
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def wechat_notify_url(request):
'''
微信支付回调接口
'''
try:
print('请求方法:',request.method)
return_xml = """<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"""
webData = request.body
print('回调返回信息:',webData)
if bool(webData):
xmlData = ET.fromstring(webData)
if xmlData.find('return_code').text != 'SUCCESS':
print('回调出现错误')
return HttpResponse(return_xml,content_type='application/xml;charset=utf-8')
else:
if xmlData.find('result_code').text != 'SUCCESS':
print('支付失败!')
return HttpResponse(return_xml,content_type='application/xml;charset=utf-8')
else:
print('订单支付成功...准备修改订单状态')
order_num = xmlData.find('out_trade_no').text
order = Order.objects.filter(order_num=order_num).first()
# 更新状态 更新支付时间 更新支付方式
order.status = 1
order.pay_time = datetime.datetime.now()
order.pay_type = 1
order.save()
# 整理库存和销量,当订单到这里时会将库存锁死
for detail in order.order_details.all():
detail.good_grade.sales += detail.buy_num
detail.good_grade.stock -= detail.buy_num
detail.good_grade.save()
return HttpResponse(return_xml,content_type='application/xml;charset=utf-8')
return HttpResponse(return_xml,content_type='application/xml;charset=utf-8')
except Exception as e:
print(e)
print({"message": "网络错误:%s"%str(e), "errorCode": 1, "data": {}})
return_xml = """<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"""
return HttpResponse(return_xml,content_type='application/xml;charset=utf-8')
示例13: post
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def post(self, request):
"""
处理支付宝的notify_url
:param request:
:return:
"""
try:
processed_dict = {}
for key, value in request.data.items():
processed_dict[key] = value
if processed_dict:
print('支付宝的参数', processed_dict)
sign = processed_dict.pop("sign", None)
alipay = AliPay(method='alipay.trade.app.pay')
verify_re = alipay.verify(processed_dict, sign)
print('支付宝的参数', processed_dict)
print('检验参数结果', verify_re)
out_trade_no = processed_dict.get('out_trade_no', None)
trade_no = processed_dict.get('trade_no', None)
# response = VerifyAndDo(out_trade_no, pay_way='alipay')
order = Order.objects.filter(order_num=out_trade_no, status=0).first()
if order:
order.status = 1
order.wechat_order_num = trade_no
order.pay_time = datetime.datetime.now()
order.pay_type = 2
order.save()
# 整理库存和销量,当订单到这里时会将库存锁死
for detail in order.order_details.all():
detail.good_grade.sales += detail.buy_num
detail.good_grade.stock -= detail.buy_num
detail.good_grade.save()
else:
print('未找到订单编号为:的订单...' % order_num)
return Response('success')
except Exception as e:
print('发生错误:',e)
return Response({"message": "出现了无法预料的view视图错误:%s" % e, "errorCode": 1, "data": {}})
示例14: test_get_crawl_by_status
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def test_get_crawl_by_status(self):
response = self.client.get(self.url + "?status=%s" % self.test_nutch_crawl.status)
assert self.parse_response(response)["status"] == "NOT STARTED"
示例15: destroy
# 需要导入模块: import rest_framework [as 别名]
# 或者: from rest_framework import status [as 别名]
def destroy(self, *args, **kwargs):
if get_setting('DISABLE_DELETE'):
return JsonResponse({
'message': 'Delete is forbidden because DISABLE_DELETE is True.'},
status=403)
else:
try:
return super(ProtectedDeleteModelViewSet, self).destroy(
*args, **kwargs)
except ProtectedError:
return JsonResponse({
'message':
'Delete failed because resource is still in use.'},
status=409)