示例#1
0
 def put(self, request, *args, **kwargs):
     ad_id = int(kwargs.get("pk"))
     ad = ProductAd.objects.get(id=ad_id)
     serializer = AdSerializer(ad, 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)
示例#2
0
 def put(self, request, *args, **kwargs):
     ad_id = int(kwargs.get('pk'))
     ad = ProductAd.objects.get(id=ad_id)
     serializer = AdSerializer(ad, 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)
示例#3
0
    def post(self, request, username, format=None):
        if request.user.username != username:
            return Response(status=status.HTTP_401_UNAUTHORIZED)

        serializer = AdSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save(owner=request.user)
            # helpers.delete_ad(serializer.data.get('id'), 60)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#4
0
    def post(self, request, username, format=None):
        if request.user.username != username:
            return Response(status=status.HTTP_401_UNAUTHORIZED)

        serializer = AdSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save(owner=request.user)
            new_ad_id = serializer.data.get("id")
            notify_data = {}
            notify_data.update({"type": "new_ad_posted"})
            notify_data.update({"ad_id": new_ad_id})
            notify_data.update({"ad_owner": serializer.data.get("owner")})
            helpers.send_push_by_subscribed_categories(notify_data, serializer.data.get("category"))
            # Set an alarm to delete the ad after 24Hours
            helpers.delete_ad(new_ad_id, delay=TWENTY_FOUR_HOURS)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#5
0
    def post(self, request, username, format=None):
        if request.user.username != username:
            return Response(status=status.HTTP_401_UNAUTHORIZED)

        serializer = AdSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save(owner=request.user)
            new_ad_id = serializer.data.get('id')
            notify_data = {}
            notify_data.update({'type': 'new_ad_posted'})
            notify_data.update({'ad_id': new_ad_id})
            notify_data.update({'ad_owner': serializer.data.get('owner')})
            helpers.send_push_by_subscribed_categories(
                notify_data, serializer.data.get('category'))
            # Set an alarm to delete the ad after 24Hours
            helpers.delete_ad(new_ad_id, delay=TWENTY_FOUR_HOURS)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)