Commit 716f240d authored by Tyler Hallada's avatar Tyler Hallada
Browse files

Renamed model fields to correct style. Other bug fixes.

parent 784a388b
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Deleting field 'Schedule.satClose'
db.delete_column('website_schedule', 'satClose')
# Deleting field 'Schedule.friClose'
db.delete_column('website_schedule', 'friClose')
# Deleting field 'Schedule.tueClose'
db.delete_column('website_schedule', 'tueClose')
# Deleting field 'Schedule.wedClose'
db.delete_column('website_schedule', 'wedClose')
# Deleting field 'Schedule.monOpen'
db.delete_column('website_schedule', 'monOpen')
# Deleting field 'Schedule.friOpen'
db.delete_column('website_schedule', 'friOpen')
# Deleting field 'Schedule.dateValidStart'
db.delete_column('website_schedule', 'dateValidStart')
# Deleting field 'Schedule.sunOpen'
db.delete_column('website_schedule', 'sunOpen')
# Deleting field 'Schedule.tueOpen'
db.delete_column('website_schedule', 'tueOpen')
# Deleting field 'Schedule.monClose'
db.delete_column('website_schedule', 'monClose')
# Deleting field 'Schedule.wedOpen'
db.delete_column('website_schedule', 'wedOpen')
# Deleting field 'Schedule.sunClose'
db.delete_column('website_schedule', 'sunClose')
# Deleting field 'Schedule.thuOpen'
db.delete_column('website_schedule', 'thuOpen')
# Deleting field 'Schedule.thuClose'
db.delete_column('website_schedule', 'thuClose')
# Deleting field 'Schedule.satOpen'
db.delete_column('website_schedule', 'satOpen')
# Deleting field 'Schedule.dateValidEnd'
db.delete_column('website_schedule', 'dateValidEnd')
# Adding field 'Schedule.valid_start'
db.add_column('website_schedule', 'valid_start',
self.gf('django.db.models.fields.DateField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.valid_end'
db.add_column('website_schedule', 'valid_end',
self.gf('django.db.models.fields.DateField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.mon_open'
db.add_column('website_schedule', 'mon_open',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.mon_close'
db.add_column('website_schedule', 'mon_close',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.tue_open'
db.add_column('website_schedule', 'tue_open',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.tue_close'
db.add_column('website_schedule', 'tue_close',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.wed_open'
db.add_column('website_schedule', 'wed_open',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.wed_close'
db.add_column('website_schedule', 'wed_close',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.thu_open'
db.add_column('website_schedule', 'thu_open',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.thu_close'
db.add_column('website_schedule', 'thu_close',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.fri_open'
db.add_column('website_schedule', 'fri_open',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.fri_close'
db.add_column('website_schedule', 'fri_close',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.sat_open'
db.add_column('website_schedule', 'sat_open',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.sat_close'
db.add_column('website_schedule', 'sat_close',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.sun_open'
db.add_column('website_schedule', 'sun_open',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.sun_close'
db.add_column('website_schedule', 'sun_close',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Deleting field 'Restaurant.mainSchedule'
db.delete_column('website_restaurant', 'mainSchedule_id')
# Adding field 'Restaurant.main_schedule'
db.add_column('website_restaurant', 'main_schedule',
self.gf('django.db.models.fields.related.ForeignKey')(default=0, related_name='restaurant_main', to=orm['website.Schedule']),
keep_default=False)
# Removing M2M table for field specialSchedules on 'Restaurant'
db.delete_table('website_restaurant_specialSchedules')
# Adding M2M table for field special_schedules on 'Restaurant'
db.create_table('website_restaurant_special_schedules', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('restaurant', models.ForeignKey(orm['website.restaurant'], null=False)),
('schedule', models.ForeignKey(orm['website.schedule'], null=False))
))
db.create_unique('website_restaurant_special_schedules', ['restaurant_id', 'schedule_id'])
def backwards(self, orm):
# Adding field 'Schedule.satClose'
db.add_column('website_schedule', 'satClose',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.friClose'
db.add_column('website_schedule', 'friClose',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.tueClose'
db.add_column('website_schedule', 'tueClose',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.wedClose'
db.add_column('website_schedule', 'wedClose',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.monOpen'
db.add_column('website_schedule', 'monOpen',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.friOpen'
db.add_column('website_schedule', 'friOpen',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.dateValidStart'
db.add_column('website_schedule', 'dateValidStart',
self.gf('django.db.models.fields.DateField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.sunOpen'
db.add_column('website_schedule', 'sunOpen',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.tueOpen'
db.add_column('website_schedule', 'tueOpen',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.monClose'
db.add_column('website_schedule', 'monClose',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.wedOpen'
db.add_column('website_schedule', 'wedOpen',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.sunClose'
db.add_column('website_schedule', 'sunClose',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.thuOpen'
db.add_column('website_schedule', 'thuOpen',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.thuClose'
db.add_column('website_schedule', 'thuClose',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.satOpen'
db.add_column('website_schedule', 'satOpen',
self.gf('django.db.models.fields.TimeField')(null=True, blank=True),
keep_default=False)
# Adding field 'Schedule.dateValidEnd'
db.add_column('website_schedule', 'dateValidEnd',
self.gf('django.db.models.fields.DateField')(null=True, blank=True),
keep_default=False)
# Deleting field 'Schedule.valid_start'
db.delete_column('website_schedule', 'valid_start')
# Deleting field 'Schedule.valid_end'
db.delete_column('website_schedule', 'valid_end')
# Deleting field 'Schedule.mon_open'
db.delete_column('website_schedule', 'mon_open')
# Deleting field 'Schedule.mon_close'
db.delete_column('website_schedule', 'mon_close')
# Deleting field 'Schedule.tue_open'
db.delete_column('website_schedule', 'tue_open')
# Deleting field 'Schedule.tue_close'
db.delete_column('website_schedule', 'tue_close')
# Deleting field 'Schedule.wed_open'
db.delete_column('website_schedule', 'wed_open')
# Deleting field 'Schedule.wed_close'
db.delete_column('website_schedule', 'wed_close')
# Deleting field 'Schedule.thu_open'
db.delete_column('website_schedule', 'thu_open')
# Deleting field 'Schedule.thu_close'
db.delete_column('website_schedule', 'thu_close')
# Deleting field 'Schedule.fri_open'
db.delete_column('website_schedule', 'fri_open')
# Deleting field 'Schedule.fri_close'
db.delete_column('website_schedule', 'fri_close')
# Deleting field 'Schedule.sat_open'
db.delete_column('website_schedule', 'sat_open')
# Deleting field 'Schedule.sat_close'
db.delete_column('website_schedule', 'sat_close')
# Deleting field 'Schedule.sun_open'
db.delete_column('website_schedule', 'sun_open')
# Deleting field 'Schedule.sun_close'
db.delete_column('website_schedule', 'sun_close')
# Adding field 'Restaurant.mainSchedule'
db.add_column('website_restaurant', 'mainSchedule',
self.gf('django.db.models.fields.related.ForeignKey')(default=0, related_name='restaurant_main', to=orm['website.Schedule']),
keep_default=False)
# Deleting field 'Restaurant.main_schedule'
db.delete_column('website_restaurant', 'main_schedule_id')
# Adding M2M table for field specialSchedules on 'Restaurant'
db.create_table('website_restaurant_specialSchedules', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('restaurant', models.ForeignKey(orm['website.restaurant'], null=False)),
('schedule', models.ForeignKey(orm['website.schedule'], null=False))
))
db.create_unique('website_restaurant_specialSchedules', ['restaurant_id', 'schedule_id'])
# Removing M2M table for field special_schedules on 'Restaurant'
db.delete_table('website_restaurant_special_schedules')
models = {
'website.restaurant': {
'Meta': {'object_name': 'Restaurant'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'main_schedule': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'restaurant_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': "'restaurant_special'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['website.Schedule']"})
},
'website.schedule': {
'Meta': {'object_name': 'Schedule'},
'fri_close': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'fri_open': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'mon_close': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'mon_open': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'sat_close': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'sat_open': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'sun_close': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'sun_open': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'thu_close': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'thu_open': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'tue_close': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'tue_open': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'valid_end': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'valid_start': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'wed_close': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
'wed_open': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['website']
\ No newline at end of file
......@@ -5,9 +5,9 @@ import datetime
class Restaurant(models.Model):
"""Represents a dining location on campus."""
name = models.CharField(max_length=100)
mainSchedule = models.ForeignKey('Schedule',
main_schedule = models.ForeignKey('Schedule',
related_name='restaurant_main')
specialSchedules = models.ManyToManyField('Schedule',
special_schedules = models.ManyToManyField('Schedule',
related_name='restaurant_special', null=True, blank=True)
def isOpen(self):
......@@ -18,15 +18,21 @@ class Restaurant(models.Model):
main default schedule.
"""
today = datetime.datetime.today()
for schedule in self.specialSchedules.all():
if schedule.dateValidStart <= today <= schedule.dateValidEnd:
if schedule.isOpenNow():
return True
if self.mainSchedule.isOpenNow():
today = datetime.datetime.today().date()
# Check special schedules first
for schedule in self.special_schedules.all():
# Special schedules must have valid_start and valid_end set
if schedule.valid_start and schedule.valid_end:
if schedule.valid_start <= today <= schedule.valid_end:
if schedule.isOpenNow():
return True
if self.main_schedule.isOpenNow():
return True
return False
def __unicode__(self):
return self.name
class Schedule(models.Model):
"""
......@@ -38,50 +44,42 @@ class Schedule(models.Model):
"""
name = models.CharField(max_length=100)
# inclusive:
dateValidStart = models.DateField(null=True, blank=True)
dateValidEnd = models.DateField(null=True, blank=True)
monOpen = models.TimeField(null=True, blank=True)
monClose = models.TimeField(null=True, blank=True)
tueOpen = models.TimeField(null=True, blank=True)
tueClose = models.TimeField(null=True, blank=True)
wedOpen = models.TimeField(null=True, blank=True)
wedClose = models.TimeField(null=True, blank=True)
thuOpen = models.TimeField(null=True, blank=True)
thuClose = models.TimeField(null=True, blank=True)
friOpen = models.TimeField(null=True, blank=True)
friClose = models.TimeField(null=True, blank=True)
satOpen = models.TimeField(null=True, blank=True)
satClose = models.TimeField(null=True, blank=True)
sunOpen = models.TimeField(null=True, blank=True)
sunClose = models.TimeField(null=True, blank=True)
valid_start = models.DateField(null=True, blank=True)
valid_end = models.DateField(null=True, blank=True)
mon_open = models.TimeField(null=True, blank=True)
mon_close = models.TimeField(null=True, blank=True)
tue_open = models.TimeField(null=True, blank=True)
tue_close = models.TimeField(null=True, blank=True)
wed_open = models.TimeField(null=True, blank=True)
wed_close = models.TimeField(null=True, blank=True)
thu_open = models.TimeField(null=True, blank=True)
thu_close = models.TimeField(null=True, blank=True)
fri_open = models.TimeField(null=True, blank=True)
fri_close = models.TimeField(null=True, blank=True)
sat_open = models.TimeField(null=True, blank=True)
sat_close = models.TimeField(null=True, blank=True)
sun_open = models.TimeField(null=True, blank=True)
sun_close = models.TimeField(null=True, blank=True)
def isOpenNow(self):
"""Return true if this schedule is open right now."""
today = datetime.datetime.today()
weekday = today.weekday()
if weekday == 0:
start = self.monOpen
end = self.monClose
elif weekday == 1:
start = self.tueOpen
end = self.tueClose
elif weekday == 2:
start = self.wedOpen
end = self.wedClose
elif weekday == 3:
start = self.thuOpen
end = self.thuClose
elif weekday == 4:
start = self.friOpen
end = self.friClose
elif weekday == 5:
start = self.satOpen
end = self.satClose
elif weekday == 6:
start = self.sunOpen
end = self.sunClose
days = [
(self.mon_open, self.mon_close),
(self.tue_open, self.tue_close),
(self.wed_open, self.wed_close),
(self.thu_open, self.thu_close),
(self.fri_open, self.fri_close),
(self.sat_open, self.sat_close),
(self.sun_open, self.sun_close),
]
start, end = days[weekday]
if (start is not None and end is not None and
start <= today.time() <= end):
return True
else:
return False
def __unicode__(self):
return self.name
from django.conf.urls import patterns, include, url
from django.conf.urls import patterns, url
urlpatterns = patterns('website.views',
url(r'^$', 'restaurant_grid', name = 'restaurant_grid'),
url(r'^$', 'restaurant_grid', name='restaurant_grid'),
)
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