Commit e89eb510 authored by Ben Waters's avatar Ben Waters
Browse files

DOIN WORK on api

parent bba0b3da
......@@ -10,5 +10,5 @@ build
apache
.ropeproject
whats_open/secret_key.py
website/static/admin/
static/admin/
data
......@@ -10,7 +10,7 @@ urlpatterns = patterns('',
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^api/v1/', include('rest_framework.urls', namespace='rest_framework')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
......
......@@ -9,7 +9,6 @@ class Category(TimeStampedModel):
class Facility(TimeStampedModel):
"""Represents a facility location on campus."""
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
owners = models.ManyToManyField(User)
category = models.ForeignKey('Category')
......@@ -60,7 +59,6 @@ class Schedule(TimeStampedModel):
when this schedule will be valid can also be set.
"""
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
# inclusive:
valid_start = models.DateField('Start Date', null=True, blank=True,
......@@ -84,7 +82,6 @@ class Schedule(TimeStampedModel):
class OpenTime(TimeStampedModel):
"""Represents a period time when a Facility is open"""
id = models.AutoField(primary_key=True)
schedule = models.ForeignKey('Schedule', related_name='open_times')
monday_start = models.TimeField()
monday_end = models.TimeField()
......
......@@ -18,9 +18,9 @@ urlpatterns = patterns('whats_open_site.views',
url(r'^facilities/(?P<on_campus>)/$', FacilityStatusListView.as_view(), name='facilities-list-by-status'),
#schedules urls
url(r'^schedule/(?P<id>)/$', ScheduleDetailView.as_view(), name='schedule-detail'),
url(r'^schedule/(?P<pk>)/$', ScheduleDetailView.as_view(), name='schedule-detail'),
#opentime urls
url(r'^open-time/(?P<id>)/$', OpenTimeDetailView.as_view(), name='open-time-detail'),
url(r'^open-time/(?P<pk>)/$', OpenTimeDetailView.as_view(), name='open-time-detail'),
)
......@@ -8,8 +8,7 @@ from .models import Facility, OpenTime, Category, Schedule
from .api import export_data
from .serializers import CategorySerializer, FacilitySerializer, ScheduleSerializer, OpenTimeSerializer
from rest_framework.decorators import api_view
from rest_framework.views import APIView
from rest_framework import viewsets
from rest_framework.response import Response
import hashlib
......@@ -20,24 +19,59 @@ class FacilityListView(ListView):
model = Facility
queryset = Facility.objects.all()
class FacilityViewSet(viewsets.ViewSet):
def list(self,request):
queryset = Facility.objects.all()
serializer = FacilitySerializer(queryset,many=True)
return Response(serializer.data)
class FacilityCategoryListView(ListView):
model = Facility
def get_queryset(self):
return Facility.objects.filter(category=self.kwargs['category'])
class FacilityCategoryListViewSet(viewsets.ViewSet):
def list(self,request):
queryset = Facility.objects.filter(category=self.kwargs['category'])
serializer = FacilitySerializer(queryset,many=True)
return Response(serializer.data)
class FacilityStatusListView(ListView):
model = Facility
def get_queryset(self):
return Facility.objects.filter(on_campus=self.kwargs['on_campus'])
class FacilityStatusListViewSet(viewsets.ViewSet):
def list(self,request):
queryset = Facility.objects.filter(on_campus=self.kwargs['on_campus'])
serializer = FacilitySerializer(queryset,many=True)
return Response(serializer.data)
class FacilityDetailView(DetailView):
model = Facility
class FacilityDetailViewSet(viewsets.ViewSet):
def retreive(self,request,slug=None):
queryset = Facility.obejcts.all()
facility = get_object_or_404(queryset,slug=slug)
serializer = FacilitySerializer(facility)
return Response(serializer.data)
class ScheduleDetailView(DetailView):
model = Schedule
def retreive(self,request,pk=None):
queryset = Schedule.objects.all()
schedule = get_object_or_404(queryset,pk=pk)
serializer = ScheduleSerializer(schedule)
return Response(serializer.data)
class OpenTimeDetailView(DetailView):
model = OpenTime
def retrieve(self,request,pk=None):
queryset = OpenTime.objects.all()
open_time = get_object_or_404(queryset,pk=pk)
serializer = OpenTimeSerializer(open_time)
return Response(serializer.data)
"""
class CategoryListView(ListView):
model = Categories
......
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