本文整理汇总了Python中rest_framework.views.Response方法的典型用法代码示例。如果您正苦于以下问题:Python views.Response方法的具体用法?Python views.Response怎么用?Python views.Response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.views
的用法示例。
在下文中一共展示了views.Response方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_paginated_response
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def get_paginated_response(self, data):
next = None
previous = None
if self.page.has_next():
next = self.page.next_page_number()
if self.page.has_previous():
previous = self.page.previous_page_number()
return Response({
'results': data,
'meta': {
'pagination': OrderedDict([
('page', self.page.number),
('pages', self.page.paginator.num_pages),
('count', self.page.paginator.count),
])
},
'links': OrderedDict([
('first', self.build_link(1)),
('last', self.build_link(self.page.paginator.num_pages)),
('next', self.build_link(next)),
('prev', self.build_link(previous))
])
})
示例2: get
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def get(self, request, *args, **kwargs):
connect = redis.StrictRedis(
host=settings.REDIS_HOST,
port=settings.REDIS_PORT,
db=settings.REDIS_SPACE,
password=settings.REDIS_PASSWD
)
week_list = ['Won', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun']
TEMP = connect.hgetall('WORK',)
WORK = []
for key in week_list:
WORK.append({
'time': str(key, encoding='utf-8'),
'执行次数': TEMP[key]
})
return Response(
{'title': '一周内工单执行','dataset': WORK} or {}, status.HTTP_200_OK
)
示例3: delete
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def delete(self, request, *args, **kwargs):
if self.qrcode_check(request):
group = self.get_object()
if group.hosts.count() != 0:
return self.msg.format(
USER=request.user.full_name,
NAME=group.name,
UUID=group.uuid
), Response({
'detail': settings.LANGUAGE.ManagerGroupDeleteAPIExsistHost
}, status=status.HTTP_406_NOT_ACCEPTABLE)
else:
return self.msg.format(
USER=request.user.full_name,
NAME=group.name,
UUID=group.uuid
), super(ManagerGroupDeleteAPI, self).delete(request, *args, **kwargs)
else:
return '', self.qrcode_response
示例4: get
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def get(self, request, *args, **kwargs):
user = request.user
if user.have_qrcode is False:
response_dist = {
'url': get_qrcode(request.user)
}
user.have_qrcode = True
user.save()
response = Response(response_dist, status=status.HTTP_201_CREATED)
return self.msg.format(
USER=request.user.full_name,
), response
else:
return '', Response({
'detail': settings.LANGUAGE.UserQRCodeAPIHaveQRCode
}, status=status.HTTP_406_NOT_ACCEPTABLE)
示例5: delete
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def delete(self, request, *args, **kwargs):
if self.qrcode_check(request):
key = self.get_object()
try:
group = key.group
return '', Response({
'detail': settings.LANGUAGE.KeyDeleteAPICanNotDelete.format(
GROUP=group.name
)}, status=status.HTTP_406_NOT_ACCEPTABLE)
except ObjectDoesNotExist:
response = super(KeyDeleteAPI, self).delete(request, *args, **kwargs)
return self.msg.format(
USER=request.user.full_name,
NAME=key.name,
UUID=key.uuid
), response
else:
return '', self.qrcode_response
示例6: update
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def update(self, request, *args, **kwargs):
work = self.get_object()
user = request.user
if self.qrcode_check(request):
pass
else:
return '', self.qrcode_response
codework = models.Code_Work.objects.filter(uuid=kwargs['pk']).get()
if codework.mission.group.users.filter(id=user.id).exists():
response = super(CodeWorkCheckAPI,self).update(request, *args, **kwargs)
return self.msg.format(
USER=request.user.full_name,
MISSION=work.mission.info,
REASON=work.info,
UUID=work.uuid,
), response
else:
return '', Response({'detail': u'您没有审核的权限'}, status=status.HTTP_406_NOT_ACCEPTABLE)
示例7: acl_save_draft
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def acl_save_draft(request, id_vlan, type_acl):
type_to_check = type_acl.strip().lower()
content_draft = request.DATA.get('content_draft', '')
if not is_valid_int_greater_zero_param(id_vlan):
raise exceptions.InvalidIdVlanException()
vlan_obj = Vlan.objects.get(pk=id_vlan)
if type_to_check == TYPE_ACL_V4:
vlan_obj.acl_draft = content_draft
else:
vlan_obj.acl_draft_v6 = content_draft
vlan_obj.save(request.user)
return Response()
示例8: acl_remove_draft
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def acl_remove_draft(request, id_vlan, type_acl):
type_to_check = type_acl.strip().lower()
if not is_valid_int_greater_zero_param(id_vlan):
raise exceptions.InvalidIdVlanException()
vlan_obj = Vlan.objects.get(pk=id_vlan)
if type_to_check == TYPE_ACL_V4:
vlan_obj.acl_draft = None
else:
vlan_obj.acl_draft_v6 = None
vlan_obj.save(request.user)
return Response()
示例9: create
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def create(self, request, *args, **kwargs):
try:
return super().create(request, *args, **kwargs)
except FileExistsError:
return Response(
{"xpi": "An extension with this filename already exists."},
status=status.HTTP_400_BAD_REQUEST,
)
示例10: update
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def update(self, request, *args, **kwargs):
try:
return super().update(request, *args, **kwargs)
except FileExistsError:
return Response(
{"xpi": "An extension with this filename already exists."},
status=status.HTTP_400_BAD_REQUEST,
)
示例11: destroy
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def destroy(self, request, *args, **kwargs):
instance = self.get_object()
revisions = RecipeRevision.objects.filter(action__name="opt-out-study").exclude(
latest_for_recipe=None, approved_for_recipe=None
)
for r in revisions:
if r.arguments.get("extensionId") == instance.id:
return Response(
["Extension cannot be updated while in use by a recipe."],
status=status.HTTP_400_BAD_REQUEST,
)
return super().destroy(request, *args, **kwargs)
示例12: delete
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def delete(self, request, *args, **kwargs):
obj = self.get_object()
if not obj.pushmission.exists():
response = super(UtilsFileDeleteAPI, self).delete(request, *args, **kwargs)
return self.msg.format(
USER=request.user.full_name,
UUID=obj.uuid,
FILENAME=obj.name,
), response
else:
return '', Response({'detail': '该文件已经属于某个任务无法被删除'}, status=status.HTTP_406_NOT_ACCEPTABLE)
示例13: create
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def create(self, request, *args, **kwargs):
data = request.data
if models.Instance.objects.filter(port=data['detail']['port'],host_id=data['host']).exists():
return Response({'detail': '该主机上已经存在该实例信息'}, status=status.HTTP_406_NOT_ACCEPTABLE)
else:
return super(ZDBInstanceCreateAPI,self).create(request, *args, **kwargs)
示例14: get
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def get(self, request, *args, **kwargs):
obj = self.get_object()
obj.check_status()
return Response({
'detail': settings.LANGUAGE.JumperStatusAPI
}, status=status.HTTP_200_OK)
示例15: get
# 需要导入模块: from rest_framework import views [as 别名]
# 或者: from rest_framework.views import Response [as 别名]
def get(self, request, *args, **kwargs):
obj = self.get_object()
if obj.status > 0:
return Response({'detail': u'该工单处于正常状态'}, status=status.HTTP_406_NOT_ACCEPTABLE)
else:
return Response({'results': obj.push_mission.results}, status=status.HTTP_202_ACCEPTED)