views.py 1.75 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, Alert
12
from .serializers import (CategorySerializer, FacilitySerializer,
13
                          ScheduleSerializer, OpenTimeSerializer, 
David Haynes's avatar
David Haynes committed
14
                          LocationSerializer, AlertSerializer)
15

16
# Other Imports
17
from rest_framework import viewsets
18

David Haynes's avatar
David Haynes committed
19
20
21
22
23
24
class AlertViewSet(viewsets.ReadOnlyModelViewSet):
    """
    """
    queryset = Alert.objects.all()
    serializer_class = AlertSerializer

25
class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
26
27
    """
    """
28
29
30
    queryset = Category.objects.all()
    serializer_class = CategorySerializer

David Haynes's avatar
David Haynes committed
31
32
33
34
35
36
class LocationViewSet(viewsets.ReadOnlyModelViewSet):
    """
    """
    queryset = Location.objects.all()
    serializer_class = LocationSerializer

37
class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
38
39
    """
    """
40
41
42
    queryset = Facility.objects.all()
    serializer_class = FacilitySerializer

43
    def get_queryset(self):
44
45
        """
        """
46
        queryset = Facility.objects.all()
47
        open_now = self.request.query_params.get('open', None)
48
49
50
        if open_now is not None:
            results = []
            for fac in queryset:
51
                if fac.is_open_now():
52
53
54
55
56
                    results.append(fac)
            return results
        else:
            return queryset

57
class ScheduleViewSet(viewsets.ModelViewSet):
58
59
    """
    """
60
61
62
63
    queryset = Schedule.objects.all()
    serializer_class = ScheduleSerializer

class OpenTimeViewSet(viewsets.ModelViewSet):
64
65
    """
    """
66
67
    queryset = OpenTime.objects.all()
    serializer_class = OpenTimeSerializer