Commit 1f9c35a9 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

merges all 1.6 branches

parents 99866cb6 dc6fbf02
from rest_framework import serializers
from website.models import Category, Facility, Schedule, OpenTime
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
class FacilitySerializer(serializers.ModelSerializer):
class Meta:
model = Facility
class ScheduleSerializer(serializers.ModelSerializer):
class Meta:
model = Schedule
class OpenTimeSerializer(serializers.ModelSerializer):
class Meta:
model = OpenTime
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
from django.conf.urls import patterns, include, url
from website.views import *
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
router.register(r'categories', CategoryViewSet)
router.register(r'facilities', FacilityViewSet)
router.register(r'schedules', ScheduleViewSet)
router.register(r'opentimes', OpenTimeViewSet)
urlpatterns = patterns('website.views',
#url(r'^(?:ajax|api)/schedule/', 'ajax_schedule_data', name='schedule_data'),
url(r'^$', 'facility_grid', name='facility_grid'),
url(r'^api/', include(router.urls)),
#facilities open urls
#url(r'^facilities/$', FacilityListView.as_view(), name='faciliites-list'),
#url(r'^facilities/(?P<category>)/$', FacilityCategoryListView.as_view(), name='facilities-list-by-cat'),
#url(r'^facilities/(?P<slug>)/$', FacilityDetailView.as_view(), name='facilities-detail'),
#url(r'^facilities/(?P<on_campus>)/$', FacilityStatusListView.as_view(), name='facilities-list-by-status'),
#schedules urls
#url(r'^schedule/(?P<pk>)/$', ScheduleDetailView.as_view(), name='schedule-detail'),
#opentime urls
url(r'^open-time/(?P<pk>)/$', OpenTimeDetailView.as_view(), name='open-time-detail'),
)
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.views.decorators.http import condition
from django.views.generic import ListView, DetailView
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
import hashlib
import json
class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Category.objects.all()
serializer_class = CategorySerializer
class FacilityViewSet(viewsets.ModelViewSet):
queryset = Facility.objects.all()
serializer_class = FacilitySerializer
class ScheduleViewSet(viewsets.ModelViewSet):
queryset = Schedule.objects.all()
serializer_class = ScheduleSerializer
class OpenTimeViewSet(viewsets.ModelViewSet):
queryset = Schedule.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.filter(on_campus=self.kwargs['on_campus'])
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:
if request.GET['sort'] == 'location':
# Display the grid by location (instead of listing alphabetically)
pass # Not implemented yet
return render_to_response('facility_grid.html',
context_instance=RequestContext(request))
def gen_etag(request):
return hashlib.sha1(str(OpenTime.objects.all())).hexdigest()
def gen_last_modified(request):
return BaseModel.objects.all().order_by('-last_modified')[0].last_modified
@condition(etag_func=gen_etag, last_modified_func=gen_last_modified)
def ajax_schedule_data(request):
# Wrapping up in an object to avoid possible CSRF attack on top-level
# arrays in JSON objects
return HttpResponse(json.dumps({'data': export_data()}, indent=4),
content_type="application/json")
from django.contrib import admin
from website.models import Facility, Category, Schedule, OpenTime
from .models import Facility, Schedule, OpenTime, Category
class OpenTimeInline(admin.TabularInline):
model = OpenTime
fk_name = 'schedule'
class OpenTimeAdmin(admin.ModelAdmin):
pass
class FacilityAdmin(admin.ModelAdmin):
pass
class ScheduleAdmin(admin.ModelAdmin):
inlines = [OpenTimeInline, ]
pass
class CategoryAdmin(admin.ModelAdmin):
pass
admin.site.register(Facility)
admin.site.register(Category)
admin.site.register(Facility, FacilityAdmin)
admin.site.register(Schedule, ScheduleAdmin)
admin.site.register(OpenTime, OpenTimeAdmin)
admin.site.register(Category, CategoryAdmin)
from website.models import Facility
from models import Facility
import re
def export_data():
......
# -*- coding: utf-8 -*-
import datetime
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
......@@ -8,96 +8,170 @@ from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'BaseModel'
db.create_table('website_basemodel', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('last_modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
# Adding model 'Category'
db.create_table(u'website_category', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('created', self.gf('model_utils.fields.AutoCreatedField')(default=datetime.datetime.now)),
('modified', self.gf('model_utils.fields.AutoLastModifiedField')(default=datetime.datetime.now)),
('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
))
db.send_create_signal('website', ['BaseModel'])
db.send_create_signal(u'website', ['Category'])
# Adding model 'Facility'
db.create_table('website_facility', (
('basemodel_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['website.BaseModel'], unique=True, primary_key=True)),
db.create_table(u'website_facility', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('created', self.gf('model_utils.fields.AutoCreatedField')(default=datetime.datetime.now)),
('modified', self.gf('model_utils.fields.AutoLastModifiedField')(default=datetime.datetime.now)),
('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
('category', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['website.Category'])),
('slug', self.gf('autoslug.fields.AutoSlugField')(unique=True, max_length=50, populate_from='name', unique_with=())),
('on_campus', self.gf('django.db.models.fields.BooleanField')(default=True)),
('location', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)),
('main_schedule', self.gf('django.db.models.fields.related.ForeignKey')(related_name='facility_main', to=orm['website.Schedule'])),
))
db.send_create_signal('website', ['Facility'])
db.send_create_signal(u'website', ['Facility'])
# Adding M2M table for field owners on 'Facility'
m2m_table_name = db.shorten_name(u'website_facility_owners')
db.create_table(m2m_table_name, (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('facility', models.ForeignKey(orm[u'website.facility'], null=False)),
('user', models.ForeignKey(orm[u'auth.user'], null=False))
))
db.create_unique(m2m_table_name, ['facility_id', 'user_id'])
# Adding M2M table for field special_schedules on 'Facility'
db.create_table('website_facility_special_schedules', (
m2m_table_name = db.shorten_name(u'website_facility_special_schedules')
db.create_table(m2m_table_name, (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('facility', models.ForeignKey(orm['website.facility'], null=False)),
('schedule', models.ForeignKey(orm['website.schedule'], null=False))
('facility', models.ForeignKey(orm[u'website.facility'], null=False)),
('schedule', models.ForeignKey(orm[u'website.schedule'], null=False))
))
db.create_unique('website_facility_special_schedules', ['facility_id', 'schedule_id'])
db.create_unique(m2m_table_name, ['facility_id', 'schedule_id'])
# Adding model 'Schedule'
db.create_table('website_schedule', (
('basemodel_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['website.BaseModel'], unique=True, primary_key=True)),
db.create_table(u'website_schedule', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('created', self.gf('model_utils.fields.AutoCreatedField')(default=datetime.datetime.now)),
('modified', self.gf('model_utils.fields.AutoLastModifiedField')(default=datetime.datetime.now)),
('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
('valid_start', self.gf('django.db.models.fields.DateField')(null=True, blank=True)),
('valid_end', self.gf('django.db.models.fields.DateField')(null=True, blank=True)),
))
db.send_create_signal('website', ['Schedule'])
db.send_create_signal(u'website', ['Schedule'])
# Adding model 'OpenTime'
db.create_table('website_opentime', (
('basemodel_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['website.BaseModel'], unique=True, primary_key=True)),
db.create_table(u'website_opentime', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('created', self.gf('model_utils.fields.AutoCreatedField')(default=datetime.datetime.now)),
('modified', self.gf('model_utils.fields.AutoLastModifiedField')(default=datetime.datetime.now)),
('schedule', self.gf('django.db.models.fields.related.ForeignKey')(related_name='open_times', to=orm['website.Schedule'])),
('start_day', self.gf('django.db.models.fields.IntegerField')()),
('start_time', self.gf('django.db.models.fields.TimeField')()),
('end_day', self.gf('django.db.models.fields.IntegerField')()),
('end_time', self.gf('django.db.models.fields.TimeField')()),
))
db.send_create_signal('website', ['OpenTime'])
db.send_create_signal(u'website', ['OpenTime'])
def backwards(self, orm):
# Deleting model 'BaseModel'
db.delete_table('website_basemodel')
# Deleting model 'Category'
db.delete_table(u'website_category')
# Deleting model 'Facility'
db.delete_table('website_facility')
db.delete_table(u'website_facility')
# Removing M2M table for field owners on 'Facility'
db.delete_table(db.shorten_name(u'website_facility_owners'))
# Removing M2M table for field special_schedules on 'Facility'
db.delete_table('website_facility_special_schedules')
db.delete_table(db.shorten_name(u'website_facility_special_schedules'))
# Deleting model 'Schedule'
db.delete_table('website_schedule')
db.delete_table(u'website_schedule')
# Deleting model 'OpenTime'
db.delete_table('website_opentime')
db.delete_table(u'website_opentime')
models = {
'website.basemodel': {
'Meta': {'object_name': 'BaseModel'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'last_modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'})
u'auth.group': {
'Meta': {'object_name': 'Group'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
u'auth.permission': {
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'website.opentime': {
'Meta': {'object_name': 'OpenTime', '_ormbases': ['website.BaseModel']},
'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['website.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
u'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'website.category': {
'Meta': {'ordering': "['name']", 'object_name': 'Category'},
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
u'website.facility': {
'Meta': {'ordering': "['name']", 'object_name': 'Facility'},
'category': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['website.Category']"}),
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'main_schedule': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'facility_main'", 'to': u"orm['website.Schedule']"}),
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'on_campus': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'owners': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.User']", 'symmetrical': 'False'}),
'slug': ('autoslug.fields.AutoSlugField', [], {'unique': 'True', 'max_length': '50', 'populate_from': "'name'", 'unique_with': '()'}),
'special_schedules': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'facility_special'", 'null': 'True', 'symmetrical': 'False', 'to': u"orm['website.Schedule']"})
},
u'website.opentime': {
'Meta': {'object_name': 'OpenTime'},
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
'end_day': ('django.db.models.fields.IntegerField', [], {}),
'end_time': ('django.db.models.fields.TimeField', [], {}),
'schedule': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'open_times'", 'to': "orm['website.Schedule']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
'schedule': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'open_times'", 'to': u"orm['website.Schedule']"}),
'start_day': ('django.db.models.fields.IntegerField', [], {}),
'start_time': ('django.db.models.fields.TimeField', [], {})
},
'website.facility': {
'Meta': {'object_name': 'Facility', '_ormbases': ['website.BaseModel']},
'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['website.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'main_schedule': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'facility_main'", 'to': "orm['website.Schedule']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'special_schedules': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'facility_special'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['website.Schedule']"})
},
'website.schedule': {
'Meta': {'object_name': 'Schedule', '_ormbases': ['website.BaseModel']},
'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['website.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
u'website.schedule': {
'Meta': {'ordering': "['name']", 'object_name': 'Schedule'},
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'valid_end': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'valid_start': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['website']
complete_apps = ['website']
\ No newline at end of file
from django.db import models
from django.contrib.auth.models import User
from model_utils.models import TimeStampedModel
from autoslug import AutoSlugField
import datetime
class BaseModel(models.Model):
last_modified = models.DateTimeField('Last Modified', auto_now=True)
class Category(BaseModel):
class Category(TimeStampedModel):
name = models.CharField(max_length=100)
class Meta:
verbose_name = "category"
verbose_name_plural = "categories"
# Sort by name in admin view
ordering = ['name']
def __unicode__(self):
return self.name
return '%s' % self.name
class Facility(BaseModel):
"""Represents a dining location on campus."""
class Facility(TimeStampedModel):
"""Represents a facility location on campus."""
name = models.CharField(max_length=100)
category = models.ForeignKey('Category', related_name="facilities", null=True, blank=True)
owners = models.ManyToManyField(User)
category = models.ForeignKey('Category')
slug = AutoSlugField(populate_from='name',unique=True)
on_campus = models.BooleanField(default=True)
location = models.CharField(max_length=100, null=True, blank=True)
main_schedule = models.ForeignKey('Schedule',
related_name='facility_main')
......@@ -58,8 +59,7 @@ class Facility(BaseModel):
def __unicode__(self):
return self.name
class Schedule(BaseModel):
class Schedule(TimeStampedModel):
"""
Contains opening and closing times for each day in a week.
......@@ -88,9 +88,10 @@ class Schedule(BaseModel):
return self.name
class OpenTime(BaseModel):
class OpenTime(TimeStampedModel):
"""Represents a period time when a Facility is open"""
schedule = models.ForeignKey('Schedule', related_name='open_times')
schedule = models.ForeignKey('Schedule', related_name='open_times')
start_day = models.IntegerField() # 0-6, Monday == 0
start_time = models.TimeField()
end_day = models.IntegerField() # 0-6, Monday == 0
......
from django.conf.urls import patterns, include, url
from django.contrib.sites.models import Site
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
from management.urls import management_urls
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'^', include('website.urls')),
url(r'management/', include('management.urls')),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^management/', include(management_urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^admin/', include(admin.site.urls)),
url(r'', include('website.urls')),
url(r'^logout/$', 'django.contrib.auth.views.logout', {
'next_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