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
5d880c96
Commit
5d880c96
authored
Oct 22, 2012
by
Tyler Hallada
Browse files
Alphabetically sorting the restaurant names.
parent
60701553
Changes
1
Hide whitespace changes
Inline
Side-by-side
website/views.py
View file @
5d880c96
from
website.models
import
Restaurant
from
django.shortcuts
import
render_to_response
import
re
def
restaurant_grid
(
request
):
...
...
@@ -9,6 +10,10 @@ def restaurant_grid(request):
# Display the grid by location (instead of listing alphabetically)
pass
# Not implemented yet
restaurants
=
Restaurant
.
objects
.
all
()
# Sort the restaurants by alphabetical order ignoring "the" and "a"
restaurants
=
sorted
(
restaurants
,
key
=
lambda
r
:
re
.
sub
(
'^(the|a) '
,
''
,
r
.
name
,
count
=
1
,
flags
=
re
.
IGNORECASE
))
# Restaurants in lists of 4 to easily create rows in template
restRows
=
[
restaurants
[
x
:
x
+
4
]
for
x
in
xrange
(
0
,
len
(
restaurants
),
4
)]
return
render_to_response
(
'restaurant_grid.html'
,
{
'restRows'
:
restRows
,
...
...
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