From 171caadf0dd2bb0d68e5c9dc09a5360e1b3ea645 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Thu, 1 Sep 2011 03:18:13 -0700 Subject: [PATCH 1/2] find() returns only records with is_primary=True. --- gazetteer/places/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gazetteer/places/models.py b/gazetteer/places/models.py index 1435632..aa269a3 100644 --- a/gazetteer/places/models.py +++ b/gazetteer/places/models.py @@ -24,8 +24,8 @@ class FeatureSearchManager(models.GeoManager): cursor = connection.cursor() cursor.execute("""SELECT set_limit(%f)""" % threshold) - def find(self, bbox=None, text=None, adm1=None, adm2=None, threshold=0.5, srid=4326): - qset = self.get_query_set() + def find(self, bbox=None, text=None, adm1=None, adm2=None, is_primary=True, threshold=0.5, srid=4326): + qset = self.get_query_set().filter(is_primary=is_primary) if bbox: (minx, miny, maxx, maxy) = bbox bbox = Polygon(((minx,miny),(minx,maxy),(maxx,maxy),(maxx,miny),(minx,miny)),srid=srid) From b4909e161c7e1853b2a85729ea40d35623898600 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Thu, 1 Sep 2011 03:43:06 -0700 Subject: [PATCH 2/2] Return is_primary to True if removing a "conflates" relation. --- gazetteer/places/views.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/gazetteer/places/views.py b/gazetteer/places/views.py index 84932f9..cd6222a 100644 --- a/gazetteer/places/views.py +++ b/gazetteer/places/views.py @@ -65,11 +65,11 @@ def search_related_json(request, id): d = [] for s in similar_features: - time_frame = relates_to = related_by = "" + time_frame = relates_to = related_by = "" if s.time_frame is not None: time_frame = s.time_frame.description if s.relationship_type is not None: - if s.feature2_id == s.id: + if s.feature2_id == s.id: relates_to = s.relationship_type elif s.feature1_id == s.id: related_by = s.relationship_type @@ -82,7 +82,7 @@ def search_related_json(request, id): 'time_frame': time_frame, 'is_primary': s.is_primary, 'relates_to': relates_to, - 'related_by': related_by + 'related_by': related_by }) return render_to_json_response(d) @@ -120,19 +120,22 @@ def add_relation(request): feature2 = get_object_or_404_json(Feature, pk=feature2) rel_obj = None try: - rel_obj = Relationship.objects.get(feature1=feature1, feature2=feature2, relationship_type=relation) + rel_obj = Relationship.objects.get(feature1=feature1, feature2=feature2, relationship_type=relation) except ObjectDoesNotExist: - rel_obj = Relationship(feature1=feature1, feature2=feature2, relationship_type=relation) + rel_obj = Relationship(feature1=feature1, feature2=feature2, relationship_type=relation) verb = "created" if relation == "": - if rel_obj.id: - verb = "deleted" - rel_obj.delete() - else: + if rel_obj.id: + verb = "deleted" + rel_obj.delete() + if relation == "conflates": + feature2.is_primary = True + feature2.save() + else: return render_to_json_response({'error': 'relation is already deleted'}) else: rel_obj.save() - if relation == "subsumes": - feature2.is_primary = False - feature2.save() + if relation == "conflates": + feature2.is_primary = False + feature2.save() return render_to_json_response({'success': 'relation %s successfully.' % verb})