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

work on api

parent a2d7d9dd
from django.shortcuts import render from django.shortcuts import render
from rest_framework import viewsets
from website.serializers import OpenTimeSerializers, ScheduleSerializer, FacilitySerializer, CategorySerializer
# Create your views here. # Create your views here.
class OpenTimeViewSet()
class FacilityViewSet():
...@@ -5,6 +5,7 @@ distribute==0.7.3 ...@@ -5,6 +5,7 @@ distribute==0.7.3
django-autoslug==1.7.2 django-autoslug==1.7.2
django-dajax==0.9.2 django-dajax==0.9.2
django-dajaxice==0.5.5 django-dajaxice==0.5.5
django-guardian==1.1.1
django-leaflet==0.10.1 django-leaflet==0.10.1
django-model-utils==2.0 django-model-utils==2.0
django-randomslugfield==0.2.1 django-randomslugfield==0.2.1
......
...@@ -133,9 +133,16 @@ INSTALLED_APPS = ( ...@@ -133,9 +133,16 @@ INSTALLED_APPS = (
'django.contrib.admindocs', 'django.contrib.admindocs',
'south', 'south',
'rest_framework', 'rest_framework',
'guardian',
'website', 'website',
) )
ANONYMOUS_USER_ID = -1
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', # this is default
'guardian.backends.ObjectPermissionBackend',
)
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer' SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
# A sample logging configuration. The only tangible logging # A sample logging configuration. The only tangible logging
......
from django.contrib import admin from django.contrib import admin
from website.models import Facility, Schedule, OpenTime from website.models import Facility, Schedule, OpenTime
class OpenTimeInline(admin.TabularInline): class OpenTimeInline(admin.TabularInline):
model = OpenTime model = OpenTime
fk_name = 'schedule' fk_name = 'schedule'
class FacilityAdmin(GuardedModelAdmin):
class ScheduleAdmin(admin.ModelAdmin): class ScheduleAdmin(admin.ModelAdmin):
inlines = [OpenTimeInline, ] inlines = [OpenTimeInline, ]
admin.site.register(Facility) admin.site.register(Facility, FacilityAdmin)
admin.site.register(Schedule, ScheduleAdmin) admin.site.register(Schedule, ScheduleAdmin)
...@@ -4,11 +4,14 @@ from model_utils.models import TimeStampedModel ...@@ -4,11 +4,14 @@ from model_utils.models import TimeStampedModel
from autoslug import AutoSlugField from autoslug import AutoSlugField
import datetime import datetime
class Category(TimeStampedModel):
name = models.CharField(max_length=100)
class Facility(TimeStampedModel): class Facility(TimeStampedModel):
"""Represents a dining location on campus.""" """Represents a dining location on campus."""
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
owner = models.ForeignKey(User) owners = models.ManyToManyField(User)
slug = AutoSlugField(populate_from='name',unique=True) slug = AutoSlugField(populate_from='name',unique=True)
location = models.CharField(max_length=100, null=True, blank=True) location = models.CharField(max_length=100, null=True, blank=True)
main_schedule = models.ForeignKey('Schedule', main_schedule = models.ForeignKey('Schedule',
...@@ -47,38 +50,6 @@ class Facility(TimeStampedModel): ...@@ -47,38 +50,6 @@ class Facility(TimeStampedModel):
def __unicode__(self): def __unicode__(self):
return self.name return self.name
class OnCampus(Facility):
class Meta:
pass
class OffCampus(Facility):
class Meta:
pass
class OnCampusRestaurant(OnCampus):
class Meta:
pass
class OnCampusGym(OnCampus):
class Meta:
pass
class OnCampusGeneral(Oncampus):
class Meta:
pass
class OffCampusRestaurant(OffCampus):
class Meta:
pass
class OffCampusShopping(OffCampus):
class Meta:
pass
class OffCampusTransportation(OffCampus):
class Meta:
pass
class Schedule(TimeStampedModel): class Schedule(TimeStampedModel):
""" """
Contains opening and closing times for each day in a week. Contains opening and closing times for each day in a week.
......
from rest_framework import serializers from rest_framework import serializers
from website.models import Category, Facility, Schedule, OpenTime from website.models import Category, Facility, Schedule, OpenTime
class CategorySerializer(serializers.Serializer): class CategorySerializer(serializers.ModelSerializer):
pass class Meta:
class FacilitySerializer(serializers.Serializer): model = Category
pass fields = ('name')
class ScheduleSerializer(serializers.Serializer): class FacilitySerializer(serializers.ModelSerializer):
pass owner = serializers.RelatedField(many=True)
class OpenTimeSerializer(serializers.Serializer): main_schedule = serializers.RelatedField(many=False)
pass 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')
...@@ -8,10 +8,8 @@ import hashlib ...@@ -8,10 +8,8 @@ import hashlib
import json import json
def ListOnCampus(ListView): def ListFacilites(ListView):
model = OnCampus model = Facility
def ListOffCampus(ListView):
model = OnCampus
def facility_grid(request): def facility_grid(request):
"""Display the facilities in a grid. Main page.""" """Display the facilities in a grid. Main page."""
......
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