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

# Python stdlib Imports
import hashlib
import json

# Django Imports
10
from django.template import RequestContext
11
from django.shortcuts import render_to_response
12
13
from django.http import HttpResponse
from django.views.decorators.http import condition
14
from django.views.generic import ListView, DetailView
Daniel W Bond's avatar
Daniel W Bond committed
15
from model_utils.models import TimeStampedModel
16

17
18
19
20
# App Imports
from .models import Facility, OpenTime, Category, Schedule
from .api import export_data
from .serializers import  CategorySerializer, FacilitySerializer, ScheduleSerializer, OpenTimeSerializer
21

22
# Other Imports
23
from rest_framework import viewsets, status
24
from rest_framework.response import Response
25
from rest_framework.decorators import api_view
26
27
28
29
30
31

# Rest Framework Class Views
class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Category.objects.all()
    serializer_class = CategorySerializer

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

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

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

class OpenTimeViewSet(viewsets.ModelViewSet):
    queryset = OpenTime.objects.all()
    serializer_class = OpenTimeSerializer

58
59
60
61
def gen_etag(request):
    return hashlib.sha1(str(OpenTime.objects.all())).hexdigest()

def gen_last_modified(request):
Daniel W Bond's avatar
Daniel W Bond committed
62
    return TimeStampedModel.objects.all().order_by('-last_modified')[0].last_modified