Commit 929e87a4 authored by Benjamin S Waters's avatar Benjamin S Waters
Browse files

got rid of my shitty old api that i messed up

parent 2a9f8165
......@@ -5,19 +5,14 @@ from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'whats_open.views.home', name='home'),
# url(r'^whats_open/', include('whats_open.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'', include(website.urls)),
url(r'^', include('website.urls')),
url(r'^login/$', 'django.contrib.auth.views.login', {
'template_name': 'login.html'})
'template_name': 'login.html'}),
url(r'^logout/$', 'django.contrib.auth.views.logout', {
'next_page': '/'})
'next_page': '/'}),
)
from rest_framework import serializers
from .models import Category, Facility, Schedule, OpenTime
from website.models import Category, Facility, Schedule, OpenTime
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = ('name')
class FacilitySerializer(serializers.ModelSerializer):
owner = serializers.RelatedField(many=True)
main_schedule = serializers.RelatedField(many=False)
special_schedule = serializers.RelatedField(many=False)
class Meta:
model = Facility
fields = ('name', 'owner', 'slug', 'location', 'main_schedule', 'special_schedules')
class ScheduleSerializer(serializers.ModelSerializer):
class Meta:
model = Schedule
fields = ('name', 'valid_start', 'valid_end')
class OpenTimeSerializer(serializers.ModelSerializer):
schedule = serializers.RelatedField(many=False)
class Meta:
model = OpenTime
fields = ('start_day', 'start_time', 'end_day', 'end_time')
from django.conf.urls import patterns, url
from .views import *
from website.views import *
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
......
......@@ -4,9 +4,9 @@ from django.http import HttpResponse
from django.views.decorators.http import condition
from django.views.generic import ListView, DetailView
from .models import Facility, OpenTime, Category, Schedule
from .api import export_data
from .serializers import CategorySerializer, FacilitySerializer, ScheduleSerializer, OpenTimeSerializer
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.response import Response
......@@ -32,66 +32,24 @@ class OpenTimeViewSet(viewsets.ModelViewSet):
serializer_class = OpenTimeSerializer
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)
serializer_class = FacilitySerializer
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
"""
def facility_grid(request):
......
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