Skip to content

Commit

Permalink
core adjustments for silage, mostly urls
Browse files Browse the repository at this point in the history
- in addition to url changes, adjust js template to use results
  instead of rows (as per search spec)
- add map changed signal to allow hooking of indexer
- add function to add bbox filter to a query
- implement local_layers
- remove obsolete integration test (covered in unit tests now)
  • Loading branch information
ischneider committed Oct 17, 2012
1 parent 9e95a01 commit 751d4d7
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 100 deletions.
13 changes: 13 additions & 0 deletions geonode/layers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,19 @@ def keyword_csv(self):

class Meta:
abstract = True


def add_bbox_query(q, bbox):
'''modify the queryset q to limit to the provided bbox
bbox - 4 tuple of floats representing x0,x1,y0,y1
returns the modified query
'''
q = q.filter(bbox_x0__gte=bbox[0])
q = q.filter(bbox_x1__lte=bbox[1])
q = q.filter(bbox_y0__gte=bbox[2])
return q.filter(bbox_y1__lte=bbox[3])


class Layer(ResourceBase):
"""
Expand Down
4 changes: 2 additions & 2 deletions geonode/layers/templates/layers/layer_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ <h3>{% trans "Selected Data" %}</h3>

{% block extra_script %}
<script type="text/html" id="searchResultsTemplate">
<%#rows%>
<%#results%>
<tr>
<td><a href="<%detail%>"><%title%></a></td>
<td><a href="<%owner_detail%>"><%owner%></a></td>
<td><abbr class="timeago" title="<%last_modified%>"><%last_modified%></abbr></td>
<td><input class="asset-selector pull-right" data-name="<%name%>" data-type="layer" type="checkbox"></td>
</tr>
<%/rows%>
<%/results%>
</script>
<script type="text/html" id="searchNoResultsTemplate">
<tr>
Expand Down
2 changes: 1 addition & 1 deletion geonode/layers/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def test_search(self):
def test_search_api(self):
'''/data/search/api -> Test accessing the data search api JSON'''
c = Client()
response = c.get('/data/search/api')
response = c.get('/search/api/data')
self.failUnlessEqual(response.status_code, 200)

def test_describe_data(self):
Expand Down
1 change: 0 additions & 1 deletion geonode/layers/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
url(r'^tag/(?P<slug>[-\w]+?)/$', 'layer_tag', name='layer_browse_tag'),
url(r'^acls/?$', 'layer_acls', name='layer_acls'),
url(r'^search/?$', 'layer_search_page', name='layer_search_page'),
url(r'^search/api/?$', 'layer_search', name='layer_search_api'),
url(r'^upload$', 'layer_upload', name='layer_upload'),
url(r'^download$', 'layer_batch_download', name='layer_batch_download'),
url(r'^(?P<layername>[^/]*)$', 'layer_detail', name="layer_detail"),
Expand Down
10 changes: 9 additions & 1 deletion geonode/maps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from django.core.urlresolvers import reverse

from geonode.layers.models import Layer, TopicCategory
from geonode.maps.signals import map_changed_signal
from geonode.security.models import PermissionLevelMixin
from geonode.security.models import AUTHENTICATED_USERS, ANONYMOUS_USERS
from geonode.utils import GXPMapBase
Expand Down Expand Up @@ -109,7 +110,9 @@ def layers(self):

@property
def local_layers(self):
return True
layer_names = MapLayer.objects.filter(map__id=self.id).values('name')
return Layer.objects.filter(typename__in=layer_names) | \
Layer.objects.filter(name__in=layer_names)

def json(self, layer_filter):
map_layers = MapLayer.objects.filter(map=self.id)
Expand Down Expand Up @@ -169,6 +172,7 @@ def source_for(layer):
return conf["sources"][layer["source"]]

layers = [l for l in conf["map"]["layers"]]
layer_names = set([l.typename for l in self.local_layers])

for layer in self.layer_set.all():
layer.delete()
Expand All @@ -180,6 +184,10 @@ def source_for(layer):
layer_from_viewer_config(
MapLayer, layer, source_for(layer), ordering
))

if layer_names != set([l.typename for l in self.local_layers]):
map_changed_signal.send_robust(sender=self,what_changed='layers')

self.save()

def keyword_list(self):
Expand Down
3 changes: 3 additions & 0 deletions geonode/maps/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.dispatch import Signal

map_changed_signal = Signal(providing_args=['what_changed'])
4 changes: 2 additions & 2 deletions geonode/maps/templates/maps/map_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ <h2 class="page-title">{% trans "Search Maps" %}</h2>

{% block extra_script %}
<script type="text/html" id="searchResultsTemplate">
<%#rows%>
<%#results%>
<tr>
<td><a href="<%detail%>"><%title%></a></td>
<td><a href="<%owner_detail%>"><%owner%></a></td>
<td><abbr class="timeago" title="<%last_modified%>"><%last_modified%></abbr></td>
</tr>
<%/rows%>
<%/results%>
</script>
<script type="text/html" id="searchNoResultsTemplate">
<tr>
Expand Down
6 changes: 3 additions & 3 deletions geonode/maps/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,16 @@ def test_maps_search(self):
map_id_2 = int(response['Location'].split('/')[-1])
c.logout()

url = '/maps/search/api/?'
url = '/search/api/maps'

# Test GET method
response = c.get(url, {'q': '', 'start': 1, 'limit': '', 'sort': '', 'dir': ''}, content_type="text/json")
response = c.get(url, {'q': '', 'start': 1}, content_type="text/json")
self.assertEquals(response.status_code,200)
response_dict = json.loads(response.content)
self.assertEquals(response_dict['success'], True)

# Test POST method
response = c.post(url, {'q': '', 'start': 1, 'limit': '', 'sort': '', 'dir': ''}, content_type="text/json")
response = c.post(url, {'q': '', 'start': 1}, content_type="text/json")
self.assertEquals(response.status_code,200)
response_dict = json.loads(response.content)
self.assertEquals(response_dict['success'], True)
Expand Down
1 change: 0 additions & 1 deletion geonode/maps/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
url(r'^category/(?P<slug>[-\w]+?)/$', 'maps_category', name='maps_browse_category'),
url(r'^tag/(?P<slug>[-\w]+?)/$', 'maps_tag', name='maps_browse_tag'),
url(r'^search/?$', 'maps_search_page', name='maps_search'),
url(r'^search/api/?$', 'maps_search', name='maps_search_api'),
url(r'^new$', 'new_map', name="new_map"),
url(r'^new/data$', 'new_map_json', name='new_map_json'),
url(r'^(?P<mapid>\d+)$', 'map_detail', name='map_detail'),
Expand Down
1 change: 1 addition & 0 deletions geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
'geonode.people',
'geonode.proxy',
'geonode.security',
'geonode.search.backends.silage',
'geonode.catalogue',
)
LOGGING = {
Expand Down
2 changes: 1 addition & 1 deletion geonode/smoke_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_maps_search_api(self):
'''Test Maps Search API page renders.'''

c = Client()
response = c.get('/maps/search/api/')
response = c.get('/search/api/maps')
self.failUnlessEqual(response.status_code, 200)

def test_new_map_page(self):
Expand Down
93 changes: 5 additions & 88 deletions geonode/tests/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@

LOGIN_URL= "/accounts/login/"

import logging
logging.getLogger("south").setLevel(logging.INFO)

class GeoNodeCoreTest(TestCase):
"""Tests geonode.security app/module
Expand Down Expand Up @@ -328,94 +330,6 @@ def test_repeated_upload(self):

