예제 #1
0
파일: views.py 프로젝트: EnHueco/APIEnHueco
 def update(self, request, pk):
     try:
         user = User.objects.get(login=pk)
         serializer = LocationSerializer(user.location, data=request.data, partial=True)
         if serializer.is_valid():
             serializer.save()
             return Response(serializer.data, status=status.HTTP_200_OK)
         return Response("Invalid Serializer", status=status.HTTP_400_BAD_REQUEST)
     except (User.DoesNotExist, ValueError) as e:
         return Response(e, status=status.HTTP_400_BAD_REQUEST)
     except:
         return Response(sys.exc_info()[0],status=status.HTTP_500_INTERNAL_SERVER_ERROR)
예제 #2
0
 def update(self, request, pk):
     try:
         user = User.objects.get(login=pk)
         serializer = LocationSerializer(user.location,
                                         data=request.data,
                                         partial=True)
         if serializer.is_valid():
             serializer.save()
             return Response(serializer.data, status=status.HTTP_200_OK)
         return Response("Invalid Serializer",
                         status=status.HTTP_400_BAD_REQUEST)
     except (User.DoesNotExist, ValueError) as e:
         return Response(e, status=status.HTTP_400_BAD_REQUEST)
     except:
         return Response(sys.exc_info()[0],
                         status=status.HTTP_500_INTERNAL_SERVER_ERROR)
예제 #3
0
파일: views.py 프로젝트: EnHueco/APIEnHueco
 def updateWithFriendsList(self, request, pk):
     try:
         user = User.objects.get(login=pk)
         serializer = LocationSerializer(user.location, data=request.data, partial=True)
         if serializer.is_valid():
             serializer.save()
             now = datetime.datetime.now()
             earlier = now - datetime.timedelta(minutes=5)
             friends = User.objects.get(login=pk).friends.exclude(location__bssid="").filter(location__bssid_date__range=(earlier, now))
             serializer = UserLocationSerializer(friends, many=True)
             return Response(serializer.data, status=status.HTTP_200_OK)
         return Response("Invalid Serializer",status=status.HTTP_400_BAD_REQUEST)
     except User.DoesNotExist:
         return Response("User does not exist", status=status.HTTP_400_BAD_REQUEST)
     except:
         return Response(sys.exc_info()[0],status=status.HTTP_500_INTERNAL_SERVER_ERROR)
예제 #4
0
 def updateWithFriendsList(self, request, pk):
     try:
         user = User.objects.get(login=pk)
         serializer = LocationSerializer(user.location,
                                         data=request.data,
                                         partial=True)
         if serializer.is_valid():
             serializer.save()
             now = datetime.datetime.now()
             earlier = now - datetime.timedelta(minutes=5)
             friends = User.objects.get(login=pk).friends.exclude(
                 location__bssid="").filter(
                     location__bssid_date__range=(earlier, now))
             serializer = UserLocationSerializer(friends, many=True)
             return Response(serializer.data, status=status.HTTP_200_OK)
         return Response("Invalid Serializer",
                         status=status.HTTP_400_BAD_REQUEST)
     except User.DoesNotExist:
         return Response("User does not exist",
                         status=status.HTTP_400_BAD_REQUEST)
     except:
         return Response(sys.exc_info()[0],
                         status=status.HTTP_500_INTERNAL_SERVER_ERROR)