Skip to content

Commit

Permalink
initial commit of web interface
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpenman committed Mar 27, 2015
0 parents commit dbe6c60
Show file tree
Hide file tree
Showing 353 changed files with 6,026 additions and 0 deletions.
1 change: 1 addition & 0 deletions __init__.py
@@ -0,0 +1 @@

29 changes: 29 additions & 0 deletions controllers/ajax.py
@@ -0,0 +1,29 @@
import re
import math


def search():
"""Results of AJAX search
"""
records = []
num_pages = 0
error = ''
search_term = request.vars.search_term
if search_term:
try:
page = int(request.vars.page or 0)
page_size = int(request.vars.page_size) or 10
except (ValueError, TypeError):
# passed arguments are invalid
error = 'Invalid parameters'
else:
try:
# 'like' not supported on GAE so manually compare strings
records = [dict(country=record.country, id=record.id, pretty_link=record.pretty_link) for record in places.search() if re.compile(search_term, flags=re.IGNORECASE).search(record.country)]
except re.error:
error = 'Invalid search term'
else:
num_pages = int(math.ceil(len(records) / float(page_size)))
records = records[page * page_size:(page + 1) * page_size]
return dict(records=records, num_pages=num_pages, error=error)

0 comments on commit dbe6c60

Please sign in to comment.