# Search Tests

def test_metadata_search(self):

# Test Empty Search [returns all results, should match len(Layer.objects.all())+5]
# +5 is for the 5 'default' records in GeoNetwork
test_url = "/data/search/api/?q=%s&start=%d&limit=%d" % ("", 0, 10)
client = Client()
resp = client.get(test_url)
results = json.loads(resp.content)
self.assertEquals(int(results["total"]), Layer.objects.count())

# Test n0ch@nc3 Search (returns no results)
test_url = "/data/search/api/?q=%s&start=%d&limit=%d" % ("n0ch@nc3", 0, 10)
resp = client.get(test_url)
results = json.loads(resp.content)
self.assertEquals(int(results["total"]), 0)

# Test Keyword Search (various search terms)
test_url = "/data/search/api/?q=%s&start=%d&limit=%d" % ("NIC", 0, 10)
resp = client.get(test_url)
results = json.loads(resp.content)
#self.assertEquals(int(results["total"]), 3)

# This Section should be greatly expanded upon after uploading several
# Test layers. Issues found with GeoNetwork search should be 'documented'
# here with a Test Case

# Test BBOX Search (various bbox)

# - Test with an empty query string and Global BBOX and validate that total is correct
test_url = "/data/search/api/?q=%s&start=%d&limit=%d&bbox=%s" % ("", 0, 10, "-180,-90,180,90")
resp = client.get(test_url)
results = json.loads(resp.content)
self.assertEquals(int(results["total"]), Layer.objects.count())

