def list(self, request, *args, **kwargs): queryset = self.filter_queryset(self.get_queryset()) serializer = self.get_serializer(queryset, many=True) new_token = custom_refresh_token(request.auth) return Response(serializer.data, status=status.HTTP_200_OK, headers={'NewToken': new_token})
def retrieve(self, request, *args, **kwargs): instance = self.get_object() serializer = self.get_serializer(instance) result = serializer.data.copy() new_token = custom_refresh_token(request.auth) result["token"] = new_token return Response(result)
def retrieve(self, request, *args, **kwargs): instance = self.get_object() serializer = self.get_serializer(instance) new_token = custom_refresh_token(request.auth) return Response(serializer.data, status=status.HTTP_200_OK, headers={'NewToken': new_token})
def hello_world(request,name): if request.method == 'POST': return Response({"message": "Got some data!", "data": request.data}) elif request.method == 'GET': jwtToken = name newToken = custom_refresh_token(jwtToken) return Response({"message": "Got some data!", "data": newToken}) return Response({"message": "Hello, world!"+str(name)})
def post(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) createdInstance = serializer.save() headers = self.get_success_headers(serializer.data) result = {"id": str(createdInstance.id)} new_token = custom_refresh_token(request.auth) return Response(result, status=status.HTTP_200_OK, headers={'NewToken': new_token})
def list(self, request, *args, **kwargs): queryset = self.filter_queryset(self.get_queryset()) page = self.paginate_queryset(queryset) if page is not None: serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data) serializer = self.get_serializer(queryset, many=True) result = serializer.data.copy() new_token = custom_refresh_token(request.auth) result["token"] = new_token return Response(result)
def list(self, request, *args, **kwargs): queryset = self.filter_queryset(self.get_queryset()) page = self.paginate_queryset(queryset) if page is not None: serializer = self.get_serializer(page, many=True) return self.get_paginated_response(serializer.data) serializer = self.get_serializer(queryset, many=True) # result = modifyUploaderResponseData(queryset, serializer.data) new_token = custom_refresh_token(request.auth) return Response(serializer.data, status=status.HTTP_200_OK, headers={'NewToken': new_token})
def destroy(self, request, *args, **kwargs): ''' change the default destroy function. delete the file stored on OSS at the same time. :param request: :param args: :param kwargs: :return: ''' post = self.get_queryset() # comment = post.query_commentById(kwargs['id']) post.update_one(pull__comment__id=Comment(id=kwargs['id']).id) new_token = custom_refresh_token(request.auth) return Response(status=status.HTTP_204_NO_CONTENT, headers={'NewToken': new_token})
def destroy(self, request, *args, **kwargs): ''' change the default destroy function. delete the file stored on OSS at the same time. :param request: :param args: :param kwargs: :return: ''' instance = self.get_object() url_list = instance['img_url'] + instance['video_url'] + instance[ 'audio_url'] if (len(url_list) > 0): delectOSSFile(url_list) self.perform_destroy(instance) new_token = custom_refresh_token(request.auth) return Response(status=status.HTTP_204_NO_CONTENT, headers={'NewToken': new_token})
def update(self, request, *args, **kwargs): partial = kwargs.pop('partial', False) instance = self.get_queryset().first().query_commentById(kwargs['id']) serializer = self.get_serializer(instance, data=request.data, partial=partial) serializer.is_valid(raise_exception=True) self.perform_update(serializer) if getattr(instance, '_prefetched_objects_cache', None): # If 'prefetch_related' has been applied to a queryset, we need to # forcibly invalidate the prefetch cache on the instance. instance._prefetched_objects_cache = {} new_token = custom_refresh_token(request.auth) return Response(serializer.data, status=status.HTTP_200_OK, headers={'NewToken': new_token})
def update(self, request, *args, **kwargs): # modify the photo_url and location format partial = kwargs.pop('partial', False) instance = self.get_object() serializer = self.get_serializer(instance, data=request.data, partial=partial) serializer.is_valid(raise_exception=True) self.perform_update(serializer) if getattr(instance, '_prefetched_objects_cache', None): # If 'prefetch_related' has been applied to a queryset, we need to # refresh the instance from the database. instance = self.get_object() serializer = self.get_serializer(instance) new_token = custom_refresh_token(request.auth) return Response(serializer.data, status=status.HTTP_200_OK, headers={'NewToken': new_token})
def post( self, request, format=None, ): newrequest = modifyUploaderRequestData( request ) if "multipart/form-data" in request.content_type else request serializer = self.get_serializer(data=newrequest.data) if serializer.is_valid(raise_exception=False): self.perform_create(serializer) # headers = self.get_success_headers(serializer.data) # result = serializer.data.copy() new_token = custom_refresh_token(request.auth) return Response(serializer.data, status=status.HTTP_200_OK, headers={'NewToken': new_token}) else: errors = serializer.errors response_data_fail = {'errormessage': errors} return Response(response_data_fail, status=status.HTTP_400_BAD_REQUEST)
def destroy(self, request, *args, **kwargs): instance = self.get_object() self.perform_destroy(instance) new_token = custom_refresh_token(request.auth) return Response(status=status.HTTP_204_NO_CONTENT, headers={'NewToken': new_token})