Python rest_framework.views.Response() Examples
The following are 30
code examples of rest_framework.views.Response().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rest_framework.views
, or try the search function
.
Example #1
Source File: dashboard.py From DevOps with GNU General Public License v2.0 | 7 votes |
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 )
Example #2
Source File: pagination.py From django-rest-framework-json-api with BSD 2-Clause "Simplified" License | 6 votes |
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)) ]) })
Example #3
Source File: pagination.py From django-rest-framework-json-api with BSD 2-Clause "Simplified" License | 6 votes |
def get_paginated_response(self, data): return Response({ 'results': data, 'meta': { 'pagination': OrderedDict([ ('count', self.count), ('limit', self.limit), ('offset', self.offset), ]) }, 'links': OrderedDict([ ('first', self.get_first_link()), ('last', self.get_last_link()), ('next', self.get_next_link()), ('prev', self.get_previous_link()) ]) })
Example #4
Source File: code.py From DevOps with GNU General Public License v2.0 | 6 votes |
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.user.id == user.id: response = super(CodeWorkUploadFileAPI,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)
Example #5
Source File: dashboard.py From DevOps with GNU General Public License v2.0 | 6 votes |
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 ) TEMP = connect.hgetall('GROUP',) GROUP = [ ['主机数目','count'], ] for key in TEMP: GROUP.append([str(key, encoding='utf-8'), int(TEMP[key])]) return Response( {'title': '主机统计', 'dataset': GROUP} or {}, status.HTTP_200_OK )
Example #6
Source File: group.py From DevOps with GNU General Public License v2.0 | 6 votes |
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
Example #7
Source File: code.py From DevOps with GNU General Public License v2.0 | 6 votes |
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.user.id == user.id: response = super(CodeWorkRunAPI,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)
Example #8
Source File: code.py From DevOps with GNU General Public License v2.0 | 6 votes |
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)
Example #9
Source File: v1.py From GloboNetworkAPI with Apache License 2.0 | 6 votes |
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()
Example #10
Source File: user.py From DevOps with GNU General Public License v2.0 | 6 votes |
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)
Example #11
Source File: v1.py From GloboNetworkAPI with Apache License 2.0 | 6 votes |
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()
Example #12
Source File: key.py From DevOps with GNU General Public License v2.0 | 6 votes |
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
Example #13
Source File: api.py From diting with GNU General Public License v2.0 | 5 votes |
def post(self, request): serializer = self.serializer_class(data=request.data) if serializer.is_valid(): host = serializer.validated_data["AUTH_LDAP_SERVER_URI"] bind_dn = serializer.validated_data["AUTH_LDAP_BIND_DN"] password = serializer.validated_data["AUTH_LDAP_BIND_PASSWORD"] use_ssl = serializer.validated_data.get("AUTH_LDAP_START_TLS", False) search_ou = serializer.validated_data["AUTH_LDAP_SEARCH_OU"] search_filter = serializer.validated_data["AUTH_LDAP_SEARCH_FILTER"] attr_map = serializer.validated_data["AUTH_LDAP_USER_ATTR_MAP"] try: attr_map = json.loads(attr_map) except json.JSONDecodeError: return Response({"error": "AUTH_LDAP_USER_ATTR_MAP not valid"}, status=401) server = Server(host, use_ssl=use_ssl) conn = Connection(server, bind_dn, password) try: conn.bind() except Exception as e: return Response({"error": str(e)}, status=401) ok = conn.search(search_ou, search_filter % ({"user": "*"}), attributes=list(attr_map.values())) if not ok: return Response({"error": "Search no entry matched"}, status=401) users = [] for entry in conn.entries: user = {} for attr, mapping in attr_map.items(): if hasattr(entry, mapping): user[attr] = getattr(entry, mapping) users.append(user) if len(users) > 0: return Response({"msg": _("Match {} s users").format(len(users))}) else: return Response({"error": "Have user but attr mapping error"}, status=401) else: return Response({"error": str(serializer.errors)}, status=401)
Example #14
Source File: monitor.py From DevOps with GNU General Public License v2.0 | 5 votes |
def get(self, request, *args, **kwargs): from deveops.tools.aliyun_v2.request.cms.ecs import AliyunCMSECSTool API = AliyunCMSECSTool() return Response({ 'title': settings.LANGUAGE.MonitorHostAliyunDetailIReadIOPS, 'dataset': API.tool_get_metric_read_iops(self.get_object().aliyun_id, int(kwargs['time'])).__next__() })
Example #15
Source File: monitor.py From DevOps with GNU General Public License v2.0 | 5 votes |
def get(self, request, *args, **kwargs): from deveops.tools.aliyun_v2.request.cms.ecs import AliyunCMSECSTool API = AliyunCMSECSTool() return Response({ 'title': settings.LANGUAGE.MonitorHostAliyunDetailInternetInRate, 'dataset': API.tool_get_metric_net_in(self.get_object().aliyun_id, int(kwargs['time'])).__next__() })
Example #16
Source File: monitor.py From DevOps with GNU General Public License v2.0 | 5 votes |
def get(self, request, *args, **kwargs): from deveops.tools.aliyun_v2.request.cms.ecs import AliyunCMSECSTool API = AliyunCMSECSTool() return Response({ 'title': settings.LANGUAGE.MonitorHostAliyunDetailDiskUse, 'dataset': API.tool_get_metric_disk_use( self.get_object().aliyun_id, int(kwargs['time'])).__next__() })
Example #17
Source File: views.py From eoj3 with MIT License | 5 votes |
def post(self, request, pk): try: request.user.notifications.get(pk=pk).mark_as_read() return Response(status=status.HTTP_200_OK) except: return Response(status=status.HTTP_400_BAD_REQUEST)
Example #18
Source File: api.py From diting with GNU General Public License v2.0 | 5 votes |
def get(self, request): if not settings.DEBUG: return Response('Only debug mode support') configs = {} for i in dir(settings): if i.isupper(): configs[i] = str(getattr(settings, i)) return Response(configs)
Example #19
Source File: api.py From diting with GNU General Public License v2.0 | 5 votes |
def get(request): user_id = request.query_params.get('user_id', '') asset_id = request.query_params.get('asset_id', '') system_id = request.query_params.get('system_user_id', '') user = get_object_or_404(User, id=user_id) asset = get_object_or_404(Asset, id=asset_id) system_user = get_object_or_404(SystemUser, id=system_id) assets_granted = NodePermissionUtil.get_user_assets(user) if system_user in assets_granted.get(asset, []): return Response({'msg': True}, status=200) else: return Response({'msg': False}, status=403)
Example #20
Source File: views.py From eoj3 with MIT License | 5 votes |
def post(self, request): request.user.notifications.mark_all_as_read() return Response(status=status.HTTP_200_OK)
Example #21
Source File: views.py From normandy with Mozilla Public License 2.0 | 5 votes |
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, )
Example #22
Source File: monitor.py From DevOps with GNU General Public License v2.0 | 5 votes |
def get(self, request, *args, **kwargs): from deveops.tools.aliyun_v2.request.cms.ecs import AliyunCMSECSTool API = AliyunCMSECSTool() return Response({ 'title': settings.LANGUAGE.MonitorHostAliyunDetailMemoryAPI, 'dataset': API.tool_get_metric_mem(self.get_object().aliyun_id, int(kwargs['time'])).__next__() })
Example #23
Source File: code.py From DevOps with GNU General Public License v2.0 | 5 votes |
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)
Example #24
Source File: jumper.py From DevOps with GNU General Public License v2.0 | 5 votes |
def get(self, request, *args, **kwargs): obj = self.get_object() obj.check_status() return Response({ 'detail': settings.LANGUAGE.JumperStatusAPI }, status=status.HTTP_200_OK)
Example #25
Source File: user.py From DevOps with GNU General Public License v2.0 | 5 votes |
def get(self, request, *args, **kwargs): return Response({ 'isexpire': request.user.is_expire }, status=status.HTTP_200_OK)
Example #26
Source File: user.py From DevOps with GNU General Public License v2.0 | 5 votes |
def get(self, request, *args, **kwargs): info_dist = {} info_dist['username'] = request.user.username info_dist['name'] = request.user.full_name info_dist['info'] = request.user.info if request.user.is_superuser is True: info_dist['isadmin'] = True else: info_dist['isadmin'] = 'None' return Response(info_dist, status=status.HTTP_200_OK)
Example #27
Source File: instance.py From DevOps with GNU General Public License v2.0 | 5 votes |
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)
Example #28
Source File: file.py From DevOps with GNU General Public License v2.0 | 5 votes |
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)
Example #29
Source File: dashboard.py From DevOps with GNU General Public License v2.0 | 5 votes |
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 ) TEMP = connect.hgetall('COUNT',) COUNT = {} for key in TEMP: COUNT[str(key, encoding='utf-8')] = TEMP[key] return Response( COUNT or {}, status.HTTP_200_OK )
Example #30
Source File: views.py From normandy with Mozilla Public License 2.0 | 5 votes |
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)