views.py 1.71 KB
Newer Older
1
2
3
# standard library imports
from __future__ import absolute_import, print_function
# third party imports
Daniel W Bond's avatar
Daniel W Bond committed
4
from rest_framework.pagination import PageNumberPagination
5
from rest_framework.generics import ListAPIView, RetrieveAPIView
6
7
# imports from your apps
from housing.models import Building, Floor, Room
Daniel W Bond's avatar
Daniel W Bond committed
8
9
10
11
12
from accounts.models import Major
from .serializers import (BuildingSerializer, FloorSerializer, RoomSerializer,
                          MajorSerializer)


13
# pagination class for optional inheritance
Daniel W Bond's avatar
Daniel W Bond committed
14
class HousingPagination(PageNumberPagination):
15
    page_size = 50
Daniel W Bond's avatar
Daniel W Bond committed
16
17
    page_size_query_param = 'page_size'
    max_page_size = 1000
18
19


20
21
22
23
# the actual api views

# housing apis
class BuildingList(ListAPIView):
24
25
26
27
    queryset = Building.objects.all()
    serializer_class = BuildingSerializer


28
29
30
31
32
33
34
35
36
37
38
39
40
41
class BuildingRetrieve(RetrieveAPIView):
    model = Building
    queryset = Building.objects.all()
    serializer_class = BuildingSerializer


#class FloorList(ListAPIView):
#    queryset = Floor.objects.all()
#    serializer_class = FloorSerializer
#    pagination_class = HousingPagination


class FloorRetrieve(RetrieveAPIView):
    model = Floor
42
43
44
45
    queryset = Floor.objects.all()
    serializer_class = FloorSerializer


46
47
class RoomRetrieve(RetrieveAPIView):
    model = Room
48
49
    queryset = Room.objects.all()
    serializer_class = RoomSerializer
Daniel W Bond's avatar
Daniel W Bond committed
50
51


52
53
54
55
56
57
58
59
60
61
62
63
64
65
#class RoomList(ListAPIView):  # kek
#    queryset = Room.objects.all()
#    serializer_class = RoomSerializer
#    pagination_class = HousingPagination


# major apis
class MajorList(ListAPIView):
    queryset = Major.objects.all()
    serializer_class = MajorSerializer


class MajorRetrieve(RetrieveAPIView):
    model = Major
Daniel W Bond's avatar
Daniel W Bond committed
66
67
    queryset = Major.objects.all()
    serializer_class = MajorSerializer