Permalink
Browse files

Update gxp module; prevent tools from being saved/loaded to/from snap…

…shots
  • Loading branch information...
1 parent a503fe6 commit 807fd29ecc21ddc3f9df230dfd145653f6aaf92f @mbertrand mbertrand committed Apr 1, 2012
View
@@ -17,8 +17,5 @@
path = src/geonode-client/externals/buildkit
url = git://github.com/tschaub/buildkit.git
[submodule "src/geonode-client/app/static/externals/gxp"]
- path = src/geonode-client/app/static/externals/gxp
- url = git://github.com/cga-harvard/gxp.git
-
-
-
+ path = src/geonode-client/app/static/externals/gxp
+ url = git://github.com/cga-harvard/gxp.git
@@ -704,68 +704,8 @@ def default_poc(self):
def default_metadata_author(self):
return self.admin_contact()
- def import_existing_layer(self, resource_name):
- #Like slurp but for just one particular layer
- cat = self.gs_catalog
- gn = self.gn_catalog
- resource = cat.get_resource(resource_name)
- if resource:
- store = resource.store
- workspace = store.workspace
- layer, created = self.get_or_create(name=resource.name, defaults = {
- "workspace": workspace.name,
- "store": store.name,
- "storeType": store.resource_type,
- "typename": "%s:%s" % (workspace.name, resource.name),
- "title": resource.title or 'No title provided',
- "abstract": resource.abstract or 'No abstract provided',
- "uuid": str(uuid.uuid4())
- })
- ## Due to a bug in GeoNode versions prior to 1.0RC2, the data
- ## in the database may not have a valid date_type set. The
- ## invalid values are expected to differ from the acceptable
- ## values only by case, so try to convert, then fallback to a
- ## default.
- ##
- ## We should probably drop this adjustment in 1.1. --David Winslow
- if layer.date_type not in Layer.VALID_DATE_TYPES:
- candidate = lower(layer.date_type)
- if candidate in Layer.VALID_DATE_TYPES:
- layer.date_type = candidate
- else:
- layer.date_type = Layer.VALID_DATE_TYPES[0]
-
- layer._populate_from_gs()
-
- layer.save()
- if created:
- layer.set_default_permissions()
- #Create layer attributes if they don't already exist
- try:
- if layer.attribute_names is not None:
- iter = 1
- for field, ftype in layer.attribute_names.iteritems():
- if field is not None:
- la, created = LayerAttribute.objects.get_or_create(layer=layer, attribute=field, attribute_type=ftype)
- if created:
- logger.debug("Created [%s] attribute for [%s]", field, layer.name)
- la.attribute_label = field
- la.searchable = (ftype == "xsd:string")
- la.display_order = iter
- la.save()
- msg = ("Created [%s] attribute for [%s]", field, layer.name)
- iter += 1
- except Exception, e:
- logger.debug("Could not create attributes for [%s] : [%s]", layer.name, str(e))
- finally:
- pass
- # Doing a logout since we know we don't need this object anymore.
- gn.logout()
-
-
-
- def slurp(self, ignore_errors=True, verbosity=1, console=sys.stdout):
+ def slurp(self, ignore_errors=True, verbosity=1, console=sys.stdout, layer=None):
"""Configure the layers available in GeoServer in GeoNode.
It returns a list of dictionaries with the name of the layer,
@@ -774,7 +714,11 @@ def slurp(self, ignore_errors=True, verbosity=1, console=sys.stdout):
if verbosity > 1:
print >> console, "Inspecting the available layers in GeoServer ..."
cat = self.gs_catalog
- resources = cat.get_resources()
+ if layer is None:
+ resources = cat.get_resources()
+ else:
+ resource = cat.get_resource(layer)
+ resources = [resource] if resource else []
number = len(resources)
if verbosity > 1:
msg = "Found %d layers, starting processing" % number
@@ -795,56 +739,58 @@ def slurp(self, ignore_errors=True, verbosity=1, console=sys.stdout):
"uuid": str(uuid.uuid4())
})
- layer.save()
- except Exception, e:
- if ignore_errors:
- status = 'failed'
- exception_type, error, traceback = sys.exc_info()
- else:
- if verbosity > 0:
- msg = "Stopping process because --ignore-errors was not set and an error was found."
- print >> sys.stderr, msg
- raise Exception('Failed to process %s' % resource.name, e), None, sys.exc_info()[2]
- else:
+
if created:
layer.set_default_permissions()
status = 'created'
+ else:
+ status = 'updated'
- #Create layer attributes if they don't already exist
- try:
+ #Create layer attributes if they don't already exist
+ try:
+ if layer.attribute_names is not None:
iter = 1
for field, ftype in layer.attribute_names.iteritems():
if field is not None:
la, created = LayerAttribute.objects.get_or_create(layer=layer, attribute=field, attribute_type=ftype)
if created:
- logger.debug("Created [%s] attribute for [%s]", field, layer.name)
la.attribute_label = field
la.searchable = (ftype == "xsd:string")
la.display_order = iter
la.save()
msg = ("Created [%s] attribute for [%s]", field, layer.name)
iter += 1
- except Exception, e:
- msg = ("Could not create attributes for [%s] : [%s]", layer.name, str(e))
- print >> console, msg
- finally:
- pass
- else:
- status = 'updated'
+ print >> console, msg
+ except Exception, e:
+ msg = ("Could not create attributes for [%s] : [%s]", layer.name, str(e))
+ print >> console, msg
+ finally:
+ pass
+
if layer is not None and layer.bbox is None:
layer._populate_from_gs()
layer.save()
- msg = "[%s] Layer %s (%d/%d)" % (status, name, i, number)
- info = {'name': name, 'status': status}
- if status == 'failed':
- info['traceback'] = traceback
- info['exception_type'] = exception_type
- info['error'] = error
- output.append(info)
- if verbosity > 0:
- print >> console, msg
+ msg = "[%s] Layer %s (%d/%d)" % (status, name, i, number)
+ info = {'name': name, 'status': status}
+ if status == 'failed':
+ info['traceback'] = traceback
+ info['exception_type'] = exception_type
+ info['error'] = error
+ output.append(info)
+ if verbosity > 0:
+ print >> console, msg
+
+ except Exception, e:
+ if ignore_errors:
+ status = 'failed'
+ exception_type, error, traceback = sys.exc_info()
+ else:
+ if verbosity > 0:
+ msg = "Stopping process because --ignore-errors was not set and an error was found."
+ print >> sys.stderr, msg
+ raise Exception('Failed to process %s' % resource.name, e), None, sys.exc_info()[2]
return output
@@ -968,6 +914,9 @@ def download_links(self):
"""Returns a list of (mimetype, URL) tuples for downloads of this data
in various formats."""
+ if self.name.find('nc_community_survey') > -1:
+ return None
+
bbox = self.llbbox_coords()
dx = float(min(180,bbox[2])) - float(max(-180,(bbox[0])))
@@ -1779,7 +1728,6 @@ def layer_config(l, user):
config["map"].update(_get_viewer_projection_info(self.projection))
- logger.debug("CONFIG: %s", config)
return config
@@ -2228,25 +2176,16 @@ def delete_layer(instance, sender, **kwargs):
def post_save_layer(instance, sender, **kwargs):
instance._autopopulate()
- if (re.search("coverageStore|dataStore", instance.storeType)):
- logger.info("Call save_to_geoserver for %s", instance.name)
- instance.save_to_geoserver()
+ instance.save_to_geoserver()
- if kwargs['created']:
- logger.info("Call populate_from_geoserver for %s", instance.name)
- instance._populate_from_gs()
+ if kwargs['created']:
+ instance._populate_from_gs()
instance.save_to_geonetwork()
if kwargs['created']:
- logger.debug("populate from geonetwork")
- try:
- instance._populate_from_gn()
- instance.save(force_update=True)
- except:
- logger.warning("Exception populating from geonetwork record for [%s]", instance.name)
- raise
- logger.debug("save instance")
+ instance._populate_from_gn()
+ instance.save(force_update=True)
signals.pre_delete.connect(delete_layer, sender=Layer)
signals.post_save.connect(post_save_layer, sender=Layer)
@@ -203,7 +203,7 @@ def maps(request, mapid=None):
map.save()
map.set_default_permissions()
map.update_from_viewer(request.raw_post_data)
- MapSnapshot.objects.create(config=request.raw_post_data,map=map,user=request.user)
+ MapSnapshot.objects.create(config=clean_config(request.raw_post_data),map=map,user=request.user)
response = HttpResponse('', status=201)
response['Location'] = map.officialurl if map.officialurl else (map.urlsuffix if map.urlsuffix else map.id)
transaction.commit()
@@ -235,7 +235,7 @@ def mapJSON(request, mapid):
return HttpResponse("You are not allowed to modify this map.", status=403)
try:
map.update_from_viewer(request.raw_post_data)
- MapSnapshot.objects.create(config=request.raw_post_data,map=Map.objects.get(id=map.id),user=request.user)
+ MapSnapshot.objects.create(config=clean_config(request.raw_post_data),map=Map.objects.get(id=map.id),user=request.user)
return HttpResponse(
"Map successfully updated.",
mimetype="text/plain",
@@ -929,12 +929,20 @@ def snapshot_create(request):
if isinstance(conf, basestring):
config = simplejson.loads(conf)
- mapid = config['id']
- snapshot = MapSnapshot.objects.create(config=conf,map=Map.objects.get(id=mapid))
+ del config["tools"]
+ snapshot = MapSnapshot.objects.create(config=clean_config(config),map=Map.objects.get(id=config['id']))
return HttpResponse(num_encode(snapshot.id), mimetype="text/plain")
else:
return HttpResponse("Invalid JSON", mimetype="text/plain", status=500)
+def clean_config(conf):
+ if isinstance(conf, basestring):
+ config = simplejson.loads(conf)
+ del config["tools"]
+ return simplejson.dumps(config)
+ else:
+ return conf
+
def ajax_snapshot_history(request, mapid):
map = Map.objects.get(pk=mapid)
@@ -2432,6 +2440,8 @@ def snaplayer_config(layer, sources, user):
snapshot = get_object_or_404(MapSnapshot, pk=decodedid)
if snapshot.map == map:
config = simplejson.loads(snapshot.config)
+ if "tools" in config:
+ del config["tools"]
layers = [l for l in config["map"]["layers"]]
sources = config["sources"]
maplayers = []
Binary file not shown.
Submodule gxp added at c650d2

0 comments on commit 807fd29

Please sign in to comment.