From b2bb64080829cf946729bd1f13f30a782a42f366 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 30 Aug 2011 22:25:41 +0530 Subject: [PATCH] js to display similar features in feature admin page --- gazetteer/places/views.py | 17 +++++++++-- gazetteer/static/js/feature_admin.js | 20 +++++++++++++ .../admin/places/feature/change_form.html | 28 ++++++++++++++++++- 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/gazetteer/places/views.py b/gazetteer/places/views.py index 50bb061..8b599e4 100644 --- a/gazetteer/places/views.py +++ b/gazetteer/places/views.py @@ -25,7 +25,9 @@ def search_json(request): } return render_to_json_response(d) - +''' +This function will be removed. No need for this page. +''' def search_related(request): id = request.GET.get("id", "0") feature = get_object_or_404(Feature, pk=id) @@ -47,5 +49,16 @@ def search_related(request): def search_related_json(request): - d = {} + id = request.GET.get("id", "0") + feature = get_object_or_404(Feature, pk=id) + similar_features = feature.similar_features() + d = [] + for s in similar_features: + d.append({ + 'id': s.id, + 'feature_type': FeatureType.objects.get(pk=s.feature_type_id).name, + 'preferred_name': s.preferred_name, + 'similarity': s.similarity, + 'distance': s.distance + }) return render_to_json_response(d) diff --git a/gazetteer/static/js/feature_admin.js b/gazetteer/static/js/feature_admin.js index e69de29..5afbd8e 100644 --- a/gazetteer/static/js/feature_admin.js +++ b/gazetteer/static/js/feature_admin.js @@ -0,0 +1,20 @@ +$(function() { + $.getJSON("/search_related_json", { + 'id': FEATURE_ID + }, function(data) { + for (var i=0; i'); + var $one = $('').appendTo($tr); + var $a = $('').attr("target", "_blank").attr("href", "/admin/places/feature/" + d.id).text(d.preferred_name).appendTo($one); + $('').text(d.feature_type).appendTo($tr); + $('').text(d.similarity).appendTo($tr); + $('').text(d.distance).appendTo($tr); + return $tr; +} diff --git a/gazetteer/templates/admin/places/feature/change_form.html b/gazetteer/templates/admin/places/feature/change_form.html index 57856e8..ee7b01c 100644 --- a/gazetteer/templates/admin/places/feature/change_form.html +++ b/gazetteer/templates/admin/places/feature/change_form.html @@ -8,10 +8,36 @@ + {% endblock %} {% block after_related_objects %}
- TEST +
Similar Features:
+ + + + + + + + + + + + + +
+ Name + + Feature Type + + Similarity + + Distance +
+
{% endblock %}