Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Nicholas J Anderson
whats-open
Commits
e8115733
Commit
e8115733
authored
Feb 01, 2014
by
Renfred Harper
Browse files
Change “restaurant” model variables to “facility”
parent
ac6f7981
Changes
13
Show whitespace changes
Inline
Side-by-side
templates/
restaurant
_grid.html
→
templates/
facility
_grid.html
View file @
e8115733
File moved
templates/location_grid.html
View file @
e8115733
{% extends 'layout/base.html' %}
<!-- Grid with
restaurant
s sorted by location -->
<!-- Grid with
facility
s 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
restaurant
s.
There aren't any
facilitie
s.
{% endfor %}
</div>
...
...
website/admin.py
View file @
e8115733
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
)
website/api.py
View file @
e8115733
from
website.models
import
Restaurant
from
website.models
import
Facility
import
re
def
export_data
():
restaurant
s
=
list
()
facilitie
s
=
list
()
# Sort the
restaurant
s by alphabetical order ignoring "the" and "a"
alphalist
=
sorted
(
Restaurant
.
objects
.
all
(),
# Sort the
facilitie
s 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
restaurant
s
facility
_data
[
'special_schedules'
]
=
special_schedules
facilities
.
append
(
facility
_data
)
return
facilitie
s
website/migrations/0001_initial.py
View file @
e8115733
...
...
@@ -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'
]},
...
...
website/migrations/0002_auto__add_field_
restaurant
_location.py
→
website/migrations/0002_auto__add_field_
facility
_location.py
View file @
e8115733
...
...
@@ -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'
]},
...
...
website/models.py
View file @
e8115733
...
...
@@ -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
()
...
...
website/static/css/style.css
View file @
e8115733
...
...
@@ -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
;
...
...
website/static/js/grid.js
View file @
e8115733
var
restaurant
s
=
[];
var
facilitie
s
=
[];
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_
restaurant
s
(
filtered_
restaurant
s
)
{
var
open
=
$
.
grep
(
filtered_
restaurant
s
,
function
sort_
facilitie
s
(
filtered_
facilitie
s
)
{
var
open
=
$
.
grep
(
filtered_
facilitie
s
,
function
(
r
,
idx
)
{
return
(
r
.
open
===
true
)
});
var
closed
=
$
.
grep
(
filtered_
restaurant
s
,
var
closed
=
$
.
grep
(
filtered_
facilitie
s
,
function
(
r
,
idx
)
{
return
(
r
.
open
===
false
)
});
return
$
.
merge
(
open
,
closed
);
}
function
construct_grid
(
filtered_
restaurant
s
)
{
function
construct_grid
(
filtered_
facilitie
s
)
{
$
(
'
#grid
'
).
empty
();
$
(
'
#grid
'
).
html
(
'
<div class="row"></div>
'
);
if
(
filtered_
restaurant
s
.
length
==
0
)
{
if
(
filtered_
facilitie
s
.
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_restaurant
s
(
filtered_
restaurant
s
);
$
.
each
(
sorted_
restaurant
s
,
function
(
idx
,
restaurant
)
{
sorted_
facilities
=
sort_facilitie
s
(
filtered_
facilitie
s
);
$
.
each
(
sorted_
facilitie
s
,
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
restaurant
s can be labeled via location. If there text in square brackets
// Note that identical
facilitie
s 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
(
restaurant
s
)
{
$
.
each
(
restaurant
s
,
function
(
idx
,
restaurant
)
{
function
update_grid
(
facilitie
s
)
{
$
.
each
(
facilitie
s
,
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
restaurant
s that are open, leave the rest closed.
// Open the
facilitie
s 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
)
{
restaurant
s
=
data
.
data
;
update_grid
(
restaurant
s
);
construct_grid
(
restaurant
s
);
facilitie
s
=
data
.
data
;
update_grid
(
facilitie
s
);
construct_grid
(
facilitie
s
);
// 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
(
restaurant
s
);
construct_grid
(
restaurant
s
);
update_grid
(
facilitie
s
);
construct_grid
(
facilitie
s
);
last_updated
=
new
Date
();
}
},
1000
);
...
...
website/static/js/info.js
View file @
e8115733
...
...
@@ -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
(
restaurant
s
,
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
(
facilitie
s
,
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
)
...
...
website/static/js/typeAhead.js
View file @
e8115733
$
.
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
(
restaurant
s
,
function
(
r
,
idx
)
{
filtered
=
$
.
grep
(
facilitie
s
,
function
(
r
,
idx
)
{
return
(
$
.
inArray
(
r
.
name
,
results
)
!=
-
1
);
});
construct_grid
(
filtered
);
...
...
website/urls.py
View file @
e8115733
...
...
@@ -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'
),
)
website/views.py
View file @
e8115733
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
restaurant
s in a grid. Main page."""
def
facility
_grid
(
request
):
"""Display the
facilitie
s 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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment