views.py 1.57 KB
Newer Older
1
2
3
"""
Rest Framework Class Views
"""
4
5
6
7
8
# Future Imports
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

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

14
# Other Imports
15
from rest_framework import viewsets
16
17

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

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

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

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

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

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