views.py 822 Bytes
Newer Older
Ben Waters's avatar
Ben Waters committed
1
from django.shortcuts import render
Ben Waters's avatar
Ben Waters committed
2
from rest_framework import viewsets
Ben Waters's avatar
Ben Waters committed
3 4 5 6
from rest_framework import authentication, permissions
from rest_framework.response import Response
from rest_framework import status
from rest_framework.decorators import api_view
Ben Waters's avatar
Ben Waters committed
7 8

from .models import Location, LocationSerializer
Ben Waters's avatar
Ben Waters committed
9 10

# Create your views here.
Ben Waters's avatar
Ben Waters committed
11 12
class LocationViewSet(viewsets.ModelViewSet):	
    queryset = Location.objects.all()
Ben Waters's avatar
Ben Waters committed
13
    serializer_class = LocationSerializer
Ben Waters's avatar
Ben Waters committed
14 15 16 17 18 19 20 21

@api_view(['PUT'])
def location_find(request, minLon, maxLon, minLat, maxLat):
    if request.method == 'POST':
        serializer = LocationSerializer(data=request.DATA)
        if serializer.is_valid():
             return Response(serializer.data, status=status.HTTP_200_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Ben Waters's avatar
Ben Waters committed
22 23