Commit e8115733 authored by Renfred Harper's avatar Renfred Harper
Browse files

Change “restaurant” model variables to “facility”

parent ac6f7981
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
<!-- Grid with restaurants sorted by location --> <!-- Grid with facilitys sorted by location -->
<!-- New revisions pending major revisions (whoo JavaScript!) by Tyler --> <!-- New revisions pending major revisions (whoo JavaScript!) by Tyler -->
{% block content %} {% block content %}
...@@ -8,14 +8,14 @@ ...@@ -8,14 +8,14 @@
<div id="grid"> <div id="grid">
{% for list in restRows %} {% for list in restRows %}
<div class = "row"> <div class = "row">
{% for restaurant in list %} {% for facility in list %}
<div class = "span3 {% if restaurant.isOpen %}open{% else %}closed{% endif %}"> <div class = "span3 {% if facility.isOpen %}open{% else %}closed{% endif %}">
{{ restaurant.name }} {{ facility.name }}
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{% empty %} {% empty %}
There aren't any restaurants. There aren't any facilities.
{% endfor %} {% endfor %}
</div> </div>
......
from django.contrib import admin from django.contrib import admin
from website.models import Restaurant, Schedule, OpenTime from website.models import Facility, Schedule, OpenTime
class OpenTimeInline(admin.TabularInline): class OpenTimeInline(admin.TabularInline):
...@@ -11,5 +11,5 @@ class ScheduleAdmin(admin.ModelAdmin): ...@@ -11,5 +11,5 @@ class ScheduleAdmin(admin.ModelAdmin):
inlines = [OpenTimeInline, ] inlines = [OpenTimeInline, ]
admin.site.register(Restaurant) admin.site.register(Facility)
admin.site.register(Schedule, ScheduleAdmin) admin.site.register(Schedule, ScheduleAdmin)
from website.models import Restaurant from website.models import Facility
import re import re
def export_data(): def export_data():
restaurants = list() facilities = list()
# Sort the restaurants by alphabetical order ignoring "the" and "a" # Sort the facilities by alphabetical order ignoring "the" and "a"
alphalist = sorted(Restaurant.objects.all(), alphalist = sorted(Facility.objects.all(),
key=lambda r: re.sub('^(the|a) ', '', r.name, count=1, key=lambda r: re.sub('^(the|a) ', '', r.name, count=1,
flags=re.IGNORECASE)) flags=re.IGNORECASE))
for restaurant in alphalist: for facility in alphalist:
restaurant_data = { facility_data = {
'name': restaurant.name, 'name': facility.name,
'location': restaurant.location, 'location': facility.location,
'id': restaurant.id 'id': facility.id
} }
open_times = list() open_times = list()
# Sort open times by their start day and time # Sort open times by their start day and time
sorted_times = sorted(restaurant.main_schedule.open_times.all(), sorted_times = sorted(facility.main_schedule.open_times.all(),
key=lambda t: (t.start_day, t.start_time, t.end_time)) key=lambda t: (t.start_day, t.start_time, t.end_time))
for time in sorted_times: for time in sorted_times:
open_times.append({ open_times.append({
...@@ -26,12 +26,12 @@ def export_data(): ...@@ -26,12 +26,12 @@ def export_data():
'end_day': time.end_day, 'end_day': time.end_day,
'end_time': time.end_time.isoformat() 'end_time': time.end_time.isoformat()
}) })
restaurant_data['main_schedule'] = { facility_data['main_schedule'] = {
'name': restaurant.main_schedule.name, 'name': facility.main_schedule.name,
'open_times': open_times 'open_times': open_times
} }
special_schedules = list() special_schedules = list()
for schedule in restaurant.special_schedules.all(): for schedule in facility.special_schedules.all():
open_times = list() open_times = list()
sorted_times = sorted(schedule.open_times.all(), sorted_times = sorted(schedule.open_times.all(),
key=lambda t: (t.start_day, t.start_time, t.end_time)) key=lambda t: (t.start_day, t.start_time, t.end_time))
...@@ -48,6 +48,6 @@ def export_data(): ...@@ -48,6 +48,6 @@ def export_data():
'end': schedule.valid_end.isoformat(), 'end': schedule.valid_end.isoformat(),
'open_times': open_times 'open_times': open_times
}) })
restaurant_data['special_schedules'] = special_schedules facility_data['special_schedules'] = special_schedules
restaurants.append(restaurant_data) facilities.append(facility_data)
return restaurants return facilities
...@@ -15,21 +15,21 @@ class Migration(SchemaMigration): ...@@ -15,21 +15,21 @@ class Migration(SchemaMigration):
)) ))
db.send_create_signal('website', ['BaseModel']) db.send_create_signal('website', ['BaseModel'])
# Adding model 'Restaurant' # Adding model 'Facility'
db.create_table('website_restaurant', ( db.create_table('website_facility', (
('basemodel_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['website.BaseModel'], unique=True, primary_key=True)), ('basemodel_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['website.BaseModel'], unique=True, primary_key=True)),
('name', self.gf('django.db.models.fields.CharField')(max_length=100)), ('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
('main_schedule', self.gf('django.db.models.fields.related.ForeignKey')(related_name='restaurant_main', to=orm['website.Schedule'])), ('main_schedule', self.gf('django.db.models.fields.related.ForeignKey')(related_name='facility_main', to=orm['website.Schedule'])),
)) ))
db.send_create_signal('website', ['Restaurant']) db.send_create_signal('website', ['Facility'])
# Adding M2M table for field special_schedules on 'Restaurant' # Adding M2M table for field special_schedules on 'Facility'
db.create_table('website_restaurant_special_schedules', ( db.create_table('website_facility_special_schedules', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('restaurant', models.ForeignKey(orm['website.restaurant'], null=False)), ('facility', models.ForeignKey(orm['website.facility'], null=False)),
('schedule', models.ForeignKey(orm['website.schedule'], null=False)) ('schedule', models.ForeignKey(orm['website.schedule'], null=False))
)) ))
db.create_unique('website_restaurant_special_schedules', ['restaurant_id', 'schedule_id']) db.create_unique('website_facility_special_schedules', ['facility_id', 'schedule_id'])
# Adding model 'Schedule' # Adding model 'Schedule'
db.create_table('website_schedule', ( db.create_table('website_schedule', (
...@@ -56,11 +56,11 @@ class Migration(SchemaMigration): ...@@ -56,11 +56,11 @@ class Migration(SchemaMigration):
# Deleting model 'BaseModel' # Deleting model 'BaseModel'
db.delete_table('website_basemodel') db.delete_table('website_basemodel')
# Deleting model 'Restaurant' # Deleting model 'Facility'
db.delete_table('website_restaurant') db.delete_table('website_facility')
# Removing M2M table for field special_schedules on 'Restaurant' # Removing M2M table for field special_schedules on 'Facility'
db.delete_table('website_restaurant_special_schedules') db.delete_table('website_facility_special_schedules')
# Deleting model 'Schedule' # Deleting model 'Schedule'
db.delete_table('website_schedule') db.delete_table('website_schedule')
...@@ -84,12 +84,12 @@ class Migration(SchemaMigration): ...@@ -84,12 +84,12 @@ class Migration(SchemaMigration):
'start_day': ('django.db.models.fields.IntegerField', [], {}), 'start_day': ('django.db.models.fields.IntegerField', [], {}),
'start_time': ('django.db.models.fields.TimeField', [], {}) 'start_time': ('django.db.models.fields.TimeField', [], {})
}, },
'website.restaurant': { 'website.facility': {
'Meta': {'object_name': 'Restaurant', '_ormbases': ['website.BaseModel']}, 'Meta': {'object_name': 'Facility', '_ormbases': ['website.BaseModel']},
'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['website.BaseModel']", 'unique': 'True', 'primary_key': 'True'}), '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': "'restaurant_main'", 'to': "orm['website.Schedule']"}), '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'}), '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']"}) 'special_schedules': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'facility_special'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['website.Schedule']"})
}, },
'website.schedule': { 'website.schedule': {
'Meta': {'object_name': 'Schedule', '_ormbases': ['website.BaseModel']}, 'Meta': {'object_name': 'Schedule', '_ormbases': ['website.BaseModel']},
...@@ -100,4 +100,4 @@ class Migration(SchemaMigration): ...@@ -100,4 +100,4 @@ class Migration(SchemaMigration):
} }
} }
complete_apps = ['website'] complete_apps = ['website']
\ No newline at end of file
...@@ -8,15 +8,15 @@ from django.db import models ...@@ -8,15 +8,15 @@ from django.db import models
class Migration(SchemaMigration): class Migration(SchemaMigration):
def forwards(self, orm): def forwards(self, orm):
# Adding field 'Restaurant.location' # Adding field 'Facility.location'
db.add_column(u'website_restaurant', 'location', db.add_column(u'website_facility', 'location',
self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True), self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True),
keep_default=False) keep_default=False)
def backwards(self, orm): def backwards(self, orm):
# Deleting field 'Restaurant.location' # Deleting field 'Facility.location'
db.delete_column(u'website_restaurant', 'location') db.delete_column(u'website_facility', 'location')
models = { models = {
...@@ -34,13 +34,13 @@ class Migration(SchemaMigration): ...@@ -34,13 +34,13 @@ class Migration(SchemaMigration):
'start_day': ('django.db.models.fields.IntegerField', [], {}), 'start_day': ('django.db.models.fields.IntegerField', [], {}),
'start_time': ('django.db.models.fields.TimeField', [], {}) 'start_time': ('django.db.models.fields.TimeField', [], {})
}, },
u'website.restaurant': { u'website.facility': {
'Meta': {'object_name': 'Restaurant', '_ormbases': [u'website.BaseModel']}, 'Meta': {'object_name': 'Facility', '_ormbases': [u'website.BaseModel']},
u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['website.BaseModel']", 'unique': 'True', 'primary_key': 'True'}), u'basemodel_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['website.BaseModel']", 'unique': 'True', 'primary_key': 'True'}),
'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'main_schedule': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'restaurant_main'", 'to': u"orm['website.Schedule']"}), 'main_schedule': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'facility_main'", 'to': u"orm['website.Schedule']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), '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': u"orm['website.Schedule']"}) '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.schedule': { u'website.schedule': {
'Meta': {'object_name': 'Schedule', '_ormbases': [u'website.BaseModel']}, 'Meta': {'object_name': 'Schedule', '_ormbases': [u'website.BaseModel']},
...@@ -51,4 +51,4 @@ class Migration(SchemaMigration): ...@@ -51,4 +51,4 @@ class Migration(SchemaMigration):
} }
} }
complete_apps = ['website'] complete_apps = ['website']
\ No newline at end of file
...@@ -6,22 +6,24 @@ class BaseModel(models.Model): ...@@ -6,22 +6,24 @@ class BaseModel(models.Model):
last_modified = models.DateTimeField('Last Modified', auto_now=True) last_modified = models.DateTimeField('Last Modified', auto_now=True)
class Restaurant(BaseModel): class Facility(BaseModel):
"""Represents a dining location on campus.""" """Represents a dining location on campus."""
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
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',
related_name='restaurant_main') related_name='facility_main')
special_schedules = models.ManyToManyField('Schedule', special_schedules = models.ManyToManyField('Schedule',
related_name='restaurant_special', null=True, blank=True) related_name='facility_special', null=True, blank=True)
class Meta: class Meta:
verbose_name = "facility"
verbose_name_plural = "facilities"
# Sort by name in admin view # Sort by name in admin view
ordering = ['name'] ordering = ['name']
def isOpen(self): def isOpen(self):
""" """
Return true if this restaurant is currently open. Return true if this facility is currently open.
First checks any valid special schedules and then checks the First checks any valid special schedules and then checks the
main default schedule. main default schedule.
...@@ -75,7 +77,7 @@ class Schedule(BaseModel): ...@@ -75,7 +77,7 @@ class Schedule(BaseModel):
class OpenTime(BaseModel): class OpenTime(BaseModel):
"""Represents a period time when a Restaurant is open""" """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_day = models.IntegerField() # 0-6, Monday == 0
start_time = models.TimeField() start_time = models.TimeField()
......
...@@ -64,7 +64,7 @@ body { ...@@ -64,7 +64,7 @@ body {
margin-bottom: 10px; margin-bottom: 10px;
cursor: pointer; cursor: pointer;
} }
.grid-box .restaurant{ .grid-box .facility{
text-align:center; text-align:center;
background-color: white; background-color: white;
padding: 10px 2px; padding: 10px 2px;
...@@ -77,14 +77,14 @@ body { ...@@ -77,14 +77,14 @@ body {
.opened{ .opened{
color:#141414; color:#141414;
} }
.restaurant.closing{ .facility.closing{
color: #FFCC33; color: #FFCC33;
} }
.restaurant.closed{ .facility.closed{
color: rgba(81,81,81,0.9); color: rgba(81,81,81,0.9);
background-color: rgba(255,255,255,0.65); background-color: rgba(255,255,255,0.65);
} }
.restaurant .building{ .facility .building{
font-size: 15px; font-size: 15px;
padding-left: 2px; padding-left: 2px;
......
var restaurants = []; var facilities = [];
function correct_grid_overflow(){ function correct_grid_overflow(){
// This function ensures that all text inside the grid-boxes display nicely on one line. // This function ensures that all text inside the grid-boxes display nicely on one line.
$('.restaurant').css('font-size', '').css('overflow-y', 'scroll'); $('.facility').css('font-size', '').css('overflow-y', 'scroll');
$('.restaurant').each(function() { $('.facility').each(function() {
// Overflow is detected if the height of the box is less than // Overflow is detected if the height of the box is less than
// the clipped scroll height of the box. // the clipped scroll height of the box.
while ($(this).height() > 0 && $(this).outerHeight() < $(this)[0].scrollHeight) { while ($(this).height() > 0 && $(this).outerHeight() < $(this)[0].scrollHeight) {
...@@ -15,38 +15,38 @@ function correct_grid_overflow(){ ...@@ -15,38 +15,38 @@ function correct_grid_overflow(){
$(this).css('padding-top', 31 - newSize + 'px'); $(this).css('padding-top', 31 - newSize + 'px');
} }
}); });
$('.restaurant').css('overflow-y', ''); $('.facility').css('overflow-y', '');
} }
function sort_restaurants(filtered_restaurants) { function sort_facilities(filtered_facilities) {
var open = $.grep(filtered_restaurants, var open = $.grep(filtered_facilities,
function (r, idx) { return (r.open === true) }); function (r, idx) { return (r.open === true) });
var closed = $.grep(filtered_restaurants, var closed = $.grep(filtered_facilities,
function (r, idx) { return (r.open === false) }); function (r, idx) { return (r.open === false) });
return $.merge(open, closed); return $.merge(open, closed);
} }
function construct_grid(filtered_restaurants) { function construct_grid(filtered_facilities) {
$('#grid').empty(); $('#grid').empty();
$('#grid').html('<div class="row"></div>'); $('#grid').html('<div class="row"></div>');
if (filtered_restaurants.length == 0) { if (filtered_facilities.length == 0) {
$('#grid').append('<span class="col-md-8 offset2 grid-box" id="no-results">No results found.</span>'); $('#grid').append('<span class="col-md-8 offset2 grid-box" id="no-results">No results found.</span>');
$('#grid').show(); $('#grid').show();
return; return;
} }
sorted_restaurants = sort_restaurants(filtered_restaurants); sorted_facilities = sort_facilities(filtered_facilities);
$.each(sorted_restaurants, function (idx, restaurant) { $.each(sorted_facilities, function (idx, facility) {
var open_class = 'closed'; var open_class = 'closed';
if (restaurant.open) { if (facility.open) {
open_class = 'opened'; open_class = 'opened';
} }
// Append the data into the grid scaffolding. // Append the data into the grid scaffolding.
// Note that identical restaurants can be labeled via location. If there text in square brackets // Note that identical facilities can be labeled via location. If there text in square brackets
// next to a restuarant name, the text will be formatted as next to it. // next to a restuarant name, the text will be formatted as next to it.
$('#grid .row').append( $('#grid .row').append(
'<div class="col-sm-6 col-md-4 col-lg-3 grid-box" id="' + restaurant.id + '">\ '<div class="col-sm-6 col-md-4 col-lg-3 grid-box" id="' + facility.id + '">\
<div class="restaurant ' + open_class + '">' + <div class="facility ' + open_class + '">' +
restaurant.name.replace(/ ?\[(.+)\]/, '<span class="building"> ($1)</span>') + facility.name.replace(/ ?\[(.+)\]/, '<span class="building"> ($1)</span>') +
'</div>\ '</div>\
</div>' </div>'
); );
...@@ -55,8 +55,8 @@ function construct_grid(filtered_restaurants) { ...@@ -55,8 +55,8 @@ function construct_grid(filtered_restaurants) {
correct_grid_overflow(); correct_grid_overflow();
} }
function update_grid(restaurants) { function update_grid(facilities) {
$.each(restaurants, function (idx, restaurant) { $.each(facilities, function (idx, facility) {
var now = new Date(); var now = new Date();
var endDate = new Date().setHours(5,0,0,0); var endDate = new Date().setHours(5,0,0,0);
// JavaScript sets 0 to Sunday instead of Monday // JavaScript sets 0 to Sunday instead of Monday
...@@ -66,7 +66,7 @@ function update_grid(restaurants) { ...@@ -66,7 +66,7 @@ function update_grid(restaurants) {
} }
var schedule = undefined; var schedule = undefined;
// If there exists a valid special schedule choose it. // If there exists a valid special schedule choose it.
$.each(restaurant.special_schedules, function (idx, special) { $.each(facility.special_schedules, function (idx, special) {
// Special schedules take effect after 5am on their start day // Special schedules take effect after 5am on their start day
// to prevent collisions with the previous night's schedule, // to prevent collisions with the previous night's schedule,
// and they end at 5am the day after their end date. // and they end at 5am the day after their end date.
...@@ -79,13 +79,13 @@ function update_grid(restaurants) { ...@@ -79,13 +79,13 @@ function update_grid(restaurants) {
}); });
// If there was no special schedule, then use main_schedule. // If there was no special schedule, then use main_schedule.
if (schedule === undefined) { if (schedule === undefined) {
schedule = restaurant.main_schedule; schedule = facility.main_schedule;
} }
// Open the restaurants that are open, leave the rest closed. // Open the facilities that are open, leave the rest closed.
if (schedule.open_times.length === 0) { if (schedule.open_times.length === 0) {
restaurant.open = false; facility.open = false;
} }
restaurant.current_schedule = schedule; facility.current_schedule = schedule;
$.each(schedule.open_times, function (idx, time) { $.each(schedule.open_times, function (idx, time) {
var start_day = time.start_day; var start_day = time.start_day;
var end_day = time.end_day; var end_day = time.end_day;
...@@ -95,13 +95,13 @@ function update_grid(restaurants) { ...@@ -95,13 +95,13 @@ function update_grid(restaurants) {
if (now >= Date.parse(time.start_time)) { if (now >= Date.parse(time.start_time)) {
if (day === end_day) { if (day === end_day) {
if (now <= Date.parse(time.end_time)) { if (now <= Date.parse(time.end_time)) {
restaurant.open = true; facility.open = true;
restaurant.current_time = time; facility.current_time = time;
return false; return false;
} }
} else { } else {
restaurant.open = true; facility.open = true;
restaurant.current_time = time; facility.current_time = time;
return false; return false;
} }
...@@ -110,30 +110,30 @@ function update_grid(restaurants) { ...@@ -110,30 +110,30 @@ function update_grid(restaurants) {
if (now <= Date.parse(time.end_time)) { if (now <= Date.parse(time.end_time)) {
if (day === start_day) { if (day === start_day) {
if (now >= Date.parse(time.start_time)) { if (now >= Date.parse(time.start_time)) {
restaurant.open = true; facility.open = true;
restaurant.current_time = time; facility.current_time = time;
return false; return false;
} }
} else { } else {
restaurant.open = true; facility.open = true;
restaurant.current_time = time; facility.current_time = time;
return false; return false;
} }
} }
} else if (start_day < end_day) { } else if (start_day < end_day) {
if (day > start_day && day < end_day) { if (day > start_day && day < end_day) {
restaurant.open = true; facility.open = true;
restaurant.current_time = time; facility.current_time = time;
return false; return false;
} }
} else if (start_day > end_day) { } else if (start_day > end_day) {
if (day > start_day || day < end_day) { if (day > start_day || day < end_day) {
restaurant.open = true; facility.open = true;
restaurant.current_time = time; facility.current_time = time;
return false; return false;
} }
} }
restaurant.open = false;