Example #1
0
 def put(self, request, pk):
     profile = Profile.objects.get(id=pk)
     if profile is not None:
         serializer = ProfileSerializer(profile, data=request.data)
         if serializer.is_valid(raise_exception=True):
             serializer.save(user=request.user)
             return Response(prepare_create_success_response(
                 serializer.data),
                             status=status.HTTP_201_CREATED)
         return Response(prepare_create_success_response(serializer.errors),
                         status=status.HTTP_400_BAD_REQUEST)
     else:
         return Response(prepare_error_response('The user ID not found'),
                         status=status.HTTP_403_FORBIDDEN)
Example #2
0
 def post(self, request):
     serializer = RegistrationSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(prepare_create_success_response(serializer.data),
                         status=status.HTTP_201_CREATED)
     return Response(prepare_error_response(serializer.errors),
                     status=status.HTTP_400_BAD_REQUEST)
Example #3
0
 def post(self, request):
     try:
         serializer = OrderSerializer(data=request.data)
         if serializer.is_valid():
             serializer.save(user=self.request.user)
             return Response(prepare_create_success_response(serializer.data), status=status.HTTP_201_CREATED)
         return Response(prepare_error_response(serializer.errors), status=status.HTTP_400_BAD_REQUEST)
     except Exception as e:
         return Response(prepare_error_response(str(e)), status=status.HTTP_404_NOT_FOUND)
Example #4
0
 def post(self, request):
     validation_error = password_validation(request.data)
     if validation_error is not None:
         return Response(prepare_error_response(validation_error),
                         status=status.HTTP_400_BAD_REQUEST)
     serializer = UserCreateSerializer(data=request.data)
     if serializer.is_valid(raise_exception=True):
         serializer.save()
         return Response(prepare_create_success_response(serializer.data),
                         status=status.HTTP_201_CREATED)
     return Response(prepare_error_response(serializer.errors),
                     status=status.HTTP_400_BAD_REQUEST)
Example #5
0
 def post(self, request):
     try:
         if request.user.role == ROLE.ADMIN or request.user.role == ROLE.MANAGER or request.user.role == ROLE.SHOPKEEPER:
             validate_error = validate_item_service(request.data)
             if validate_error is not None:
                 return Response(prepare_error_response(validate_error), status=status.HTTP_400_BAD_REQUEST)
             serializer = ItemSerializer(data=request.data)
             if serializer.is_valid():
                 serializer.save(proprietor=self.request.user.shop_owner)
                 return Response(prepare_create_success_response(serializer.data), status=status.HTTP_201_CREATED)
             return Response(prepare_error_response(serializer.errors), status=status.HTTP_400_BAD_REQUEST)
         else:
             return Response(prepare_error_response('You have no permission'), status=status.HTTP_401_UNAUTHORIZED)
     except Exception as e:
         return Response(prepare_error_response(str(e)), status=status.HTTP_400_BAD_REQUEST)
Example #6
0
 def put(self, request, pk):
     profile = self.get_object(pk)
     if profile is not None:
         serializer = ProfileSerializer(profile, data=request.data)
         if serializer.is_valid():
             serializer.save(user=request.user)
             return Response(prepare_create_success_response(
                 serializer.data),
                             status=status.HTTP_201_CREATED)
         return Response(prepare_error_response(serializer.errors),
                         status=status.HTTP_400_BAD_REQUEST)
     else:
         return Response(
             prepare_error_response("No user found for this ID"),
             status=status.HTTP_400_BAD_REQUEST)
Example #7
0
 def put(self, request, pk):
     if request.user.role == ROLE.ADMIN or request.user.role == ROLE.MANAGER or request.user.role == ROLE.SHOPKEEPER:
         validate_error = validate_item_service(request.data)
         if validate_error is not None:
             return Response(prepare_error_response(validate_error), status=status.HTTP_400_BAD_REQUEST)
         item = self.get_object(pk)
         if item is not None:
             serializer = ItemSerializer(item, data=request.data)
             if serializer.is_valid():
                 serializer.save()
                 return Response(prepare_create_success_response(serializer.data), status=status.HTTP_201_CREATED)
             return Response(prepare_error_response(serializer.errors), status=status.HTTP_400_BAD_REQUEST)
         else:
             return Response(prepare_error_response("No data found for this ID"), status=status.HTTP_400_BAD_REQUEST)
     else:
         return Response(prepare_error_response('You have no permission'), status=status.HTTP_401_UNAUTHORIZED)
Example #8
0
 def post(self, request, *args, **kwargs):
     if request.user.role == ROLE.ADMIN:
         try:
             serializer = SiteSettingSerializer(data=request.data)
             if serializer.is_valid():
                 serializer.save()
                 return Response(prepare_create_success_response(
                     serializer.data),
                                 status=status.HTTP_201_CREATED)
             return Response(prepare_error_response(serializer.errors),
                             status=status.HTTP_404_NOT_FOUND)
         except Exception as e:
             return Response(prepare_error_response(str(e)),
                             status=status.HTTP_404_NOT_FOUND)
     else:
         return Response(prepare_error_response('You have no permission'),
                         status=status.HTTP_401_UNAUTHORIZED)
Example #9
0
 def put(self, request, pk):
     if request.user.role == ROLE.ADMIN or request.user.role == ROLE.MANAGER or request.user.role == ROLE.SHOPKEEPER:
         try:
             order_item = self.get_object(pk)
             serializer = OrderItemSerializer(order_item, data=request.data)
             if serializer.is_valid(raise_exception=True):
                 serializer.save()
                 return Response(prepare_create_success_response(
                     serializer.data),
                                 status=status.HTTP_201_CREATED)
             return Response(prepare_error_response(serializer.errors),
                             status=status.HTTP_400_BAD_REQUEST)
         except Exception as e:
             return Response(prepare_error_response(str(e)),
                             status=status.HTTP_400_BAD_REQUEST)
     else:
         return Response(prepare_error_response('You have no permission'),
                         status=status.HTTP_401_UNAUTHORIZED)
Example #10
0
 def put(self, request, pk):
     try:
         if request.user.role == ROLE.ADMIN or request.user.role == ROLE.MANAGER or request.user.role == ROLE.SHOPKEEPER:
             order = self.get_object(pk)
             if order is not None:
                 serializer = OrderSerializer(order, data=request.data)
                 if serializer.is_valid(raise_exception=True):
                     serializer.save(user=self.request.user)
                     return Response(prepare_create_success_response(serializer.data),
                                     status=status.HTTP_201_CREATED)
                 return Response(prepare_error_response(serializer.errors), status=status.HTTP_400_BAD_REQUEST)
             else:
                 return Response(prepare_error_response("No data found for this ID"),
                                 status=status.HTTP_400_BAD_REQUEST)
         else:
             return Response(prepare_error_response('You have no permission'), status=status.HTTP_400_BAD_REQUEST)
     except Exception as e:
         return Response(prepare_error_response(str(e)), status=status.HTTP_404_NOT_FOUND)