add list of features in authority record admin; cleaner urls for json end-points

This commit is contained in:
Sanj 2011-08-30 22:56:53 +05:30
parent b2bb640808
commit 0ac0ca9236
6 changed files with 77 additions and 5 deletions

View File

@ -61,4 +61,16 @@ def search_related_json(request):
'similarity': s.similarity,
'distance': s.distance
})
return render_to_json_response(d)
return render_to_json_response(d)
def auth_record_json(request):
id = request.GET.get("id", "0")
auth_record = get_object_or_404(AuthorityRecord, pk=id)
features = [f.get_geojson() for f in auth_record.feature_set.all()]
d = {
'type': 'FeatureCollection',
'features': features
}
return render_to_json_response(d)

View File

@ -0,0 +1,30 @@
$(function() {
$.getJSON("/auth_record_json", {
'id': RECORD_ID
}, function(features) {
for (var i=0; i<features.features.length;i++) {
var f = features.features[i];
var props = f.properties;
var listItem = getRow(props);
$('#mapList tbody').append(listItem);
}
});
});
/*
function copied over from gazetteer.js. TODO:resolve to DRY.
*/
function getRow(props) {
var $tr = $('<tr />');
var $one = $('<td />').appendTo($tr);
var $a = $('<a />').attr("target", "_blank").attr("href", "/admin/places/feature/" + props.id).text(props.preferred_name + " ").appendTo($one);
var $a2 = $('<a />').addClass("viewSimilar").attr("target", "_blank").attr("href", "/search_related?id=" + props.id).text("view similar").appendTo($one);
$('<td />').text(props.feature_type).appendTo($tr);
$('<td />').text(props.admin2).appendTo($tr);
$('<td />').text(props.admin1).appendTo($tr);
return $tr;
}

View File

@ -1,5 +1,5 @@
$(function() {
$.getJSON("/search_related_json", {
$.getJSON("/feature/search_related.json", {
'id': FEATURE_ID
}, function(data) {
for (var i=0; i<data.length;i++) {

View File

@ -16,7 +16,7 @@ $(function() {
e.preventDefault();
var bbox = map.getExtent().toBBOX();
var search_term = $('#search').val();
$.getJSON("search_json", {
$.getJSON("/feature/search.json", {
'bbox': bbox,
'search': search_term
}, function(features) {

View File

@ -1 +1,30 @@
{% extends 'admin/change_form.html' %}
{% block extrahead %}
{{ block.super }}
<script type="text/javascript" src="/static/js/jquery.js"></script>
<script type="text/javascript">
RECORD_ID = {{ object_id }}
</script>
<script type="text/javascript" src="/static/js/auth_record_admin.js"></script>
{% endblock %}
% block after_related_objects %}
<div id="similarFeatures">
<table id="mapList">
<thead>
<tr>
<td>Name</td>
<td>Type</td>
<td>County</td>
<td>State</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
{% endblock %}

View File

@ -10,9 +10,10 @@ urlpatterns = patterns('',
# Example:
# (r'^gazetteer/', include('gazetteer.foo.urls')),
('^search$', 'places.views.search'),
('^search_json$', 'places.views.search_json'),
('^feature/search.json$', 'places.views.search_json'),
('^search_related$', 'places.views.search_related'),
('^search_related_json$', 'places.views.search_related_json'),
('^feature/search_related.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')),
(r'^ajax_select/', include('ajax_select.urls')),