add JS to edit relations; add TODOs in views.py
This commit is contained in:
parent
1f4333bf94
commit
a61d8dd6fe
|
@ -89,7 +89,7 @@ def search_related_json(request, id):
|
|||
d = []
|
||||
|
||||
for s in similar_features:
|
||||
f = Feature.objects.get(pk=s.id) # This seems inefficient - better to get something like time_frame_id in models method? TODO
|
||||
f = Feature.objects.get(pk=s.id) # This seems inefficient - better to get something like time_frame_id in models method?
|
||||
if f.time_frame is not None:
|
||||
time_frame = f.time_frame.description
|
||||
else:
|
||||
|
@ -104,7 +104,7 @@ def search_related_json(request, id):
|
|||
'distance': s.distance,
|
||||
'time_frame': time_frame,
|
||||
'is_primary': s.is_primary,
|
||||
'relationship': ''
|
||||
'relationship': '' #TODO: query db for relation between id and s.id - if exists, return relation_type as string, else return empty string.
|
||||
})
|
||||
return render_to_json_response(d)
|
||||
|
||||
|
@ -128,7 +128,14 @@ def time_frame_json(request):
|
|||
}
|
||||
return render_to_json_response(d)
|
||||
|
||||
|
||||
def add_relation(request):
|
||||
feature1 = request.GET.get("feature1", None)
|
||||
feature2 = request.GET.get("feature2", None)
|
||||
relation = request.GET.get("relation", "")
|
||||
if feature1 == None or feature2 == None or not request.user.is_staff(): #TODO: split up errors :/ -- not imp.
|
||||
return render_to_json_response({'error': 'bad request'})
|
||||
#TODO: handle saving m2m between feature1 and feature2 with relation
|
||||
return render_to_json_response({'success': 'relation made successfully.'})
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ $(function() {
|
|||
var RELATIONSHIP_OPTIONS = ['conflates', 'contains', 'consumes', 'supersedes']
|
||||
|
||||
function getRow(d) {
|
||||
var $tr = $('<tr />');
|
||||
var $tr = $('<tr />').data("id", d.id);
|
||||
var $one = $('<td />').appendTo($tr);
|
||||
var $a = $('<a />').attr("href", "/admin/places/feature/" + d.id).text(d.preferred_name).appendTo($one);
|
||||
var similarity = Math.round(parseFloat(d.similarity) * 1000) / 10;
|
||||
|
@ -51,6 +51,19 @@ function getRow(d) {
|
|||
});
|
||||
}
|
||||
|
||||
$relationselect.change(function() {
|
||||
var feature1 = FEATURE_ID;
|
||||
var feature2 = $(this).parents("tr").data("id");
|
||||
var relation = $(this).val();
|
||||
$.getJSON("/add_relation", {
|
||||
'feature1': feature1,
|
||||
'feature2': feature2,
|
||||
'relation': relation
|
||||
}, function(response) {
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
return $tr;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ urlpatterns = patterns('',
|
|||
('^feature/(?P<id>\d+)/similar.json$', 'places.views.search_related_json'),
|
||||
('^auth_record.json$', 'places.views.auth_record_json'),
|
||||
('^time_frame.json$', 'places.views.time_frame_json'),
|
||||
('^add_relation$', 'places.views.add_relation'),
|
||||
# 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')),
|
||||
|
|
Loading…
Reference in New Issue
Block a user