Commit e8115733 authored by Renfred Harper's avatar Renfred Harper

Change “restaurant” model variables to “facility”

parent ac6f7981
{% 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 -->
{% block content %}
......@@ -8,14 +8,14 @@
<div id="grid">
{% for list in restRows %}
<div class = "row">
{% for restaurant in list %}
<div class = "span3 {% if restaurant.isOpen %}open{% else %}closed{% endif %}">
{{ restaurant.name }}
{% for facility in list %}
<div class = "span3 {% if facility.isOpen %}open{% else %}closed{% endif %}">
{{ facility.name }}
</div>
{% endfor %}
</div>
{% empty %}
There aren't any restaurants.
There aren't any facilities.
{% endfor %}
</div>
......
from django.contrib import admin
from website.models import Restaurant, Schedule, OpenTime
from website.models import Facility, Schedule, OpenTime
class OpenTimeInline(admin.TabularInline):
......@@ -11,5 +11,5 @@ class ScheduleAdmin(admin.ModelAdmin):
inlines = [OpenTimeInline, ]
admin.site.register(Restaurant)
admin.site.register(Facility)
admin.site.register(Schedule, ScheduleAdmin)
from website.models import Restaurant
from website.models import Facility
import re
def export_data():
restaurants = list()
facilities = list()
# Sort the restaurants by alphabetical order ignoring "the" and "a"
alphalist = sorted(Restaurant.objects.all(),
# Sort the facilities by alphabetical order ignoring "the" and "a"
alphalist = sorted(Facility.objects.all(),
key=lambda r: re.sub('^(the|a) ', '', r.name, count=1,
flags=re.IGNORECASE))
for restaurant in alphalist:
restaurant_data = {
'name': restaurant.name,
'location': restaurant.location,
'id': restaurant.id
for facility in alphalist:
facility_data = {
'name': facility.name,
'location': facility.location,
'id': facility.id
}
open_times = list()
# 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))
for time in sorted_times:
open_times.append({
......@@ -26,12 +26,12 @@ def export_data():
'end_day': time.end_day,
'end_time': time.end_time.isoformat()
})
restaurant_data['main_schedule'] = {
'name': restaurant.main_schedule.name,
facility_data['main_schedule'] = {
'name': facility.main_schedule.name,
'open_times': open_times
}
special_schedules = list()
for schedule in restaurant.special_schedules.all():
for schedule in facility.special_schedules.all():
open_times = list()
sorted_times = sorted(schedule.open_times.all(),
key=lambda t: (t.start_day, t.start_time, t.end_time))
......@@ -48,6 +48,6 @@ def export_data():
'end': schedule.valid_end.isoformat(),
'open_times': open_times
})
restaurant_data['special_schedules'] = special_schedules
restaurants.append(restaurant_data)
return restaurants
facility_data['special_schedules'] = special_schedules
facilities.append(facility_data)
return facilities
......@@ -15,21 +15,21 @@ class Migration(SchemaMigration):
))
db.send_create_signal('website', ['BaseModel'])
# Adding model 'Restaurant'
db.create_table('website_restaurant', (
# 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)),
('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'
db.create_table('website_restaurant_special_schedules', (
# Adding M2M table for field special_schedules on 'Facility'
db.create_table('website_facility_special_schedules', (
('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))
))
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'
db.create_table('website_schedule', (
......@@ -56,11 +56,11 @@ class Migration(SchemaMigration):
# Deleting model 'BaseModel'
db.delete_table('website_basemodel')
# Deleting model 'Restaurant'
db.delete_table('website_restaurant')
# Deleting model 'Facility'
db.delete_table('website_facility')
# Removing M2M table for field special_schedules on 'Restaurant'
db.delete_table('website_restaurant_special_schedules')
# Removing M2M table for field special_schedules on 'Facility'
db.delete_table('website_facility_special_schedules')
# Deleting model 'Schedule'
db.delete_table('website_schedule')
......@@ -84,12 +84,12 @@ class Migration(SchemaMigration):
'start_day': ('django.db.models.fields.IntegerField', [], {}),
'start_time': ('django.db.models.fields.TimeField', [], {})
},
'website.restaurant': {
'Meta': {'object_name': 'Restaurant', '_ormbases': ['website.BaseModel']},
'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': "'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'}),
'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': {
'Meta': {'object_name': 'Schedule', '_ormbases': ['website.BaseModel']},
......@@ -100,4 +100,4 @@ class Migration(SchemaMigration):
}
}
complete_apps = ['website']
\ No newline at end of file
complete_apps = ['website']
......@@ -8,15 +8,15 @@ from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'Restaurant.location'
db.add_column(u'website_restaurant', 'location',
# Adding field 'Facility.location'
db.add_column(u'website_facility', 'location',
self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True),
keep_default=False)
def backwards(self, orm):
# Deleting field 'Restaurant.location'
db.delete_column(u'website_restaurant', 'location')
# Deleting field 'Facility.location'
db.delete_column(u'website_facility', 'location')
models = {
......@@ -34,13 +34,13 @@ class Migration(SchemaMigration):
'start_day': ('django.db.models.fields.IntegerField', [], {}),
'start_time': ('django.db.models.fields.TimeField', [], {})
},
u'website.restaurant': {
'Meta': {'object_name': 'Restaurant', '_ormbases': [u'website.BaseModel']},
u'website.facility': {
'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'}),
'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'}),
'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': {
'Meta': {'object_name': 'Schedule', '_ormbases': [u'website.BaseModel']},
......@@ -51,4 +51,4 @@ class Migration(SchemaMigration):
}
}
complete_apps = ['website']
\ No newline at end of file
complete_apps = ['website']
......@@ -6,22 +6,24 @@ class BaseModel(models.Model):
last_modified = models.DateTimeField('Last Modified', auto_now=True)
class Restaurant(BaseModel):
class Facility(BaseModel):
"""Represents a dining location on campus."""
name = models.CharField(max_length=100)
location = models.CharField(max_length=100, null=True, blank=True)
main_schedule = models.ForeignKey('Schedule',
related_name='restaurant_main')
related_name='facility_main')
special_schedules = models.ManyToManyField('Schedule',
related_name='restaurant_special', null=True, blank=True)
related_name='facility_special', null=True, blank=True)
class Meta:
verbose_name = "facility"
verbose_name_plural = "facilities"
# Sort by name in admin view
ordering = ['name']
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
main default schedule.
......@@ -75,7 +77,7 @@ class Schedule(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')
start_day = models.IntegerField() # 0-6, Monday == 0
start_time = models.TimeField()
......
......@@ -64,7 +64,7 @@ body {
margin-bottom: 10px;
cursor: pointer;
}
.grid-box .restaurant{
.grid-box .facility{
text-align:center;
background-color: white;
padding: 10px 2px;
......@@ -77,14 +77,14 @@ body {
.opened{
color:#141414;
}
.restaurant.closing{
.facility.closing{
color: #FFCC33;
}
.restaurant.closed{
.facility.closed{
color: rgba(81,81,81,0.9);
background-color: rgba(255,255,255,0.65);
}
.restaurant .building{
.facility .building{
font-size: 15px;
padding-left: 2px;
......
var restaurants = [];
var facilities = [];
function correct_grid_overflow(){
// This function ensures that all text inside the grid-boxes display nicely on one line.
$('.restaurant').css('font-size', '').css('overflow-y', 'scroll');
$('.restaurant').each(function() {
$('.facility').css('font-size', '').css('overflow-y', 'scroll');
$('.facility').each(function() {
// Overflow is detected if the height of the box is less than
// the clipped scroll height of the box.
while ($(this).height() > 0 && $(this).outerHeight() < $(this)[0].scrollHeight) {
......@@ -15,38 +15,38 @@ function correct_grid_overflow(){
$(this).css('padding-top', 31 - newSize + 'px');
}
});
$('.restaurant').css('overflow-y', '');
$('.facility').css('overflow-y', '');
}
function sort_restaurants(filtered_restaurants) {
var open = $.grep(filtered_restaurants,
function sort_facilities(filtered_facilities) {
var open = $.grep(filtered_facilities,
function (r, idx) { return (r.open === true) });
var closed = $.grep(filtered_restaurants,
var closed = $.grep(filtered_facilities,
function (r, idx) { return (r.open === false) });
return $.merge(open, closed);
}
function construct_grid(filtered_restaurants) {
function construct_grid(filtered_facilities) {
$('#grid').empty();
$('#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').show();
return;
}
sorted_restaurants = sort_restaurants(filtered_restaurants);
$.each(sorted_restaurants, function (idx, restaurant) {
sorted_facilities = sort_facilities(filtered_facilities);
$.each(sorted_facilities, function (idx, facility) {
var open_class = 'closed';
if (restaurant.open) {
if (facility.open) {
open_class = 'opened';
}
// 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.
$('#grid .row').append(
'<div class="col-sm-6 col-md-4 col-lg-3 grid-box" id="' + restaurant.id + '">\
<div class="restaurant ' + open_class + '">' +
restaurant.name.replace(/ ?\[(.+)\]/, '<span class="building"> ($1)</span>') +
'<div class="col-sm-6 col-md-4 col-lg-3 grid-box" id="' + facility.id + '">\
<div class="facility ' + open_class + '">' +
facility.name.replace(/ ?\[(.+)\]/, '<span class="building"> ($1)</span>') +
'</div>\
</div>'
);
......@@ -55,8 +55,8 @@ function construct_grid(filtered_restaurants) {
correct_grid_overflow();
}
function update_grid(restaurants) {
$.each(restaurants, function (idx, restaurant) {
function update_grid(facilities) {
$.each(facilities, function (idx, facility) {
var now = new Date();
var endDate = new Date().setHours(5,0,0,0);
// JavaScript sets 0 to Sunday instead of Monday
......@@ -66,7 +66,7 @@ function update_grid(restaurants) {
}
var schedule = undefined;
// 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
// to prevent collisions with the previous night's schedule,
// and they end at 5am the day after their end date.
......@@ -79,13 +79,13 @@ function update_grid(restaurants) {
});
// If there was no special schedule, then use main_schedule.
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) {
restaurant.open = false;
facility.open = false;
}
restaurant.current_schedule = schedule;
facility.current_schedule = schedule;
$.each(schedule.open_times, function (idx, time) {
var start_day = time.start_day;
var end_day = time.end_day;
......@@ -95,13 +95,13 @@ function update_grid(restaurants) {
if (now >= Date.parse(time.start_time)) {
if (day === end_day) {
if (now <= Date.parse(time.end_time)) {
restaurant.open = true;
restaurant.current_time = time;
facility.open = true;
facility.current_time = time;
return false;
}
} else {
restaurant.open = true;
restaurant.current_time = time;
facility.open = true;
facility.current_time = time;
return false;
}
......@@ -110,30 +110,30 @@ function update_grid(restaurants) {
if (now <= Date.parse(time.end_time)) {
if (day === start_day) {
if (now >= Date.parse(time.start_time)) {
restaurant.open = true;
restaurant.current_time = time;
facility.open = true;
facility.current_time = time;
return false;
}
} else {
restaurant.open = true;
restaurant.current_time = time;
facility.open = true;
facility.current_time = time;
return false;
}
}
} else if (start_day < end_day) {
if (day > start_day && day < end_day) {
restaurant.open = true;
restaurant.current_time = time;
facility.open = true;
facility.current_time = time;
return false;
}
} else if (start_day > end_day) {
if (day > start_day || day < end_day) {
restaurant.open = true;
restaurant.current_time = time;
facility.open = true;
facility.current_time = time;
return false;
}
}
restaurant.open = false;
facility.open = false;
});
});
}
......@@ -141,9 +141,9 @@ function update_grid(restaurants) {
$.ajax({
url: '/ajax/schedule/',
}).done(function (data) {
restaurants = data.data;
update_grid(restaurants);
construct_grid(restaurants);
facilities = data.data;
update_grid(facilities);
construct_grid(facilities);
// Every second, check and see if it is necessary to update the grid.
var last_updated = new Date();
setInterval(function(){
......@@ -152,8 +152,8 @@ $.ajax({
// or it has been over a half hour (180000 milliseconds) since the last update.
if (last_updated.getHours() != now.getHours() ||
(last_updated.getMinutes() < 30 && now.getMinutes() >= 30) || now - last_updated > 1800000){
update_grid(restaurants);
construct_grid(restaurants);
update_grid(facilities);
construct_grid(facilities);
last_updated = new Date();
}
}, 1000);
......
......@@ -58,19 +58,19 @@ $.fn.displaySchedule = function(open_times){
}
}
function dispalyInfo(restaurant) {
// Display restaurant info in the info-body without bracketed locations
$('#info-name').text(restaurant.name.replace(/ ?\[(.+)\]/, ''));
if (restaurant.location == '') {
function dispalyInfo(facility) {
// Display facility info in the info-body without bracketed locations
$('#info-name').text(facility.name.replace(/ ?\[(.+)\]/, ''));
if (facility.location == '') {
$('#info-location').hide();
}
else {
$('#info-location').html('<b>Location:</b> ' + restaurant.location).show();
$('#info-location').html('<b>Location:</b> ' + facility.location).show();
}
if (restaurant.open){
if (facility.open){
$('#info-status').html('<b>Status:</b> Open');
var closing = Date.parse(restaurant.current_time.end_time);
// Print the time the restaurant closes in local format with the seconds removed via regex
var closing = Date.parse(facility.current_time.end_time);
// Print the time the facility closes in local format with the seconds removed via regex
$('#info-next').html('<b>Open Till:</b> ' + closing.toLocaleTimeString().replace(/(\d+:\d{2})(:\d+ )/, "$1 ")).show();
}
else {
......@@ -79,7 +79,7 @@ function dispalyInfo(restaurant) {
}
$('#info-schedule').empty();
// Display all open times for the main schedule
var open_times = restaurant.current_schedule.open_times;
var open_times = facility.current_schedule.open_times;
$('#info-schedule').displaySchedule(open_times);
}
......@@ -101,21 +101,21 @@ $(document).ready(function() {
$(this).slideUp(350);
}
});
// Displays more info about a restaurant on-click
// Displays more info about a facility on-click
$(document).on('click', '.grid-box', function() {
grid_id = $(this).attr('id');
// Keep track of the users vertical position so it can be scolled back
//to when the window is closed
position = $(window).scrollTop();
// Search though the restaurnts object to find the selected restaurant's info
var restaurant;
$.each(restaurants, function(idx, restaurant_i) {
if (restaurant_i.id == grid_id) {
restaurant = restaurant_i;
// Search though the restaurnts object to find the selected facility's info
var facility;
$.each(facilities, function(idx, facility_i) {
if (facility_i.id == grid_id) {
facility = facility_i;
return false;
}
});
dispalyInfo(restaurant);
dispalyInfo(facility);
// If the user clicks on the same box twice it will close the info menu
if (lastClicked == grid_id){
$('#info-body').slideToggle(300)
......@@ -138,4 +138,4 @@ $(document).ready(function() {
scrollTop: position
}, 350);
});
});
\ No newline at end of file
});
$.ajax({
url: '/ajax/schedule/',
}).done(function (data) {
//collecting list of restaurant names from server data
//collecting list of facility names from server data
var rest_names = [];
for (var i = 0; i < data.data.length; i++) {
......@@ -19,7 +19,7 @@ $.ajax({
response: function(event, ui) {
//ui.content array contains all names that are returned from the search
results = $.map(ui.content, function(r) { return r.value; });
filtered = $.grep(restaurants, function (r, idx) {
filtered = $.grep(facilities, function (r, idx) {
return ($.inArray(r.name, results) != -1);
});
construct_grid(filtered);
......
......@@ -2,5 +2,5 @@ from django.conf.urls import patterns, url
urlpatterns = patterns('website.views',
url(r'^(?:ajax|api)/schedule/', 'ajax_schedule_data', name='schedule_data'),
url(r'^$', 'restaurant_grid', name='restaurant_grid'),
url(r'^$', 'facility_grid', name='facility_grid'),
)
from django.template import RequestContext
from website.models import Restaurant, OpenTime, BaseModel
from website.models import Facility, OpenTime, BaseModel
from website.api import export_data
from django.shortcuts import render_to_response
from django.http import HttpResponse
......@@ -8,13 +8,13 @@ import hashlib
import json
def restaurant_grid(request):
"""Display the restaurants in a grid. Main page."""
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('restaurant_grid.html',
return render_to_response('facility_grid.html',
context_instance=RequestContext(request))
def gen_etag(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