2013-10-14 22:54:52 -04:00
|
|
|
from models import ParkingLot, ParkingRating
|
|
|
|
from serializers import *
|
2013-10-14 22:31:36 -04:00
|
|
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
from rest_framework.response import Response
|
2013-10-14 22:54:52 -04:00
|
|
|
from rest_framework import status
|
2013-10-14 22:31:36 -04:00
|
|
|
|
|
|
|
class ParkingLotList(APIView):
|
|
|
|
"""
|
|
|
|
List all parking lots
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
parking_lots = ParkingLot.objects.all()
|
|
|
|
serializer = ParkingLotSerializer(parking_lots, many=True)
|
2013-10-14 22:54:52 -04:00
|
|
|
return Response(serializer.data)
|
|
|
|
|
|
|
|
class RateLot(APIView):
|
|
|
|
"""
|
2013-10-14 23:10:09 -04:00
|
|
|
Rate a parking lot
|
|
|
|
**GET**: Get the rating choice options
|
|
|
|
**POST**: Rate a parking lot
|
2013-10-14 22:54:52 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
def post(self, request):
|
2013-10-14 23:10:09 -04:00
|
|
|
'Rate a parking lot'
|
2013-10-14 22:54:52 -04:00
|
|
|
rating = ParkingRatingSerializer(data=request.DATA)
|
|
|
|
if rating.is_valid():
|
|
|
|
rating.save()
|
|
|
|
return Response(rating.data)
|
2013-10-14 23:10:09 -04:00
|
|
|
return Response(rating.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
'Get the rating choice options'
|
|
|
|
return Response(ParkingRating.RATING_CHOICES)
|