Exemple #1
0
 def put(self, request, pk, format=None):
     file = self.get_object(pk)
     serializer = UrunResimler(file, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #2
0
 def put(self, request, pk, format=None):
     user = self.get_object(pk)
     serializer = PilotplotsSerializer(user, data=request.DATA)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #3
0
def Register(request):
    apiresponse = {}
    #Getting The Comming Request
    data = JSONParser().parse(request)
    if ("Users_Email" in data and data['Users_Email'] != ""
            and "Users_Password" in data and data['Users_Password'] != ""):
        email = data['Users_Email']
        password = data['Users_Password']
        if is_user_email_exist(email):
            serializer = Userserilazers(data=data)
            if serializer.is_valid():
                serializer.save()
                apiresponse['status'] = 102
                apiresponse['Details'] = "Registration Complete"
            else:
                apiresponse['status'] = 103
                apiresponse['Details'] = serializer.errors
        else:
            apiresponse['status'] = 101
            apiresponse['Details'] = "Email Id Already Exist"
    else:
        apiresponse['status'] = 104
        apiresponse['Details'] = "Need To Pass User Name And Password"

    return Response(apiresponse)
Exemple #4
0
 def post(self, request, format=None):
     serializer = StockSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         print(serializer)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #5
0
 def perform_create(self, serializer):
     try:
         if serializer.is_valid(raise_exception=False):
             serializer.save(owner=random_user())
     except IntegrityError:
         return Response(data={'message': 'That URL already exists'},
                         status=HTTP_400_BAD_REQUEST)
Exemple #6
0
def drf_article_create(request):
    serializer = ArticleCreateSerializer(data=request.data,
                                         context={'writer': request.user})
    if serializer.is_valid():
        serializer.save()
        article_serialized = serializer.data
        return Response(article_serialized, status=status.HTTP_201_CREATED)
    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #7
0
 def resim_ekle(self, request, pk):
     obj = self.get_object()
     serializer = self.serializer_class(obj, data=request.data,
                                        partial=True)
     if serializer.is_valid():
         serializer.save()
         return response.Response(serializer.data)
     return response.Response(serializer.errors,
                              status.HTTP_400_BAD_REQUEST)
Exemple #8
0
 def title(self, request, pk=None):
     """
     修改标题
     """
     address = self.get_object()
     serializer = serializers.AddressTitleSerializer(instance=address, data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(serializer.data)
Exemple #9
0
def Submit_Location(request):
    if request.method == 'POST':

        user_id = request.user.id
        print(repr(request.data))
        serializer = RecordSerializer(data=request.data,
                                      context={'user_id': request.user.id})
        if (serializer.is_valid()):
            serializer.save()
            content = json.dumps({'status': "success"})
            return HttpResponse(content)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #10
0
    def post(self, request, *args, **kwargs):
        serializer = EventSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors)


# sample json resonse data
# def test_api(request):
#      data = {
#         'title': ' Heading for the best',
#         'description':' we are live now no shaking ',
#         'locaction ':'wembley park',
#         'date': 'December'
#      }
#      return JsonResponse(data)
Exemple #11
0
 def post(self, request, *args, **kwargs):
     request_data = request.data
     print(request_data)
     serializer = UserSerialize(data=request_data)
     print("okok")
     serializer.is_valid(raise_exception=True)
     res = serializer.save()
     return APIResponse(200, True, results=UserSerialize(res).data)
Exemple #12
0
 def post(self, request, pk, choice_pk):
     voted_by = request.data.get("voted_by")
     data = {'choice': choice_pk, 'poll': pk, 'voted_by': voted_by}
     serializer = VoteSerializer(data=data)
     if serializer.is_valid():
         vote = serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Exemple #13
0
 def post(self, request, *args, **kwargs):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = serializer.save()
     return Response({
         "user":
         UserSerializer(user, context=self.get_serializer_context()).data,
         "token":
         AuthToken.objects.create(user)[1]
     })
Exemple #14
0
def drf_register_view(request):
    # print('drf_register_view')
    if request.method == 'POST':
        serializer = WriterRegistrationSerializer(data=request.data)
        data = {}
        if serializer.is_valid():
            # print('is_valid')
            writer = serializer.save()
            data['response'] = "Successfully registered a new user."
            data['name'] = writer.name
            data['is_editor'] = writer.is_editor
            token = Token.objects.get(user=writer)
            data['token'] = token.key
            # print('data', data)
        else:
            data = serializer.errors
        # print(data)
        return Response(data)
 def perform_create(self, serializer):
     serializer.save(operator=self.request.user)
Exemple #16
0
 def post(self, request):
     serializer = AvaliacaoSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(serializer.data, status=status.HTTP_201_CREATED)
 def perform_create(self, serializer):
     return serializer.save()
Exemple #18
0
 def post(self, request, *args, **kwargs):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save(author=self.request.user)
     return Response(serializer.data)
Exemple #19
0
 def patch(self, request, *args, **kwargs):
     obj = self.get_object()
     serializer = self.get_serializer(obj, data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(serializer.data)
def taskCreate(request):
    serializer = TaskSerializer(data=request.data)
    if serializer.is_valid():
        serializer.save()
    return Response(serializer.data)
Exemple #21
0
 def post(self, request, format=None):
     serializer = STRVVarietySerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200_OK)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #22
0
 def perform_create(self):
     serializer.save(user=self.request.user)
Exemple #23
0
 def perform_update(self, serializer):
     serializer.save(user=self.request.user)
def taskUpdate(request, pk):
    tasks = Task.objects.get(id=pk)
    serializer = TaskSerializer(instance=tasks, data=request.data)
    if serializer.is_valid():
        serializer.save()
    return Response(serializer.data)