Commit e90a1494 authored by Benjamin S Waters's avatar Benjamin S Waters
Browse files

Merge branch 'feature/openstatus' into 'master'


Change 1:
Changed Facility API into Read Only For Now. So now one can breach the API

Change 2:
Added optional filter ?open to list all currently open places. For use in mobile apps

See merge request !3
parents f9f8be98 5bdd5150
......@@ -10,8 +10,9 @@ from website.models import Facility, OpenTime, Category, Schedule
from website.api import export_data
from website.serializers import CategorySerializer, FacilitySerializer, ScheduleSerializer, OpenTimeSerializer
from rest_framework import viewsets
from rest_framework import viewsets, status
from rest_framework.response import Response
from rest_framework.decorators import api_view
import hashlib
import json
......@@ -21,10 +22,24 @@ class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Category.objects.all()
serializer_class = CategorySerializer
class FacilityViewSet(viewsets.ModelViewSet):
class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Facility.objects.all()
serializer_class = FacilitySerializer
def get_queryset(self):
queryset = Facility.objects.all()
open_now = self.request.QUERY_PARAMS.get('open', None)
if open_now is not None:
results = []
for fac in queryset:
print fac
if fac.isOpen():
print True
return results
return queryset
class ScheduleViewSet(viewsets.ModelViewSet):
queryset = Schedule.objects.all()
serializer_class = ScheduleSerializer
......@@ -33,27 +48,6 @@ class OpenTimeViewSet(viewsets.ModelViewSet):
queryset = OpenTime.objects.all()
serializer_class = OpenTimeSerializer
class FacilityListView(ListView):
queryset = Facility.objects.all()
serializer_class = FacilitySerializer
class FacilityCategoryListView(ListView):
model = Facility
def get_queryset(self):
return Facility.objects.filter(category=self.kwargs['category'])
class FacilityStatusListView(ListView):
model = Facility
def get_queryset(self):
return Facility.objects.all()
class FacilityDetailView(DetailView):
model = Facility
class OpenTimeDetailView(DetailView):
model = OpenTime
def facility_grid(request):
"""Display the facilities in a grid. Main page."""
if 'sort' in request.GET:
......@@ -76,4 +70,3 @@ def ajax_schedule_data(request):
# arrays in JSON objects
return HttpResponse(json.dumps({'data': export_data()}, indent=4),
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment