mirror of
https://github.com/bspeice/itcs4180
synced 2024-11-14 03:18:12 -05:00
28 lines
864 B
Python
28 lines
864 B
Python
# Create your views here.
|
|
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(locations_serializer.data)
|
|
|
|
class LocationResult(APIView):
|
|
'''
|
|
Show the result for a specific location
|
|
'''
|
|
def get(self, request, format=None):
|
|
l_form = LocationValidator(data=request.GET)
|
|
if l_form.is_valid():
|
|
location = l_form._instance
|
|
return Response(location.result)
|
|
else:
|
|
return Response("You found the wrong code!", status=400)
|