2014-03-26 23:26:57 -04:00
|
|
|
# Create your views here.
|
2014-03-28 18:31:06 -04:00
|
|
|
from scavenger.models import Location
|
|
|
|
from scavenger.serializers import LocationListSerializer
|
|
|
|
from scavenger.forms import LocationValidator
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
|
|
|
class LocationList(APIView):
|
|
|
|
'''
|
|
|
|
List all locations available for the scavenger hunt.
|
|
|
|
'''
|
|
|
|
def get(self, request, format=None):
|
|
|
|
locations = Location.objects.all()
|
|
|
|
locations_serializer = LocationListSerializer(locations, many=True)
|
|
|
|
return Response(serializer.data)
|
|
|
|
|
|
|
|
class LocationResult(APIView):
|
|
|
|
'''
|
|
|
|
Show the result for a specific location
|
|
|
|
'''
|
|
|
|
def get(self, request, format=None):
|
2014-03-31 14:30:21 -04:00
|
|
|
l_form = LocationValidator(data=request.GET)
|
2014-03-28 18:31:06 -04:00
|
|
|
if l_form.is_valid():
|
|
|
|
location = l_form._instance
|
|
|
|
return Response(location.result)
|
|
|
|
else:
|
|
|
|
return Response("You found the wrong code!", status=400)
|