From a61d8dd6febadc4ca31d0f4e6ff307331890a0ed Mon Sep 17 00:00:00 2001
From: Sanj
Date: Thu, 1 Sep 2011 08:28:02 +0530
Subject: [PATCH] add JS to edit relations; add TODOs in views.py
---
gazetteer/places/views.py | 13 ++++++++++---
gazetteer/static/js/feature_admin.js | 15 ++++++++++++++-
gazetteer/urls.py | 1 +
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/gazetteer/places/views.py b/gazetteer/places/views.py
index 6422e89..dca9f83 100644
--- a/gazetteer/places/views.py
+++ b/gazetteer/places/views.py
@@ -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.'})
diff --git a/gazetteer/static/js/feature_admin.js b/gazetteer/static/js/feature_admin.js
index 7000816..2e1aceb 100644
--- a/gazetteer/static/js/feature_admin.js
+++ b/gazetteer/static/js/feature_admin.js
@@ -17,7 +17,7 @@ $(function() {
var RELATIONSHIP_OPTIONS = ['conflates', 'contains', 'consumes', 'supersedes']
function getRow(d) {
- var $tr = $('');
+ var $tr = $(' ').data("id", d.id);
var $one = $('