views.py 1.59 KB
Newer Older
1
"""
2
3
api/views.py

4
5
Rest Framework Class Views
"""
6
7
8
9
10
# Future Imports
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

# App Imports
David Haynes's avatar
David Haynes committed
11
from .models import Facility, OpenTime, Category, Schedule, Location
12
from .serializers import (CategorySerializer, FacilitySerializer,
13
14
                          ScheduleSerializer, OpenTimeSerializer, 
                          LocationSerializer)
15

16
# Other Imports
17
from rest_framework import viewsets
18
19

class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
20
21
    """
    """
22
23
24
    queryset = Category.objects.all()
    serializer_class = CategorySerializer

David Haynes's avatar
David Haynes committed
25
26
27
28
29
30
class LocationViewSet(viewsets.ReadOnlyModelViewSet):
    """
    """
    queryset = Location.objects.all()
    serializer_class = LocationSerializer

31
class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
32
33
    """
    """
34
35
36
    queryset = Facility.objects.all()
    serializer_class = FacilitySerializer

37
    def get_queryset(self):
38
39
        """
        """
40
        queryset = Facility.objects.all()
41
        open_now = self.request.query_params.get('open', None)
42
43
44
        if open_now is not None:
            results = []
            for fac in queryset:
45
                if fac.is_open_now():
46
47
48
49
50
                    results.append(fac)
            return results
        else:
            return queryset

51
class ScheduleViewSet(viewsets.ModelViewSet):
52
53
    """
    """
54
55
56
57
    queryset = Schedule.objects.all()
    serializer_class = ScheduleSerializer

class OpenTimeViewSet(viewsets.ModelViewSet):
58
59
    """
    """
60
61
    queryset = OpenTime.objects.all()
    serializer_class = OpenTimeSerializer