Skip to content

Commit

Permalink
- Restored the possibility of sending multiple uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed May 21, 2018
1 parent 15123a5 commit 6c0e8ca
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
14 changes: 11 additions & 3 deletions geonode/static/geonode/js/upload/LayerInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ define(function (require, exports) {
};

LayerInfo.prototype.doResume = function (event) {
$(this).text('Done').attr('disabled','disabled');
var id = (new Date()).getTime();
var newWin = window.open(window.location.href,
id, "toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=800,height=600,left = 240,top = 212");
common.make_request({
url: event.data.url,
async: true,
Expand All @@ -340,9 +344,13 @@ define(function (require, exports) {
},
success: function (resp, status) {
if(resp.url && resp.input_required){
window.location = resp.url;
// window.location = resp.url;
newWin.location = resp.url;
newWin.focus();
}else {
window.location = resp.redirect_to;
// window.location = resp.redirect_to;
newWin.location = resp.redirect_to;
newWin.focus();
}
},
});
Expand Down Expand Up @@ -447,7 +455,7 @@ define(function (require, exports) {
} else if (resp.status === "incomplete") {
var id = common.parseQueryString(resp.url).id;
var element = 'next_step_' + id
var a = '<a id="' + element + '" class="btn btn-primary" target="_new">Continue</a>';
var a = '<a id="' + element + '" class="btn btn-primary" target="_blank">Continue</a>';
var msg = '<p>' + gettext('Files are ready to be ingested!')

if (resp.redirect_to.indexOf('time') !== -1 || resp.url.indexOf('time') !== -1) {
Expand Down
6 changes: 3 additions & 3 deletions geonode/static/geonode/js/upload/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ define(['underscore',
$.merge(info.files, files[name]);
info.displayFiles();
} else {
if (Object.keys(layers).length == 0) {
// if (Object.keys(layers).length == 0) {
info = new LayerInfo({
name: name,
files: files[name]
});
info.collectErrors();
layers[name] = info;
} else {
/* } else {
log_error({
title: 'Wrong selection',
message: gettext('Only one File at a time can be uploaded!')
});
}
} */
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions geonode/upload/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,18 @@ def __repr__(self):
TYPE_UNKNOWN = FileType("unknown", None, None)

_tif_extensions = ("tif", "tiff", "geotif", "geotiff")
_mosaics_extensions = ("properties", "shp")

types = [
FileType("Shapefile", "shp", vector,
auxillary_file_exts=('dbf', 'shx', 'prj')),
FileType("GeoTIFF", _tif_extensions[0], raster,
aliases=_tif_extensions[1:]),
FileType(
"ImageMosaic", "zip-mosaic", raster,
aliases=_tif_extensions[1:],
auxillary_file_exts=("properties", "aux") + _tif_extensions[1:]
),
FileType("ASCII Text File", "asc", raster,
auxillary_file_exts=('prj')),
# requires geoserver importer extension
Expand Down
60 changes: 53 additions & 7 deletions geonode/upload/upload_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def validate_uploaded_files(cleaned, uploaded_files, field_spatial_types):
valid_extensions = validate_kml_zip(cleaned["base_file"])
if not valid_extensions:
# Let's check if the zip file contains any valid Raster Image
valid_extensions = validate_raster(cleaned["base_file"])
valid_extensions = validate_raster_zip(cleaned["base_file"])
if not valid_extensions:
# No suitable data have been found on the ZIP file; raise a ValidationError
raise forms.ValidationError(
Expand All @@ -96,6 +96,8 @@ def validate_uploaded_files(cleaned, uploaded_files, field_spatial_types):
file_paths)
elif base_ext.lower() == "kml":
valid_extensions = validate_kml(uploaded_files)
elif base_ext.lower() in files._tif_extensions:
valid_extensions = validate_raster(uploaded_files)
else: # default behavior just assumes files are valid
valid_extensions = []
for field_name in field_spatial_types:
Expand Down Expand Up @@ -252,19 +254,63 @@ def validate_shapefile(zip_django_file):
return valid_extensions


def validate_raster(zip_django_file):
def validate_raster(contents, allow_multiple=False):
def dupes(_a):
return set([x for x in _a if _a.count(x) > 1])

valid_extensions = None
raster_types = [t for t in files.types if t.layer_type == files.raster]
raster_exts = [".%s" % t.code for t in raster_types]
raster_aliases = []
for alias in [aliases for aliases in [t.aliases for t in raster_types] if aliases]:
raster_aliases.extend([".%s" % a for a in alias])
raster_exts.extend(raster_aliases)

raster_files = [
f for f in contents if os.path.splitext(str(f).lower())[1] in raster_exts]
other_files = [
f for f in contents if os.path.splitext(str(f).lower())[1] not in raster_exts]

all_extensions = [os.path.splitext(str(f))[1][1:] for f in raster_files]
other_extensions = tuple(set([os.path.splitext(str(f))[1][1:] for f in other_files]))
valid_extensions = tuple(set(all_extensions))
dup_extensions = tuple(dupes(all_extensions))
if dup_extensions:
geotiff_extensions = [
x for x in dup_extensions if x in files._tif_extensions]
mosaics_extensions = [
x for x in other_extensions if x in files._mosaics_extensions]
if mosaics_extensions:
return ("zip-mosaic",)
elif geotiff_extensions:
if not allow_multiple:
raise forms.ValidationError(
_("You are trying to upload multiple GeoTIFFs without a valid 'indexer.properties' file."))
else:
return ("zip-mosaic",)
else:
raise forms.ValidationError(
_("Only one raster file per ZIP is allowed"))
else:
if valid_extensions:
if len(valid_extensions) > 1 and not allow_multiple:
raise forms.ValidationError(
_("No multiple rasters allowed"))
else:
if not allow_multiple or 'sld' in other_extensions or 'xml' in other_extensions:
return valid_extensions
else:
return ("zip-mosaic",)
else:
return None


def validate_raster_zip(zip_django_file):
valid_extensions = None
with zipfile.ZipFile(zip_django_file) as zip_handler:
contents = zip_handler.namelist()
raster_files = [
f for f in contents if os.path.splitext(f.lower())[1] in raster_exts]
if raster_files:
valid_extensions = tuple(set([os.path.splitext(f)[1][1:] for f in raster_files]))
if valid_extensions:
valid_extensions = validate_raster(contents, allow_multiple=True)
if valid_extensions and "zip-mosaic" not in valid_extensions:
return ("zip",)
else:
return ("zip-mosaic",)

0 comments on commit 6c0e8ca

Please sign in to comment.