From 2ef297873dae1cb6e0fe00089d05f39eed764701 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 31 Aug 2011 18:50:16 +0530 Subject: [PATCH 1/2] cleaner url for similar.json endpoint --- gazetteer/places/views.py | 8 ++++---- gazetteer/static/js/gazetteer.js | 14 +++++++++++++- .../admin/places/authorityrecord/change_form.html | 2 +- gazetteer/urls.py | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/gazetteer/places/views.py b/gazetteer/places/views.py index b97de58..b2f6b3a 100644 --- a/gazetteer/places/views.py +++ b/gazetteer/places/views.py @@ -1,6 +1,6 @@ # Create your views here. from django.shortcuts import render_to_response, get_object_or_404 -from ox.django.shortcuts import render_to_json_response +from ox.django.shortcuts import render_to_json_response, get_object_or_404_json from django.template import RequestContext from models import Feature, FeatureType, AuthorityRecord from django.core.paginator import Paginator, InvalidPage, EmptyPage @@ -79,9 +79,9 @@ def search_related(request): }) -def search_related_json(request): - id = request.GET.get("id", "0") - feature = get_object_or_404(Feature, pk=id) +def search_related_json(request, id): +# id = request.GET.get("id", "0") + feature = get_object_or_404_json(Feature, pk=id) similar_features = feature.similar_features() d = [] diff --git a/gazetteer/static/js/gazetteer.js b/gazetteer/static/js/gazetteer.js index a86f851..38be5b4 100644 --- a/gazetteer/static/js/gazetteer.js +++ b/gazetteer/static/js/gazetteer.js @@ -17,12 +17,24 @@ $(function() { var bbox = map.getExtent().toBBOX(); var search_term = $('#search').val(); $('#searchField').addClass("loading"); + $('#searchField').attr("disabled", "disabled"); $.getJSON("/feature/search.json", { 'bbox': bbox, 'q': search_term, 'srid': 3785, - 'threshold': 0.5 + 'threshold': 0.5, + 'count': 20 }, function(features) { + + if (features.hasOwnProperty("error") && features.error != '') { + alert(features.error); + return; + } + + $('#noOfResults').text(features.results); + $('#currPage').text(features.current_page); + $('#totalPages').text(features.pages); + $('#searchField').removeAttr("disabled"); $('#searchField').removeClass("loading"); $('#mapList tbody').empty(); // var headerRow = getHeaderRow(); diff --git a/gazetteer/templates/admin/places/authorityrecord/change_form.html b/gazetteer/templates/admin/places/authorityrecord/change_form.html index 8d9cd61..368607a 100644 --- a/gazetteer/templates/admin/places/authorityrecord/change_form.html +++ b/gazetteer/templates/admin/places/authorityrecord/change_form.html @@ -2,7 +2,7 @@ {% block extrahead %} {{ block.super }} - + diff --git a/gazetteer/urls.py b/gazetteer/urls.py index c4264c8..6d8c711 100644 --- a/gazetteer/urls.py +++ b/gazetteer/urls.py @@ -13,7 +13,7 @@ urlpatterns = patterns('', ('^search$', 'places.views.search'), ('^feature/search.json$', 'places.views.search_json'), ('^search_related$', 'places.views.search_related'), - ('^feature/search_related.json$', 'places.views.search_related_json'), + ('^feature/(?P[0-9]*)/similar.json$', 'places.views.search_related_json'), ('^auth_record.json$', 'places.views.auth_record_json'), # Uncomment the admin/doc line below to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), From b5083d178ce5e58d2c176164a5dc7386cda8eb32 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 31 Aug 2011 18:55:45 +0530 Subject: [PATCH 2/2] uh --- gazetteer/places/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gazetteer/places/views.py b/gazetteer/places/views.py index b2f6b3a..c08cf62 100644 --- a/gazetteer/places/views.py +++ b/gazetteer/places/views.py @@ -81,6 +81,7 @@ def search_related(request): def search_related_json(request, id): # id = request.GET.get("id", "0") + id = str(id) feature = get_object_or_404_json(Feature, pk=id) similar_features = feature.similar_features() d = []