Skip to content

Commit

Permalink
[Fixes GeoNode#4025] Regression with uploading a shapefile with no as…
Browse files Browse the repository at this point in the history
…cii characters
  • Loading branch information
afabiani committed Oct 29, 2018
1 parent c9ca47e commit 5afb5ad
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 26 deletions.
8 changes: 4 additions & 4 deletions geonode/base/models.py
Expand Up @@ -805,7 +805,7 @@ def csw_crs(self):
@property
def group_name(self):
if self.group:
return str(self.group)
return str(self.group).encode("utf-8", "replace")
return None

@property
Expand Down Expand Up @@ -908,13 +908,13 @@ def metadata_completeness(self):
return '{}%'.format(len(filled_fields) * 100 / len(required_fields))

def keyword_list(self):
return [kw.name for kw in self.keywords.all()]
return [kw.name.encode("utf-8", "replace") for kw in self.keywords.all()]

def keyword_slug_list(self):
return [kw.slug for kw in self.keywords.all()]
return [kw.slug.encode("utf-8", "replace") for kw in self.keywords.all()]

def region_name_list(self):
return [region.name for region in self.regions.all()]
return [region.name.encode("utf-8", "replace") for region in self.regions.all()]

def spatial_representation_type_string(self):
if hasattr(self.spatial_representation_type, 'identifier'):
Expand Down
9 changes: 6 additions & 3 deletions geonode/base/templates/base/_resourcebase_snippet.html
Expand Up @@ -53,9 +53,12 @@ <h4>
<span ng-if="item.online == false"><i class="fa fa-power-off text-danger"></i> {% trans "Service is" %} {% trans "offline" %}</span>
{% verbatim %}
</em>
<div class="alert alert-danger" ng-if="item.dirty_state == true">SECURITY NOT YET SYNCHRONIZED</div>
<div class="alert alert-warning" ng-if="item.dirty_state == false && item.is_approved == false">PENDING APPROVAL</div>
<div class="alert alert-danger" ng-if="item.dirty_state == false && item.is_approved == true && item.is_published == false">UNPUBLISHED</div>
{% endverbatim %}
<div class="alert alert-danger" ng-if="item.dirty_state == true">{% trans "SECURITY NOT YET SYNCHRONIZED" %}</div>
<div class="alert alert-warning" ng-if="item.dirty_state == false && item.is_approved == false">{% trans "PENDING APPROVAL" %}</div>
<div class="alert alert-danger" ng-if="item.dirty_state == false && item.is_approved == true && item.is_published == false">{% trans "UNPUBLISHED" %}</div>
{% verbatim %}

<p class="abstract">{{ item.abstract | limitTo: 300 }}{{ item.abstract.length > 300 ? '...' : ''}}</p>
<div class="row">
<div class="col-lg-12 item-items">
Expand Down
47 changes: 31 additions & 16 deletions geonode/geoserver/signals.py
Expand Up @@ -243,14 +243,17 @@ def geoserver_post_save_local(instance, *args, **kwargs):
instance.workspace = gs_resource.store.workspace.name
instance.store = gs_resource.store.name

bbox = gs_resource.native_bbox

# Set bounding box values
instance.bbox_x0 = bbox[0]
instance.bbox_x1 = bbox[1]
instance.bbox_y0 = bbox[2]
instance.bbox_y1 = bbox[3]
instance.srid = bbox[4]
try:
bbox = gs_resource.native_bbox

# Set bounding box values
instance.bbox_x0 = bbox[0]
instance.bbox_x1 = bbox[1]
instance.bbox_y0 = bbox[2]
instance.bbox_y1 = bbox[3]
instance.srid = bbox[4]
except BaseException:
pass

if instance.srid:
instance.srid_url = "http://www.spatialreference.org/ref/" + \
Expand All @@ -271,14 +274,17 @@ def geoserver_post_save_local(instance, *args, **kwargs):
gs_catalog.save(gs_resource)

if not settings.FREETEXT_KEYWORDS_READONLY:
if len(instance.keyword_list()) == 0 and gs_resource.keywords:
for keyword in gs_resource.keywords:
if keyword not in instance.keyword_list():
instance.keywords.add(keyword)
try:
if len(instance.keyword_list()) == 0 and gs_resource.keywords:
for keyword in gs_resource.keywords:
if keyword not in instance.keyword_list():
instance.keywords.add(keyword)
except BaseException:
pass

if any(instance.keyword_list()):
keywords = instance.keyword_list()
gs_resource.keywords = list(set(keywords))
gs_resource.keywords = [kw.decode("utf-8", "replace") for kw in list(set(keywords))]

# gs_resource should only be called if
# ogc_server_settings.BACKEND_WRITE_ENABLED == True
Expand Down Expand Up @@ -321,7 +327,10 @@ def geoserver_post_save_local(instance, *args, **kwargs):
# store the resource to avoid another geoserver call in the post_save
instance.gs_resource = gs_resource

bbox = gs_resource.native_bbox
try:
bbox = gs_resource.native_bbox
except BaseException:
bbox = instance.bbox
dx = float(bbox[1]) - float(bbox[0])
dy = float(bbox[3]) - float(bbox[2])

Expand All @@ -337,7 +346,10 @@ def geoserver_post_save_local(instance, *args, **kwargs):
instance.bbox_x1, instance.bbox_y1])

# Create Raw Data download link
path = gs_resource.dom.findall('nativeName')
try:
path = gs_resource.dom.findall('nativeName')
except BaseException:
path = instance.alternate
download_url = urljoin(settings.SITEURL,
reverse('download', args=[instance.id]))
Link.objects.get_or_create(resource=instance.resourcebase_ptr,
Expand Down Expand Up @@ -397,7 +409,10 @@ def geoserver_post_save_local(instance, *args, **kwargs):
url=ogc_server_settings.public_url,
repo_name=geogig_repo_name)

path = gs_resource.dom.findall('nativeName')
try:
path = gs_resource.dom.findall('nativeName')
except BaseException:
path = instance.alternate

if path:
path = 'path={path}'.format(path=path[0].text)
Expand Down
11 changes: 8 additions & 3 deletions geonode/geoserver/upload.py
Expand Up @@ -180,8 +180,13 @@ def geoserver_upload(
# Step 6. Make sure our data always has a valid projection
# FIXME: Put this in gsconfig.py
logger.info('>>> Step 6. Making sure [%s] has a valid projection' % name)
if gs_resource.native_bbox is None:
box = gs_resource.native_bbox[:4]
_native_bbox = None
try:
_native_bbox = gs_resource.native_bbox
except BaseException:
pass
if _native_bbox:
box = _native_bbox[:4]
minx, maxx, miny, maxy = [float(a) for a in box]
if -180 <= minx <= 180 and -180 <= maxx <= 180 and \
- 90 <= miny <= 90 and -90 <= maxy <= 90:
Expand All @@ -190,7 +195,7 @@ def geoserver_upload(
# If GeoServer couldn't figure out the projection, we just
# assume it's lat/lon to avoid a bad GeoServer configuration

gs_resource.latlon_bbox = gs_resource.native_bbox
gs_resource.latlon_bbox = _native_bbox
gs_resource.projection = "EPSG:4326"
cat.save(gs_resource)
else:
Expand Down

0 comments on commit 5afb5ad

Please sign in to comment.