Example #1
0
 def update_location(self, location_object):
     serialized_location = LocationSerializer(data=location_object)
     if serialized_location.is_valid():
         location = Location(**serialized_location.validated_data)
         location.user = self.__user
         location.time = timezone.now()
         location.category = self.categorize_location(
             latitude=location.latitude, longitude=location.longitude)
         location.save()
         return location
     else:
         raise self.InvalidLocation()
def location_list(request):
    """
    List all locations, or create a new location.
    """
    if request.method == 'GET':
        locations = Location.objects.all()
        serializer = LocationSerializer(locations, many=True)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = LocationSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)
Example #3
0
def location_list(request):
    """
    List all locations, or create a new location.
    """
    if request.method == 'GET':
        locations = Location.objects.all()
        serializer = LocationSerializer(locations, many=True)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = LocationSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)