Permalink
Browse files

Merge branch 'mapstory' of github.com:opengeo/geonode into mapstory

  • Loading branch information...
2 parents a014223 + 42c8031 commit 978c8df25d38dd2b2ed000ff8b65fd3a9b38616a @mpriour mpriour committed Apr 6, 2012
@@ -929,8 +929,9 @@ def verify(self):
def maps(self):
"""Return a list of all the maps that use this layer"""
- local_wms = "%swms" % settings.GEOSERVER_BASE_URL
- return set([layer.map for layer in MapLayer.objects.filter(ows_url=local_wms, name=self.typename).select_related()])
+ # @todo revist this - ows_url is not anything close to GEOSERVER_BASE_URL
+ local_wms = "/geoserver/wms"
+ return set([layer.map for layer in MapLayer.objects.filter(ows_url=local_wms, name__endswith=self.name).select_related()])
def metadata(self):
return _get_wms(self.typename)[self.typename]
@@ -597,7 +597,7 @@ def mapdetail(request,mapid):
config = map.viewer_json(authenticated=request.user.is_authenticated())
#config["tools"] = False;
config = json.dumps(config)
- layers = MapLayer.objects.filter(map=map.id)
+ layers = set(MapLayer.objects.filter(map=map.id))
return render_to_response("maps/mapinfo.html", RequestContext(request, {
'config': config,
'map': map,
@@ -867,10 +867,10 @@ def layer_thumbnail(req, layername):
def _handleThumbNail(req, obj):
# object will either be a map or a layer, one or the other permission must apply
- if not req.user.has_perm('maps.change_maps', obj=obj) or not req.user.has_perm('maps.change_layer', obj=obj):
+ if not req.user.has_perm('maps.change_map', obj=obj) and not req.user.has_perm('maps.change_layer', obj=obj):
return HttpResponse(loader.render_to_string('401.html',
RequestContext(req, {'error_message':
- _("You are not permitted to modify this layer")})), status=401)
+ _("You are not permitted to modify this object")})), status=401)
if req.method == 'GET':
thumb = Thumbnail.objects.get_thumbnail(obj,allow_null=False)
if thumb:
@@ -7,6 +7,9 @@
from geonode.maps.views import _metadata_search
from geonode.maps.views import _split_query
+# @hack - fix dependency by allowing injection
+from mapstory.models import Section
+
import re
_exclude_patterns = []
@@ -30,6 +33,7 @@ def __init__(self,o,data = None):
self.dict = None
self.title = o.title
self.last_modified = self.last_modified(o)
+ self.iid = None
def last_modified(self,o):
abstract
def as_dict(self):
@@ -47,7 +51,6 @@ def populate(self, dict):
owner_name = Contact.objects.get(user=map.owner).name
except:
owner_name = map.owner.first_name + " " + map.owner.last_name
- thumb = Thumbnail.objects.get_thumbnail(map)
# resolve any local layers and their keywords
local_kw = [ l.keywords.split(' ') for l in map.local_layers if l.keywords]
keywords = local_kw and list(set( reduce(lambda a,b: a+b, local_kw))) or []
@@ -62,7 +65,7 @@ def populate(self, dict):
'last_modified' : map.last_modified.isoformat(),
'_type' : 'map',
'_display_type' : 'Map',
- 'thumb' : thumb and thumb.get_thumbnail_url() or None,
+ 'thumb' : map.get_thumbnail_url(),
'keywords' : keywords
}
@@ -71,9 +74,8 @@ def last_modified(self,layer):
return layer.date.isoformat()
def populate(self, doc):
layer = self.o
- thumb = Thumbnail.objects.get_thumbnail(layer)
doc['owner'] = layer.metadata_author.name
- doc['thumb'] = thumb and thumb.get_thumbnail_url() or None
+ doc['thumb'] = layer.get_thumbnail_url()
doc['last_modified'] = layer.date.isoformat()
doc['id'] = layer.id
doc['_type'] = 'layer'
@@ -86,7 +88,16 @@ def populate(self, doc):
return doc
def _get_map_results(results, query, kw):
- map_query = Map.objects.all()
+ bysection = kw.get('bysection', None)
+ if bysection:
+ section = Section.objects.get(pk=bysection)
+ mapids = set()
+ for t in section.topics.all():
+ for l in t.maps.all():
+ mapids.add( l.pk )
+ map_query = Map.objects.filter(pk__in=mapids)
+ else:
+ map_query = Map.objects.all()
if query:
keywords = _split_query(query)
@@ -108,9 +119,18 @@ def _get_layer_results(results, query, kw):
layer_results = filter(_filter_results, layer_results)
# @todo search cache timeout in settings?
cache.set(cache_key, layer_results, timeout=300)
-
- #build our Layer query, first by uuids
- Q = Layer.objects.filter(uuid__in=[ doc['uuid'] for doc in layer_results ])
+
+ bysection = kw.get('bysection', None)
+ if bysection:
+ section = Section.objects.get(pk=bysection)
+ layerids = set()
+ for t in section.topics.all():
+ for l in t.layers.all():
+ layerids.add( l.pk )
+ Q = Layer.objects.filter(pk__in=layerids)
+ else:
+ #build our Layer query, first by uuids
+ Q = Layer.objects.filter(uuid__in=[ doc['uuid'] for doc in layer_results ])
bytype = kw.get('bytype', None)
if bytype and bytype != 'layer':
@@ -3,6 +3,7 @@
urlpatterns = patterns('geonode.simplesearch.views',
url(r'^search/?$', 'new_search_page', name='new_search'),
url(r'^search/api?$', 'new_search_api', name='new_search_api'),
+ url(r'^search/sapi?$', 'new_search_api_reduced', name='new_search_api_reduced'),
#override search urls with specific views
url(r'^data/search$','new_search_page',kwargs={'bytype':'layer'}, name='search_layers'),
url(r'^maps/search$','new_search_page',kwargs={'bytype':'map'}, name='search_maps'),
@@ -7,6 +7,9 @@
from geonode.maps.models import *
from geonode.simplesearch.search import combined_search_results
+# @hack - fix dependency by allowing injection
+from mapstory.models import Section
+
import json
DEFAULT_MAPS_SEARCH_BATCH_SIZE = 10
@@ -40,18 +43,47 @@ def new_search_page(request, **kw):
topic_cnts = {}
for t in topics: topic_cnts[t] = topic_cnts.get(t,0) + 1
- return render_to_response('maps/new_search.html', RequestContext(request, {
+ return render_to_response('simplesearch/search.html', RequestContext(request, {
'init_search': json.dumps(params or {}),
'viewer_config': json.dumps(map.viewer_json(added_layers=DEFAULT_BASE_LAYERS, authenticated=request.user.is_authenticated())),
'GOOGLE_API_KEY' : settings.GOOGLE_API_KEY,
"site" : settings.SITEURL,
'counts' : counts,
'users' : User.objects.all(),
'topics' : topic_cnts,
+ 'sections' : Section.objects.all(),
'keywords' : Layer.objects.gn_catalog.get_all_keywords()
}))
def new_search_api(request):
+ from time import time
+
+ ts = time()
+ params = _search_params(request)
+ start = params[1]
+ total, items = _new_search(*params)
+ ts = time() - ts
+ logger.info('generated combined search results in %s',ts)
+
+ return _search_json(items, total, start, ts)
+
+def new_search_api_reduced(request):
+ from time import time
+
+ ts = time()
+ params = _search_params(request)
+ total, items = _new_search(*params)
+ ts = time() - ts
+ logger.info('generated combined search results in %s',ts)
+ idfun = lambda o: (isinstance(o, Map) and 'm%s' or 'l%s') % o.o.pk
+ results = {
+ "_time" : ts,
+ "rows" : [ idfun(i) for i in items ],
+ "total" : total
+ }
+ return HttpResponse(json.dumps(results), mimetype="application/json")
+
+def _search_params(request):
if request.method == 'GET':
params = request.GET
elif request.method == 'POST':
@@ -86,53 +118,48 @@ def new_search_api(request):
}[params.get('sort','newest')]
filters = {}
- for k in ('bytype','bytopic','bykw'):
+ for k in ('bytype','bytopic','bykw','bysection'):
if k in params:
if params[k]:
filters[k] = params[k]
- result = _new_search(query, start, limit, sort_field, sort_asc, filters)
-
- result['success'] = True
- return HttpResponse(json.dumps(result), mimetype="application/json")
-
-
+ return query, start, limit, sort_field, sort_asc, filters
+
+
+def _search_json(results, total, start, time):
+ # unique item id for ext store (this could be done client side)
+ iid = start
+ for r in results:
+ r.iid = iid
+ iid += 1
+
+ results = map(lambda r: r.as_dict(),results)
+
+ results = {
+ '_time' : time,
+ 'rows' : results,
+ 'total' : total
+ }
+ results['success'] = True
+ return HttpResponse(json.dumps(results), mimetype="application/json")
def _new_search(query, start, limit, sort_field, sort_asc, filters):
- from time import time
-
- ts = time()
results = combined_search_results(query, filters)
filter_fun = []
# careful when creating lambda or function filters inline like this
# as multiple filters cannot use the same local variable or they
# will overwrite each other
- if 'kw' in filters:
- kw = filters['kw']
- filter_fun.append(lambda r: 'keywords' in r and kw in r['keywords'])
+ if 'bykw' in filters:
+ kw = filters['bykw']
+ filter_fun.append(lambda r: 'keywords' in r.as_dict() and kw in r.as_dict()['keywords'])
for fun in filter_fun:
results = filter(fun,results)
# default sort order by id (could be last_modified when external layers are dealt with)
results.sort(key=lambda r: getattr(r,sort_field),reverse=not sort_asc)
- totalQueryCount = len(results)
- results = results[start:start+limit]
- # unique item id for ext store (this could be done client side)
- iid = start
- for r in results:
- r.iid = iid
- iid += 1
-
- results = map(lambda r: r.as_dict(),results)
-
- ts = time() - ts
- logger.info('generated combined search results in %s',ts)
- return {
- '_time' : ts,
- 'rows' : results,
- 'total' : totalQueryCount
- }
+ return len(results), results[start:start+limit]
+
@@ -33,7 +33,7 @@ function updateThumbnail(interactive) {
if (interactive) {
Ext.MessageBox.show({
title : "Thumbnail Updated",
- msg : '<img src="' + thumbURL + "'?_='" + Math.random() + '">',
+ msg : '<img src="' + thumbURL + "?_=" + Math.random() + '">',
buttons: Ext.MessageBox.OK
});
}
@@ -11,7 +11,7 @@
{% autoescape off %}
var viewer_config = {{ viewer_config }};
var init_search = {{ init_search }};
- {% include "maps/new_search.js" %}
+ {% include "simplesearch/search.js" %}
{% endautoescape %}
</script>
{% endblock %}

0 comments on commit 978c8df

Please sign in to comment.