views.py 1.42 KB
Newer Older
1
2
3
4
5
6
# Future Imports
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

# App Imports
from .models import Facility, OpenTime, Category, Schedule
7
8
from .serializers import (CategorySerializer, FacilitySerializer,
                          ScheduleSerializer, OpenTimeSerializer)
9

10
# Other Imports
11
from rest_framework import viewsets
12
13
14

# Rest Framework Class Views
class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
15
16
    """
    """
17
18
19
    queryset = Category.objects.all()
    serializer_class = CategorySerializer

20
class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
21
22
    """
    """
23
24
25
    queryset = Facility.objects.all()
    serializer_class = FacilitySerializer

26
    def get_queryset(self):
27
28
        """
        """
29
        queryset = Facility.objects.all()
30
        open_now = self.request.query_params.get('open', None)
31
32
33
        if open_now is not None:
            results = []
            for fac in queryset:
34
                print(fac)
35
                if fac.isOpen():
36
                    print(True)
37
38
39
40
41
                    results.append(fac)
            return results
        else:
            return queryset

42
class ScheduleViewSet(viewsets.ModelViewSet):
43
44
    """
    """
45
46
47
48
    queryset = Schedule.objects.all()
    serializer_class = ScheduleSerializer

class OpenTimeViewSet(viewsets.ModelViewSet):
49
50
    """
    """
51
52
    queryset = OpenTime.objects.all()
    serializer_class = OpenTimeSerializer