# - Test with a specific query string and a bbox that is disjoint from its results
#test_url = "%sdata/search/api/?q=%s&start=%d&limit=%d&bbox=%s" % (settings.SITEURL, "NIC", 0, 10, "0,-90,180,90")
#results = json.loads(get_web_page(test_url))
#self.assertEquals(int(results["total"]), 0)

# - Many more Tests required

# Test start/limit params (do in unit test?)

# Test complex/compound Search

# Test Permissions applied to search from ACLs

# TODO Write a method to accept a perm_spec and query params
# and test that query results are returned respecting the
# perm_spec

# - Test with Anonymous User
perm_spec = {"anonymous":"_none","authenticated":"_none","users":[["admin","layer_readwrite"]]}
for layer in Layer.objects.all():
layer_set_permissions(layer, perm_spec)

test_url = "/data/search/api/?q=%s&start=%d&limit=%d" % ("", 0, 10)
resp = client.get(test_url)
results = json.loads(resp.content)

for layer in results["rows"]:
if layer["_local"] == False:
# Ignore non-local layers
pass
else:
self.assertEquals(layer["_permissions"]["view"], False)
self.assertEquals(layer["_permissions"]["change"], False)
self.assertEquals(layer["_permissions"]["delete"], False)
self.assertEquals(layer["_permissions"]["change_permissions"], False)

# - Test with Authenticated User
client = Client()
client.login(username='admin', password='admin')
resp = client.get(test_url)
results = json.loads(resp.content)

for layer in results["rows"]:
if layer["_local"] == False:
# Ignore non-local layers
pass
else:
self.assertEquals(layer["_permissions"]["view"], True)
self.assertEquals(layer["_permissions"]["change"], True)
self.assertEquals(layer["_permissions"]["delete"], True)
self.assertEquals(layer["_permissions"]["change_permissions"], True)

# Test that MAX_SEARCH_BATCH_SIZE is respected (in unit test?)

def test_search_result_detail(self):
shp_file = os.path.join(gisdata.VECTOR_DATA, 'san_andres_y_providencia_poi.shp')
shp_layer = file_upload(shp_file, overwrite=True)
Expand All @@ -427,6 +341,9 @@ def test_search_result_detail(self):
client = Client()
resp = client.get(test_url)
results = resp.content
print results
print resp.status_code
assert resp.status_code == 200

# Test with an invalid UUID (should return 404, but currently does not)
uuid="xyz"
Expand Down
3 changes: 3 additions & 0 deletions geonode/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@

# Map views
(r'^maps/', include('geonode.maps.urls')),

# Search
(r'^search/', include('geonode.search.backends.silage.urls')),

# Social
(r'^comments/', include('dialogos.urls')),
Expand Down

0 comments on commit 751d4d7

Please sign in to comment.